]> git.saurik.com Git - apt.git/blame_incremental - test/integration/test-kernel-helper-autoremove
Use _apt as our unprivileged user name
[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
9# the executed script would use the installed apt-config,
10# which is outside of our control
11msgtest 'Check that the installed apt-config supports' '--no-empty'
12if /usr/bin/apt-config dump --no-empty >/dev/null 2>&1; then
13 msgpass
14else
15 msgskip
16 exit 0
17fi
18
19CURRENTKERNEL="linux-image-$(uname -r)"
20insertinstalledpackage "$CURRENTKERNEL" 'amd64' '1'
21insertinstalledpackage 'linux-image-1.0.0-2-generic' 'amd64' '1.0.0-2'
22insertinstalledpackage 'linux-image-100.0.0-1-generic' 'amd64' '100.0.0-1'
23insertinstalledpackage 'linux-image-amd64' 'amd64' '100.0.0-1'
24# ensure that the '.' is really a dot and not a wildcard
25insertinstalledpackage 'linux-headers-1000000-1-generic' 'amd64' '100.0.0-1'
26
27testsuccess aptmark auto "$CURRENTKERNEL" 'linux-image-1.0.0-2-generic' 'linux-image-100.0.0-1-generic' 'linux-headers-1000000-1-generic'
28
29cat > ./fake-dpkg <<EOF
30#!/bin/sh
31exec $(aptconfig dump --no-empty --format='%v ' 'DPKG::options') "\$@"
32EOF
33chmod +x ./fake-dpkg
34echo 'Dir::Bin::dpkg "./fake-dpkg";' > rootdir/etc/apt/apt.conf.d/99fakedpkg
35
36# install fake-dpkg into it
37catfail() {
38 echo >&2
39 echo >&2 '### List of protected kernels:'
40 cat >&2 protected.list
41 msgfail
42}
43
44testprotected() {
45 rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
46
47 testsuccess runapt sh ${TESTDIR}/../../debian/apt.auto-removal.sh "$@"
48
49 msgtest 'Check kernel autoremoval protection list' 'is created'
50 test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels && msgpass || msgfail
51
52 msgtest 'Check kernel autoremoval protection list' 'can be dumped'
53 aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove' >protected.list 2>&1 && msgpass || catfail
54
55 msgtest 'Check kernel autoremoval protection list' 'can be parsed'
56 grep -q '^[A-Z]: ' protected.list && catfail || msgpass
57
58 msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
59 grep -q '^\^linux-image-100\\\.0\\\.0-1-generic\$$' protected.list && msgpass || catfail
60
61 msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
62 grep -q "^\\^linux-image-$(uname -r | sed -e 's#\.#\\\\.#g')\\\$\$" protected.list && msgpass || catfail
63}
64
65testequal "Reading package lists...
66Building dependency tree...
67Reading state information...
68The following packages will be REMOVED:
69 linux-headers-1000000-1-generic (100.0.0-1)
70 linux-image-1.0.0-2-generic (1.0.0-2)
71 linux-image-100.0.0-1-generic (100.0.0-1)
72 $CURRENTKERNEL (1)
730 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
74Remv linux-headers-1000000-1-generic [100.0.0-1]
75Remv linux-image-1.0.0-2-generic [1.0.0-2]
76Remv linux-image-100.0.0-1-generic [100.0.0-1]
77Remv $CURRENTKERNEL [1]" aptget autoremove -sV
78
79testprotected
80msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
81grep -q '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list && catfail || msgpass
82
83testequal 'Reading package lists...
84Building dependency tree...
85Reading state information...
86The following packages will be REMOVED:
87 linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
880 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
89Remv linux-headers-1000000-1-generic [100.0.0-1]
90Remv linux-image-1.0.0-2-generic [1.0.0-2]' aptget autoremove -s
91
92testprotected 1.0.0-2-generic
93msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
94grep -q '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list && msgpass || catfail
95testequal 'Reading package lists...
96Building dependency tree...
97Reading state information...
98The following packages will be REMOVED:
99 linux-headers-1000000-1-generic
1000 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
101Remv linux-headers-1000000-1-generic [100.0.0-1]' aptget autoremove -s