]> git.saurik.com Git - apt.git/blame_incremental - test/integration/test-kernel-helper-autoremove
protect only the latest same-source providers from autoremove
[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)"
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
25testsuccess aptmark auto "$CURRENTKERNEL" "${CURRENTKERNEL}-dbg" "${CURRENTKERNEL}-686-pae:i386" "${CURRENTKERNEL}-rt" \
26 'linux-image-1.0.0-2-generic' 'linux-image-100.0.0-1-generic' 'linux-headers-1000000-1-generic'
27testsuccess aptmark hold "${CURRENTKERNEL}-rt"
28
29testprotected() {
30 rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
31
32 testsuccess runapt sh "${TESTDIR}/../../debian/apt.auto-removal.sh" "$@"
33 testfailure test -s rootdir/tmp/testsuccess.output
34
35 msgtest 'Check kernel autoremoval protection list' 'is created'
36 testsuccess --nomsg test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels
37 testfilestats 'rootdir/etc/apt/apt.conf.d/01autoremove-kernels' '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:444"
38
39 msgtest 'Check kernel autoremoval protection list' 'can be dumped'
40 testsuccess --nomsg aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove'
41 cp rootdir/tmp/testsuccess.output protected.list
42
43 msgtest 'Check kernel autoremoval protection list' 'can be parsed'
44 testfailure --nomsg grep '^[A-Z]: ' protected.list
45
46 msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
47 testsuccess --nomsg grep '^\^linux-image-100\\\.0\\\.0-1-generic\$$' protected.list
48
49 msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
50 testsuccess --nomsg grep "^\\^linux-image-$(uname -r | sed -e 's#\.#\\\\.#g')\\\$\$" protected.list
51
52 msgtest 'Check kernel autoremoval protection list does not include' 'metapackages'
53 testfailure --nomsg grep -e '^\^linux-image-amd64\$$' -e '^\^linux-image-686-pae\$$' -e ':i386' protected.list
54}
55
56AUTOREMOVE='apt autoremove'
57if [ -n "$SUDO_USER" ]; then
58 AUTOREMOVE="sudo $AUTOREMOVE"
59fi
60testsuccessequal "Reading package lists...
61Building dependency tree...
62Reading state information...
63The following packages were automatically installed and are no longer required:
64 linux-headers-1000000-1-generic (100.0.0-1)
65 linux-image-1.0.0-2-generic (1.0.0-2)
66 linux-image-100.0.0-1-generic (100.0.0-1)
67 $CURRENTKERNEL (5-1)
68 ${CURRENTKERNEL}-686-pae:i386 (5-1)
69 ${CURRENTKERNEL}-dbg (5-1)
70Use '$AUTOREMOVE' to remove them.
710 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV
72testsuccessequal "Reading package lists...
73Building dependency tree...
74Reading state information...
75The following packages were automatically installed and are no longer required:
76 linux-headers-1000000-1-generic (100.0.0-1)
77 linux-image-1.0.0-2-generic (1.0.0-2)
78 linux-image-100.0.0-1-generic (100.0.0-1)
79 $CURRENTKERNEL (5-1)
80 ${CURRENTKERNEL}-686-pae:i386 (5-1)
81 ${CURRENTKERNEL}-dbg (5-1)
82 ${CURRENTKERNEL}-rt (5-1)
83Use '$AUTOREMOVE' to remove them.
840 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV --ignore-hold
85testequal "Reading package lists...
86Building dependency tree...
87Reading state information...
886 packages were automatically installed and are no longer required.
89Use '$AUTOREMOVE' to remove them.
900 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -s -o APT::Get::HideAutoRemove=small
91testequal "Reading package lists...
92Building dependency tree...
93Reading state information...
94The following packages will be REMOVED:
95 linux-headers-1000000-1-generic (100.0.0-1)
96 linux-image-1.0.0-2-generic (1.0.0-2)
97 linux-image-100.0.0-1-generic (100.0.0-1)
98 $CURRENTKERNEL (5-1)
99 ${CURRENTKERNEL}-686-pae:i386 (5-1)
100 ${CURRENTKERNEL}-dbg (5-1)
1010 upgraded, 0 newly installed, 6 to remove and 0 not upgraded.
102Remv linux-headers-1000000-1-generic [100.0.0-1]
103Remv linux-image-1.0.0-2-generic [1.0.0-2]
104Remv linux-image-100.0.0-1-generic [100.0.0-1]
105Remv $CURRENTKERNEL [5-1]
106Remv ${CURRENTKERNEL}-686-pae:i386 [5-1]
107Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -sV
108
109msgmsg "run without parameter"
110testprotected
111msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
112testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
113testsuccessequal "Reading package lists...
114Building dependency tree...
115Reading state information...
116The following packages will be REMOVED:
117 linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
118 ${CURRENTKERNEL}-dbg
1190 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
120Remv linux-headers-1000000-1-generic [100.0.0-1]
121Remv linux-image-1.0.0-2-generic [1.0.0-2]
122Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
123
124msgmsg "install unknown kernel"
125# even if installed/uname reports a kernel which we can't find via dpkg,
126# ensure that we still protect it just in case as these are kernels we
127# know for sure without complicated detection mechanisms
128testprotected 1.0.0-2-ungeneric
129msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
130testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
131msgtest 'Check kernel autoremoval protection list does include' 'unknown installed kernel'
132testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-ungeneric\$$' protected.list
133testsuccessequal "Reading package lists...
134Building dependency tree...
135Reading state information...
136The following packages will be REMOVED:
137 linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
138 ${CURRENTKERNEL}-dbg
1390 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
140Remv linux-headers-1000000-1-generic [100.0.0-1]
141Remv linux-image-1.0.0-2-generic [1.0.0-2]
142Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
143
144msgmsg "install an old kernel"
145testprotected 1.0.0-2-generic
146msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
147testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
148testsuccessequal "Reading package lists...
149Building dependency tree...
150Reading state information...
151The following packages will be REMOVED:
152 linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg
1530 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
154Remv linux-headers-1000000-1-generic [100.0.0-1]
155Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
156
157# rt kernel was put on hold while the protected list was generated
158testsuccess aptmark unhold "${CURRENTKERNEL}-rt"
159testsuccessequal "Reading package lists...
160Building dependency tree...
161Reading state information...
162The following packages will be REMOVED:
163 linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg
1640 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
165Remv linux-headers-1000000-1-generic [100.0.0-1]
166Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s