forked from xoseperez/pi-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-kernel
executable file
·130 lines (118 loc) · 2.36 KB
/
install-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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
trap '{ stty sane; echo ""; errexit "Aborted"; }' SIGINT SIGTERM
errexit()
{
echo ""
echo "$1"
echo ""
exit 1
}
usage()
{
cat <<EOF
Usage: $0 [options] <kernel-archive>
-h,--help This usage description
-n,--noinitramfs Disable running update-initramfs
-r,--reboot Reboot upon completion
EOF
}
if [ $(id -u) -ne 0 ]; then
errexit "Must be run as root user: sudo $0"
fi
PGMNAME="$(basename $0)"
for PID in $(pidof -x -o %PPID "${PGMNAME}"); do
if [ ${PID} -ne $$ ]; then
errexit "${PGMNAME} is already running"
fi
done
ARCHIVE=""
NOINITRAMFS=FALSE
REBOOT=FALSE
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
usage
exit
;;
-n|--noinitramfs)
NOINITRAMFS=TRUE
shift
;;
-r|--reboot)
REBOOT=TRUE
shift
;;
-*|--*)
errexit "Unrecognized option"
;;
*)
ARCHIVE="$1"
ARCHIVE="$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "${ARCHIVE}")"
shift
;;
esac
done
if [ "${ARCHIVE}" = "" ]; then
usage
exit
fi
if [ ! -f "${ARCHIVE}" ]; then
errexit "${ARCHIVE} not found"
fi
unzip -tq "${ARCHIVE}" > /dev/null
if [ $? -ne 0 ]; then
errexit "${ARCHIVE} is not a valid archive"
fi
BUILD="$(unzip -l ${ARCHIVE} boot/vmlinuz-* | sed -n 's|^.*boot/vmlinuz-\(.*\)$|\1|p')"
if [ "${BUILD}" = "" ]; then
echo ""
echo "${ARCHIVE} appears to use old boot mount (/boot)"
NOINITRAMFS=TRUE
fi
if [ "${NOINITRAMFS}" = "TRUE" ]; then
echo ""
echo "update-initramfs will not be run"
fi
echo ""
echo -n "Ok to install ${ARCHIVE} (y/n)? "
while read -r -n 1 -s answer; do
if [[ "${answer}" = [yYnN] ]]; then
echo "${answer}"
if [[ "${answer}" = [yY] ]]; then
break
else
errexit "Aborted"
exit 1
fi
fi
done
echo ""
unzip -o "${ARCHIVE}" -d /
if [ $? -ne 0 ]; then
errexit "unzip ${ARCHIVE} failed"
fi
if [ "${NOINITRAMFS}" = "FALSE" ]; then
update-initramfs -c -v -k "${BUILD}"
fi
echo ""
echo "Kernel installation completed"
echo ""
if [ "${REBOOT}" = "TRUE" ]; then
echo "Rebooting"
echo ""
shutdown -r now
else
echo "Reboot required to use new kernel"
echo ""
echo -n "Reboot now (y/n)? "
while read -r -n 1 -s answer; do
if [[ ${answer} = [yYnN] ]]; then
echo "${answer}"
if [[ ${answer} = [yY] ]]; then
shutdown -r now
fi
break
fi
done
fi
echo ""