-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-kernel
executable file
·99 lines (78 loc) · 1.83 KB
/
update-kernel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env sh
# Author: J.M. Thiessen <[email protected]>
# Version: 0.2
LOG_FILE="/var/log/kernel_update.log"
SEPERATOR_STRING="----------"
# print usage
usage() {
printf "%s\n" "Usage: $0 [-l] [-e] [-m] [-h]"
printf "\t%s\n" "-l enable lvm"
printf "\t%s\n" "-e enable luks"
printf "\t%s\n" "-m enable mdadm"
printf "\t%s\n" "-h help"
}
OPTS=""
while getopts ":lemh" arg; do
case $arg in
l)
OPTS="$OPTS --lvm"
;;
e)
OPTS="$OPTS --luks"
;;
m)
OPTS="$OPTS --mdadm"
;;
h | *)
usage
exit 0
;;
esac
done
# simple logging method
log() {
printf "\033[0;37m%s \033[0m%s\n" "[$(date +%FT%TZ)]" "$*"
}
# seperator for log file to make things easier to find
seperator() {
printf "%s%s%s\n" $SEPERATOR_STRING "$*" $SEPERATOR_STRING >> $LOG_FILE
}
if [ "$(id -u)" != 0 ]; then
printf "\033[1;31m%s\n" "Root permissions required!"
exit 1
fi
log "Log file is located at $LOG_FILE"
if [ "$(grep -c /boot < /proc/mounts)" = 0 ]; then
mount $(printenv BOOT_DRIVE) "/boot"
fi
if [ -f "$LOG_FILE" ]; then
rm "$LOG_FILE";
fi
eselect kernel list
printf "%s\n" "kernel version?"
read -r version
eselect kernel set "$version"
kernel=$(uname -r)
cp "/boot/config-$kernel" /usr/src/linux
cd "/usr/src/linux" || exit 1
seperator "olddef"
log "Running olddef"
{ make olddefconfig >> $LOG_FILE; } 2>&1
seperator "kernel"
log "Running make kernel"
{ make -j"$(nproc)" >> $LOG_FILE; } 2>&1
seperator "modules"
log "Running make modules"
{ make -j"$(nproc)" modules_install >> $LOG_FILE; } 2>&1
seperator "installing"
log "Installing new kernel"
{ make install >> $LOG_FILE; } 2>&1
seperator "initramfs"
log "Setting up initramfs"
echo $OPTS
{ genkernel initramfs $OPTS >> $LOG_FILE; } 2>&1
seperator "bootloader"
log "Updating bootloader"
{ grub-mkconfig -o /boot/grub/grub.cfg >> $LOG_FILE; } 2>&1
log "Unmounting boot"
umount "/boot"