4 TESTDIR
="$(readlink -f "$(dirname "$0")")"
7 configarchitecture 'amd64'
9 CURRENTKERNEL="linux
-image-$(uname -r | tr '[A-Z]' '[a-z]')"
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'
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'
19 # kernel metapackages should be ignored
20 insertinstalledpackage 'linux-image-amd64' 'amd64' '200-1'
21 insertinstalledpackage 'linux-image-686-pae' 'i386' '300-1'
22 # ensure that the '.' is really a dot and not a wildcard
23 insertinstalledpackage 'linux-headers-1000000-1-generic' 'amd64' '100.0.0-1'
24 # ensure that the '+' is really a plus and not a regexp quantifier
25 insertinstalledpackage "${CURRENTKERNEL}+variant
" 'amd64' '5-1'
27 testsuccess aptmark auto "$CURRENTKERNEL" "${CURRENTKERNEL}-dbg" "${CURRENTKERNEL}-686-pae:i386
" "${CURRENTKERNEL}-rt" \
28 'linux-image-1.0.0-2-generic' 'linux-image-100.0.0-1-generic' 'linux-headers-1000000-1-generic' "${CURRENTKERNEL}+variant
"
29 testsuccess aptmark hold "${CURRENTKERNEL}-rt"
32 rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
34 testsuccess runapt sh "${TESTDIR}/..
/..
/debian
/apt.auto
-removal.sh
" "$@
"
35 testfailure test -s rootdir/tmp/testsuccess.output
37 msgtest 'Check kernel autoremoval protection list' 'is created'
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"
41 msgtest 'Check kernel autoremoval protection list' 'can be dumped'
42 testsuccess --nomsg aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove'
43 cp rootdir/tmp/testsuccess.output protected.list
45 msgtest 'Check kernel autoremoval protection list' 'can be parsed'
46 testfailure --nomsg grep '^[A-Z]: ' protected.list
48 msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
49 testsuccess --nomsg grep '^\^linux-image-100\\\.0\\\.0-1-generic\$$' protected.list
51 msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
52 testsuccess --nomsg grep "^
\\^linux
-image-$(uname -r | tr '[A-Z]' '[a-z]' | sed -e 's#\.#\\\\.#g')\\\$\$
" protected.list
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
58 AUTOREMOVE='apt autoremove'
59 if [ -n "$SUDO_USER" ]; then
60 AUTOREMOVE="sudo
$AUTOREMOVE"
62 testsuccessequal "Reading package lists...
63 Building dependency tree...
64 Reading state information...
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)
70 ${CURRENTKERNEL}+variant
(5-1)
71 ${CURRENTKERNEL}-686-pae:i386
(5-1)
72 ${CURRENTKERNEL}-dbg (5-1)
73 Use
'$AUTOREMOVE' to remove them.
74 0 upgraded
, 0 newly installed
, 0 to remove and
0 not upgraded.
" aptget install -sV
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)
83 ${CURRENTKERNEL}+variant
(5-1)
84 ${CURRENTKERNEL}-686-pae:i386
(5-1)
85 ${CURRENTKERNEL}-dbg (5-1)
86 ${CURRENTKERNEL}-rt (5-1)
87 Use
'$AUTOREMOVE' to remove them.
88 0 upgraded
, 0 newly installed
, 0 to remove and
0 not upgraded.
" aptget install -sV --ignore-hold
89 testequal "Reading package lists...
90 Building dependency tree...
91 Reading state information...
92 7 packages were automatically installed and are no longer required.
93 Use
'$AUTOREMOVE' to remove them.
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...
98 The following packages will be REMOVED
:
99 linux
-headers-1000000-1-generic (100.0.0-1)
100 linux
-image-1.0
.0-2-generic (1.0.0-2)
101 linux
-image-100.0
.0-1-generic (100.0.0-1)
103 ${CURRENTKERNEL}+variant
(5-1)
104 ${CURRENTKERNEL}-686-pae:i386
(5-1)
105 ${CURRENTKERNEL}-dbg (5-1)
106 0 upgraded
, 0 newly installed
, 7 to remove and
0 not upgraded.
107 Remv linux
-headers-1000000-1-generic [100.0.0-1]
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]
110 Remv
$CURRENTKERNEL [5-1]
111 Remv
${CURRENTKERNEL}+variant
[5-1]
112 Remv
${CURRENTKERNEL}-686-pae:i386
[5-1]
113 Remv
${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -sV
115 msgmsg "run without parameter
"
117 msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
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
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
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...
140 Building dependency tree...
141 Reading state information...
142 The following packages will be REMOVED
:
143 linux
-headers-1000000-1-generic linux
-image-1.0
.0-2-generic
145 0 upgraded
, 0 newly installed
, 3 to remove and
0 not upgraded.
146 Remv linux
-headers-1000000-1-generic [100.0.0-1]
147 Remv linux
-image-1.0
.0-2-generic [1.0.0-2]
148 Remv
${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
150 msgmsg "install an old kernel
"
151 testprotected 1.0.0-2-generic
152 msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
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
163 # rt kernel was put on hold while the protected list was generated
164 testsuccess aptmark unhold "${CURRENTKERNEL}-rt"
165 testsuccessequal "Reading package lists...
166 Building dependency tree...
167 Reading state information...
168 The following packages will be REMOVED
:
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