]>
Commit | Line | Data |
---|---|---|
e5bdcc87 | 1 | #!/bin/sh |
e5bdcc87 MV |
2 | set -e |
3 | ||
3abb6a6a DK |
4 | TESTDIR="$(readlink -f "$(dirname "$0")")" |
5 | . "$TESTDIR/framework" | |
b9b0f622 | 6 | setupenvironment |
33677a0c | 7 | configarchitecture 'amd64' |
e5bdcc87 | 8 | |
15134a8e | 9 | CURRENTKERNEL="linux-image-$(uname -r | tr '[A-Z]' '[a-z]')" |
3196dae8 DK |
10 | insertinstalledpackage "$CURRENTKERNEL" 'amd64' '5-1' |
11 | # debug packages do not need our protection | |
12 | insertinstalledpackage "${CURRENTKERNEL}-dbg" 'amd64' '5-1' | |
13 | # but other kernel flavours should be protected | |
14 | insertinstalledpackage "${CURRENTKERNEL}-686-pae" 'i386' '5-1' | |
15 | insertinstalledpackage "${CURRENTKERNEL}-rt" 'amd64' '5-1' | |
16 | # some more versions | |
33677a0c DK |
17 | insertinstalledpackage 'linux-image-1.0.0-2-generic' 'amd64' '1.0.0-2' |
18 | insertinstalledpackage 'linux-image-100.0.0-1-generic' 'amd64' '100.0.0-1' | |
3196dae8 DK |
19 | # kernel metapackages should be ignored |
20 | insertinstalledpackage 'linux-image-amd64' 'amd64' '200-1' | |
21 | insertinstalledpackage 'linux-image-686-pae' 'i386' '300-1' | |
7ce1ac85 DK |
22 | # ensure that the '.' is really a dot and not a wildcard |
23 | insertinstalledpackage 'linux-headers-1000000-1-generic' 'amd64' '100.0.0-1' | |
130176bc AP |
24 | # ensure that the '+' is really a plus and not a regexp quantifier |
25 | insertinstalledpackage "${CURRENTKERNEL}+variant" 'amd64' '5-1' | |
33677a0c | 26 | |
3196dae8 | 27 | testsuccess aptmark auto "$CURRENTKERNEL" "${CURRENTKERNEL}-dbg" "${CURRENTKERNEL}-686-pae:i386" "${CURRENTKERNEL}-rt" \ |
130176bc | 28 | 'linux-image-1.0.0-2-generic' 'linux-image-100.0.0-1-generic' 'linux-headers-1000000-1-generic' "${CURRENTKERNEL}+variant" |
3196dae8 | 29 | testsuccess aptmark hold "${CURRENTKERNEL}-rt" |
e5bdcc87 | 30 | |
b9b0f622 DK |
31 | testprotected() { |
32 | rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list | |
e5bdcc87 | 33 | |
63c71412 | 34 | testsuccess runapt sh "${TESTDIR}/../../debian/apt.auto-removal.sh" "$@" |
3196dae8 | 35 | testfailure test -s rootdir/tmp/testsuccess.output |
c6918c16 | 36 | |
b9b0f622 | 37 | msgtest 'Check kernel autoremoval protection list' 'is created' |
3196dae8 DK |
38 | testsuccess --nomsg test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels |
39 | testfilestats 'rootdir/etc/apt/apt.conf.d/01autoremove-kernels' '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:444" | |
c6918c16 | 40 | |
b9b0f622 | 41 | msgtest 'Check kernel autoremoval protection list' 'can be dumped' |
3196dae8 DK |
42 | testsuccess --nomsg aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove' |
43 | cp rootdir/tmp/testsuccess.output protected.list | |
e5bdcc87 | 44 | |
b9b0f622 | 45 | msgtest 'Check kernel autoremoval protection list' 'can be parsed' |
3196dae8 | 46 | testfailure --nomsg grep '^[A-Z]: ' protected.list |
d269b88d | 47 | |
b9b0f622 | 48 | msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel' |
3196dae8 | 49 | testsuccess --nomsg grep '^\^linux-image-100\\\.0\\\.0-1-generic\$$' protected.list |
b9b0f622 DK |
50 | |
51 | msgtest 'Check kernel autoremoval protection list includes' 'running kernel' | |
15134a8e | 52 | testsuccess --nomsg grep "^\\^linux-image-$(uname -r | tr '[A-Z]' '[a-z]' | sed -e 's#\.#\\\\.#g')\\\$\$" protected.list |
3196dae8 DK |
53 | |
54 | msgtest 'Check kernel autoremoval protection list does not include' 'metapackages' | |
55 | testfailure --nomsg grep -e '^\^linux-image-amd64\$$' -e '^\^linux-image-686-pae\$$' -e ':i386' protected.list | |
b9b0f622 DK |
56 | } |
57 | ||
73fe49f9 DK |
58 | AUTOREMOVE='apt autoremove' |
59 | if [ -n "$SUDO_USER" ]; then | |
60 | AUTOREMOVE="sudo $AUTOREMOVE" | |
61 | fi | |
25b86db1 | 62 | testsuccessequal "Reading package lists... |
33677a0c DK |
63 | Building dependency tree... |
64 | Reading state information... | |
a0c19a21 DK |
65 | The following packages were automatically installed and are no longer required: |
66 | linux-headers-1000000-1-generic (100.0.0-1) | |
67 | linux-image-1.0.0-2-generic (1.0.0-2) | |
68 | linux-image-100.0.0-1-generic (100.0.0-1) | |
3196dae8 | 69 | $CURRENTKERNEL (5-1) |
130176bc | 70 | ${CURRENTKERNEL}+variant (5-1) |
3196dae8 DK |
71 | ${CURRENTKERNEL}-686-pae:i386 (5-1) |
72 | ${CURRENTKERNEL}-dbg (5-1) | |
73fe49f9 | 73 | Use '$AUTOREMOVE' to remove them. |
a0c19a21 | 74 | 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV |
3196dae8 DK |
75 | testsuccessequal "Reading package lists... |
76 | Building dependency tree... | |
77 | Reading state information... | |
78 | The following packages were automatically installed and are no longer required: | |
79 | linux-headers-1000000-1-generic (100.0.0-1) | |
80 | linux-image-1.0.0-2-generic (1.0.0-2) | |
81 | linux-image-100.0.0-1-generic (100.0.0-1) | |
82 | $CURRENTKERNEL (5-1) | |
130176bc | 83 | ${CURRENTKERNEL}+variant (5-1) |
3196dae8 DK |
84 | ${CURRENTKERNEL}-686-pae:i386 (5-1) |
85 | ${CURRENTKERNEL}-dbg (5-1) | |
86 | ${CURRENTKERNEL}-rt (5-1) | |
73fe49f9 | 87 | Use '$AUTOREMOVE' to remove them. |
3196dae8 | 88 | 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV --ignore-hold |
a0c19a21 DK |
89 | testequal "Reading package lists... |
90 | Building dependency tree... | |
91 | Reading state information... | |
130176bc | 92 | 7 packages were automatically installed and are no longer required. |
73fe49f9 | 93 | Use '$AUTOREMOVE' to remove them. |
a0c19a21 DK |
94 | 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -s -o APT::Get::HideAutoRemove=small |
95 | testequal "Reading package lists... | |
96 | Building dependency tree... | |
97 | Reading state information... | |
33677a0c | 98 | The following packages will be REMOVED: |
7ce1ac85 | 99 | linux-headers-1000000-1-generic (100.0.0-1) |
33677a0c DK |
100 | linux-image-1.0.0-2-generic (1.0.0-2) |
101 | linux-image-100.0.0-1-generic (100.0.0-1) | |
3196dae8 | 102 | $CURRENTKERNEL (5-1) |
130176bc | 103 | ${CURRENTKERNEL}+variant (5-1) |
3196dae8 DK |
104 | ${CURRENTKERNEL}-686-pae:i386 (5-1) |
105 | ${CURRENTKERNEL}-dbg (5-1) | |
130176bc | 106 | 0 upgraded, 0 newly installed, 7 to remove and 0 not upgraded. |
7ce1ac85 | 107 | Remv linux-headers-1000000-1-generic [100.0.0-1] |
33677a0c DK |
108 | Remv linux-image-1.0.0-2-generic [1.0.0-2] |
109 | Remv linux-image-100.0.0-1-generic [100.0.0-1] | |
3196dae8 | 110 | Remv $CURRENTKERNEL [5-1] |
130176bc | 111 | Remv ${CURRENTKERNEL}+variant [5-1] |
3196dae8 DK |
112 | Remv ${CURRENTKERNEL}-686-pae:i386 [5-1] |
113 | Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -sV | |
33677a0c | 114 | |
3196dae8 | 115 | msgmsg "run without parameter" |
b9b0f622 DK |
116 | testprotected |
117 | msgtest 'Check kernel autoremoval protection list does not include' 'old kernel' | |
3196dae8 DK |
118 | testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list |
119 | testsuccessequal "Reading package lists... | |
120 | Building dependency tree... | |
121 | Reading state information... | |
122 | The following packages will be REMOVED: | |
123 | linux-headers-1000000-1-generic linux-image-1.0.0-2-generic | |
124 | ${CURRENTKERNEL}-dbg | |
125 | 0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded. | |
126 | Remv linux-headers-1000000-1-generic [100.0.0-1] | |
127 | Remv linux-image-1.0.0-2-generic [1.0.0-2] | |
128 | Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s | |
d269b88d | 129 | |
3196dae8 DK |
130 | msgmsg "install unknown kernel" |
131 | # even if installed/uname reports a kernel which we can't find via dpkg, | |
132 | # ensure that we still protect it just in case as these are kernels we | |
133 | # know for sure without complicated detection mechanisms | |
134 | testprotected 1.0.0-2-ungeneric | |
135 | msgtest 'Check kernel autoremoval protection list does not include' 'old kernel' | |
136 | testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list | |
137 | msgtest 'Check kernel autoremoval protection list does include' 'unknown installed kernel' | |
138 | testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-ungeneric\$$' protected.list | |
139 | testsuccessequal "Reading package lists... | |
33677a0c DK |
140 | Building dependency tree... |
141 | Reading state information... | |
142 | The following packages will be REMOVED: | |
7ce1ac85 | 143 | linux-headers-1000000-1-generic linux-image-1.0.0-2-generic |
3196dae8 DK |
144 | ${CURRENTKERNEL}-dbg |
145 | 0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded. | |
7ce1ac85 | 146 | Remv linux-headers-1000000-1-generic [100.0.0-1] |
3196dae8 DK |
147 | Remv linux-image-1.0.0-2-generic [1.0.0-2] |
148 | Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s | |
33677a0c | 149 | |
3196dae8 | 150 | msgmsg "install an old kernel" |
b9b0f622 DK |
151 | testprotected 1.0.0-2-generic |
152 | msgtest 'Check kernel autoremoval protection list includes' 'installed kernel' | |
3196dae8 DK |
153 | testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list |
154 | testsuccessequal "Reading package lists... | |
155 | Building dependency tree... | |
156 | Reading state information... | |
157 | The following packages will be REMOVED: | |
158 | linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg | |
159 | 0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded. | |
160 | Remv linux-headers-1000000-1-generic [100.0.0-1] | |
161 | Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s | |
162 | ||
163 | # rt kernel was put on hold while the protected list was generated | |
164 | testsuccess aptmark unhold "${CURRENTKERNEL}-rt" | |
165 | testsuccessequal "Reading package lists... | |
33677a0c DK |
166 | Building dependency tree... |
167 | Reading state information... | |
7ce1ac85 | 168 | The following packages will be REMOVED: |
3196dae8 DK |
169 | linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg |
170 | 0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded. | |
171 | Remv linux-headers-1000000-1-generic [100.0.0-1] | |
172 | Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s |