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