-
Notifications
You must be signed in to change notification settings - Fork 4
/
check-kernels
executable file
·133 lines (121 loc) · 3.56 KB
/
check-kernels
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
131
132
133
#! /bin/sh
. /usr/share/debconf/confmodule
ARCH="$(dpkg --print-architecture)"
SUBARCH="$(archdetect)"
SUBARCH="${SUBARCH#*/}"
CPUINFO=/proc/cpuinfo
UNAME_R="$(uname -r)"
KERNEL_MAJOR="$(echo "$UNAME_R" | cut -d . -f 1,2)"
KERNEL_VERSION="$(echo "$UNAME_R" | cut -d - -f 1)"
KERNEL_ABI="$(echo "$UNAME_R" | cut -d - -f 1,2)"
MACHINE="$(uname -m)"
NUMCPUS=
if [ -f /usr/lib/ubiquity/base-installer/kernel.sh ]; then
. /usr/lib/ubiquity/base-installer/kernel.sh
else
exit 0
fi
kernels="$(dpkg-query -f '${status} ${package}\n' \
-W linux-image-\* linux-signed-image-\* 2>/dev/null | \
grep '^install ok installed ' | cut -d' ' -f4 | xargs)"
flavour="$(arch_get_kernel_flavour || true)"
preferred_kernels="$(arch_get_kernel "$flavour")"
if db_get base-installer/kernel/altmeta && [ "$RET" ]; then
preferred_kernels="$(echo "$preferred_kernels" | sed "s/$/-$RET/"; \
echo "$preferred_kernels")"
fi
install_new=
compatible=
incompatible=
# TODO cjwatson 2009-10-19: Nasty hack for PAE-capable systems; see
# https://launchpad.net/bugs/413135. We should generalise this somehow.
case $preferred_kernels in
linux-generic-pae*)
if [ "$(apt-cache search -n '^linux-generic-pae$')" ]; then
install_new="${install_new:+$install_new }linux-generic-pae"
for kernel in $kernels; do
case $kernel in
*-generic-pae)
compatible="${compatible:+$compatible }$kernel"
;;
*)
incompatible="${incompatible:+$incompatible }$kernel"
;;
esac
done
fi
;;
esac
# If base-installer asks for a signed kernel, try hard to lay our hands on
# one.
for kernel in $preferred_kernels; do
case $kernel in
linux-signed-*)
if [ "$(apt-cache search -n "^$kernel\$")" ]; then
install_new="${install_new:+$install_new }$kernel"
fi
;;
esac
done
if [ -z "$compatible" ] && [ -z "$install_new" ]; then
for kernel in $kernels; do
# If base-installer didn't ask for a signed kernel, then
# consider signed kernels incompatible. This isn't
# technically true - they'll boot - but it saves leaving a
# kernel installed that users probably won't need but will
# have to upgrade.
case $preferred_kernels in
*linux-signed-*)
;;
*)
case $kernel in
linux-signed-*)
incompatible="${incompatible:+$incompatible }$kernel"
continue
;;
esac
;;
esac
if arch_check_usable_kernel "$kernel" "$flavour"; then
compatible="${compatible:+$compatible }$kernel"
else
if [ "${kernel%-$UNAME_R}" != "$kernel" ]; then
echo 'Would try to remove running kernel;' \
'bailing out for sanity' >&2
exit 0
fi
incompatible="${incompatible:+$incompatible }$kernel"
fi
done
fi
kernel_to_headers () {
echo "$1" | sed 's/linux\(-signed\|\)\(-image\|\)/linux-headers/'
}
if [ -z "$compatible" ] && [ -z "$install_new" ]; then
# We must be wrong. After all, we got this far ...
echo 'No usable kernel found; assuming foreign package naming' >&2
else
mkdir -p /var/lib/ubiquity
for kernel in $install_new; do
echo "$kernel" >>/var/lib/ubiquity/install-kernels
kernel_to_headers "$kernel" >>/var/lib/ubiquity/install-kernels
done
for kernel in $compatible; do
apt-install "$kernel" "$(kernel_to_headers "$kernel")"
done
for kernel in $incompatible; do
echo "$kernel" >> /var/lib/ubiquity/remove-kernels
case $kernel in
linux-signed-*)
# If the entire flavour is incompatible, then we'll
# find out about that separately. Otherwise,
# removing the signed kernel doesn't merit removing
# headers too.
;;
*)
kernel_to_headers "$kernel" >>/var/lib/ubiquity/remove-kernels
;;
esac
done
fi
exit 0