]> git.saurik.com Git - apt.git/blame_incremental - test/integration/test-kernel-helper-autoremove
test-apt-cdrom: Fix for gnupg 2.1.15
[apt.git] / test / integration / test-kernel-helper-autoremove
... / ...
CommitLineData
1#!/bin/sh
2set -e
3
4TESTDIR="$(readlink -f "$(dirname "$0")")"
5. "$TESTDIR/framework"
6setupenvironment
7configarchitecture 'amd64'
8
9CURRENTKERNEL="linux-image-$(uname -r | tr '[A-Z]' '[a-z]')"
10insertinstalledpackage "$CURRENTKERNEL" 'amd64' '5-1'
11# debug packages do not need our protection
12insertinstalledpackage "${CURRENTKERNEL}-dbg" 'amd64' '5-1'
13# but other kernel flavours should be protected
14insertinstalledpackage "${CURRENTKERNEL}-686-pae" 'i386' '5-1'
15insertinstalledpackage "${CURRENTKERNEL}-rt" 'amd64' '5-1'
16# some more versions
17insertinstalledpackage 'linux-image-1.0.0-2-generic' 'amd64' '1.0.0-2'
18insertinstalledpackage 'linux-image-100.0.0-1-generic' 'amd64' '100.0.0-1'
19# kernel metapackages should be ignored
20insertinstalledpackage 'linux-image-amd64' 'amd64' '200-1'
21insertinstalledpackage 'linux-image-686-pae' 'i386' '300-1'
22# ensure that the '.' is really a dot and not a wildcard
23insertinstalledpackage 'linux-headers-1000000-1-generic' 'amd64' '100.0.0-1'
24# ensure that the '+' is really a plus and not a regexp quantifier
25insertinstalledpackage "${CURRENTKERNEL}+variant" 'amd64' '5-1'
26
27testsuccess 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"
29testsuccess aptmark hold "${CURRENTKERNEL}-rt"
30
31testprotected() {
32 rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
33
34 testsuccess runapt sh "${TESTDIR}/../../debian/apt.auto-removal.sh" "$@"
35 testfailure test -s rootdir/tmp/testsuccess.output
36
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"
40
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
44
45 msgtest 'Check kernel autoremoval protection list' 'can be parsed'
46 testfailure --nomsg grep '^[A-Z]: ' protected.list
47
48 msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
49 testsuccess --nomsg grep '^\^linux-image-100\\\.0\\\.0-1-generic\$$' protected.list
50
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
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
56}
57
58AUTOREMOVE='apt autoremove'
59if [ -n "$SUDO_USER" ]; then
60 AUTOREMOVE="sudo $AUTOREMOVE"
61fi
62testsuccessequal "Reading package lists...
63Building dependency tree...
64Reading state information...
65The 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)
69 $CURRENTKERNEL (5-1)
70 ${CURRENTKERNEL}+variant (5-1)
71 ${CURRENTKERNEL}-686-pae:i386 (5-1)
72 ${CURRENTKERNEL}-dbg (5-1)
73Use '$AUTOREMOVE' to remove them.
740 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV
75testsuccessequal "Reading package lists...
76Building dependency tree...
77Reading state information...
78The 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)
83 ${CURRENTKERNEL}+variant (5-1)
84 ${CURRENTKERNEL}-686-pae:i386 (5-1)
85 ${CURRENTKERNEL}-dbg (5-1)
86 ${CURRENTKERNEL}-rt (5-1)
87Use '$AUTOREMOVE' to remove them.
880 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV --ignore-hold
89testequal "Reading package lists...
90Building dependency tree...
91Reading state information...
927 packages were automatically installed and are no longer required.
93Use '$AUTOREMOVE' to remove them.
940 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -s -o APT::Get::HideAutoRemove=small
95testequal "Reading package lists...
96Building dependency tree...
97Reading state information...
98The 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)
102 $CURRENTKERNEL (5-1)
103 ${CURRENTKERNEL}+variant (5-1)
104 ${CURRENTKERNEL}-686-pae:i386 (5-1)
105 ${CURRENTKERNEL}-dbg (5-1)
1060 upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
107Remv linux-headers-1000000-1-generic [100.0.0-1]
108Remv linux-image-1.0.0-2-generic [1.0.0-2]
109Remv linux-image-100.0.0-1-generic [100.0.0-1]
110Remv $CURRENTKERNEL [5-1]
111Remv ${CURRENTKERNEL}+variant [5-1]
112Remv ${CURRENTKERNEL}-686-pae:i386 [5-1]
113Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -sV
114
115msgmsg "run without parameter"
116testprotected
117msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
118testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
119testsuccessequal "Reading package lists...
120Building dependency tree...
121Reading state information...
122The following packages will be REMOVED:
123 linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
124 ${CURRENTKERNEL}-dbg
1250 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
126Remv linux-headers-1000000-1-generic [100.0.0-1]
127Remv linux-image-1.0.0-2-generic [1.0.0-2]
128Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
129
130msgmsg "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
134testprotected 1.0.0-2-ungeneric
135msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
136testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
137msgtest 'Check kernel autoremoval protection list does include' 'unknown installed kernel'
138testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-ungeneric\$$' protected.list
139testsuccessequal "Reading package lists...
140Building dependency tree...
141Reading state information...
142The following packages will be REMOVED:
143 linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
144 ${CURRENTKERNEL}-dbg
1450 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
146Remv linux-headers-1000000-1-generic [100.0.0-1]
147Remv linux-image-1.0.0-2-generic [1.0.0-2]
148Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
149
150msgmsg "install an old kernel"
151testprotected 1.0.0-2-generic
152msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
153testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
154testsuccessequal "Reading package lists...
155Building dependency tree...
156Reading state information...
157The following packages will be REMOVED:
158 linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg
1590 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
160Remv linux-headers-1000000-1-generic [100.0.0-1]
161Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
162
163# rt kernel was put on hold while the protected list was generated
164testsuccess aptmark unhold "${CURRENTKERNEL}-rt"
165testsuccessequal "Reading package lists...
166Building dependency tree...
167Reading state information...
168The following packages will be REMOVED:
169 linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg
1700 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
171Remv linux-headers-1000000-1-generic [100.0.0-1]
172Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s