]> git.saurik.com Git - apt.git/blame - test/integration/test-kernel-helper-autoremove
apt-inst: Do not try to create a substring of an empty string in error reporting
[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'
7ce1ac85
DK
23# ensure that the '.' is really a dot and not a wildcard
24insertinstalledpackage 'linux-headers-1000000-1-generic' 'amd64' '100.0.0-1'
33677a0c 25
7ce1ac85 26testsuccess aptmark auto "$CURRENTKERNEL" 'linux-image-1.0.0-2-generic' 'linux-image-100.0.0-1-generic' 'linux-headers-1000000-1-generic'
33677a0c 27
b9b0f622
DK
28cat > ./fake-dpkg <<EOF
29#!/bin/sh
33677a0c 30exec $(aptconfig dump --no-empty --format='%v ' 'DPKG::options') "\$@"
e5bdcc87 31EOF
b9b0f622
DK
32chmod +x ./fake-dpkg
33echo 'Dir::Bin::dpkg "./fake-dpkg";' > rootdir/etc/apt/apt.conf.d/99fakedpkg
e5bdcc87 34
33677a0c 35# install fake-dpkg into it
b9b0f622
DK
36catfail() {
37 echo >&2
38 echo >&2 '### List of protected kernels:'
39 cat >&2 protected.list
40 msgfail
41}
e5bdcc87 42
b9b0f622
DK
43testprotected() {
44 rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
e5bdcc87 45
b9b0f622 46 testsuccess runapt sh ${TESTDIR}/../../debian/apt.auto-removal.sh "$@"
c6918c16 47
b9b0f622
DK
48 msgtest 'Check kernel autoremoval protection list' 'is created'
49 test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels && msgpass || msgfail
c6918c16 50
b9b0f622
DK
51 msgtest 'Check kernel autoremoval protection list' 'can be dumped'
52 aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove' >protected.list 2>&1 && msgpass || catfail
e5bdcc87 53
b9b0f622
DK
54 msgtest 'Check kernel autoremoval protection list' 'can be parsed'
55 grep -q '^[A-Z]: ' protected.list && catfail || msgpass
d269b88d 56
b9b0f622 57 msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
7ce1ac85 58 grep -q '^\^linux-image-100\\\.0\\\.0-1-generic\$$' protected.list && msgpass || catfail
b9b0f622
DK
59
60 msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
7ce1ac85 61 grep -q "^\\^linux-image-$(uname -r | sed -e 's#\.#\\\\.#g')\\\$\$" protected.list && msgpass || catfail
b9b0f622
DK
62}
63
33677a0c
DK
64testequal "Reading package lists...
65Building dependency tree...
66Reading state information...
67The following packages will be REMOVED:
7ce1ac85 68 linux-headers-1000000-1-generic (100.0.0-1)
33677a0c
DK
69 linux-image-1.0.0-2-generic (1.0.0-2)
70 linux-image-100.0.0-1-generic (100.0.0-1)
71 $CURRENTKERNEL (1)
7ce1ac85
DK
720 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
73Remv linux-headers-1000000-1-generic [100.0.0-1]
33677a0c
DK
74Remv linux-image-1.0.0-2-generic [1.0.0-2]
75Remv linux-image-100.0.0-1-generic [100.0.0-1]
76Remv $CURRENTKERNEL [1]" aptget autoremove -sV
77
b9b0f622
DK
78testprotected
79msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
7ce1ac85 80grep -q '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list && catfail || msgpass
d269b88d 81
33677a0c
DK
82testequal 'Reading package lists...
83Building dependency tree...
84Reading state information...
85The following packages will be REMOVED:
7ce1ac85
DK
86 linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
870 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
88Remv linux-headers-1000000-1-generic [100.0.0-1]
33677a0c
DK
89Remv linux-image-1.0.0-2-generic [1.0.0-2]' aptget autoremove -s
90
b9b0f622
DK
91testprotected 1.0.0-2-generic
92msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
7ce1ac85 93grep -q '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list && msgpass || catfail
33677a0c
DK
94testequal 'Reading package lists...
95Building dependency tree...
96Reading state information...
7ce1ac85
DK
97The following packages will be REMOVED:
98 linux-headers-1000000-1-generic
990 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
100Remv linux-headers-1000000-1-generic [100.0.0-1]' aptget autoremove -s