]> git.saurik.com Git - apt.git/blame - test/integration/test-kernel-helper-autoremove
add ".*-{kernel,modules}-$KERVER" matcher for hook
[apt.git] / test / integration / test-kernel-helper-autoremove
CommitLineData
e5bdcc87 1#!/bin/sh
e5bdcc87
MV
2set -e
3
e5bdcc87
MV
4TESTDIR=$(readlink -f $(dirname $0))
5. $TESTDIR/framework
b9b0f622 6setupenvironment
33677a0c 7configarchitecture 'amd64'
e5bdcc87 8
b9b0f622
DK
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 apt-config dump --no-empty >/dev/null 2>&1; then
13 msgpass
14else
15 msgskip
16 exit 0
17fi
e5bdcc87 18
33677a0c
DK
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'
23
24testsuccess aptmark auto "$CURRENTKERNEL" 'linux-image-1.0.0-2-generic' 'linux-image-100.0.0-1-generic'
25
b9b0f622
DK
26cat > ./fake-dpkg <<EOF
27#!/bin/sh
33677a0c 28exec $(aptconfig dump --no-empty --format='%v ' 'DPKG::options') "\$@"
e5bdcc87 29EOF
b9b0f622
DK
30chmod +x ./fake-dpkg
31echo 'Dir::Bin::dpkg "./fake-dpkg";' > rootdir/etc/apt/apt.conf.d/99fakedpkg
e5bdcc87 32
33677a0c 33# install fake-dpkg into it
b9b0f622
DK
34catfail() {
35 echo >&2
36 echo >&2 '### List of protected kernels:'
37 cat >&2 protected.list
38 msgfail
39}
e5bdcc87 40
b9b0f622
DK
41testprotected() {
42 rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
e5bdcc87 43
b9b0f622 44 testsuccess runapt sh ${TESTDIR}/../../debian/apt.auto-removal.sh "$@"
c6918c16 45
b9b0f622
DK
46 msgtest 'Check kernel autoremoval protection list' 'is created'
47 test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels && msgpass || msgfail
c6918c16 48
b9b0f622
DK
49 msgtest 'Check kernel autoremoval protection list' 'can be dumped'
50 aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove' >protected.list 2>&1 && msgpass || catfail
e5bdcc87 51
b9b0f622
DK
52 msgtest 'Check kernel autoremoval protection list' 'can be parsed'
53 grep -q '^[A-Z]: ' protected.list && catfail || msgpass
d269b88d 54
b9b0f622
DK
55 msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
56 grep -q '^\^linux-image-100\.0\.0-1-generic\$$' protected.list && msgpass || catfail
57
58 msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
59 grep -q "^\\^linux-image-$(uname -r)\\\$\$" protected.list && msgpass || catfail
60}
61
33677a0c
DK
62testequal "Reading package lists...
63Building dependency tree...
64Reading state information...
65The following packages will be REMOVED:
66 linux-image-1.0.0-2-generic (1.0.0-2)
67 linux-image-100.0.0-1-generic (100.0.0-1)
68 $CURRENTKERNEL (1)
690 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
70Remv linux-image-1.0.0-2-generic [1.0.0-2]
71Remv linux-image-100.0.0-1-generic [100.0.0-1]
72Remv $CURRENTKERNEL [1]" aptget autoremove -sV
73
b9b0f622
DK
74testprotected
75msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
76grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && catfail || msgpass
d269b88d 77
33677a0c
DK
78testequal 'Reading package lists...
79Building dependency tree...
80Reading state information...
81The following packages will be REMOVED:
82 linux-image-1.0.0-2-generic
830 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
84Remv linux-image-1.0.0-2-generic [1.0.0-2]' aptget autoremove -s
85
b9b0f622
DK
86testprotected 1.0.0-2-generic
87msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
88grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && msgpass || catfail
33677a0c
DK
89testequal 'Reading package lists...
90Building dependency tree...
91Reading state information...
920 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.' aptget autoremove -s