]>
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 DK |
6 | setupenvironment |
7 | configarchitecture 'native' | |
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 | |
b9b0f622 DK |
19 | # install fake-dpkg into it |
20 | cat > ./fake-dpkg <<EOF | |
21 | #!/bin/sh | |
22 | set -e | |
23 | if [ "\$1" = "-l" ]; then | |
24 | echo "ii linux-image-1.0.0-2-generic 1.0.0-2 amd64" | |
25 | echo "ii linux-image-\$(uname -r) not-used amd64" | |
26 | echo "ii linux-image-100.0.0-1-generic 100.0.0.1-1 amd64" | |
27 | else | |
28 | dpkg "\$@" | |
29 | fi | |
e5bdcc87 | 30 | EOF |
b9b0f622 DK |
31 | chmod +x ./fake-dpkg |
32 | echo 'Dir::Bin::dpkg "./fake-dpkg";' > rootdir/etc/apt/apt.conf.d/99fakedpkg | |
e5bdcc87 | 33 | |
b9b0f622 DK |
34 | catfail() { |
35 | echo >&2 | |
36 | echo >&2 '### List of protected kernels:' | |
37 | cat >&2 protected.list | |
38 | msgfail | |
39 | } | |
e5bdcc87 | 40 | |
b9b0f622 DK |
41 | testprotected() { |
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 | ||
62 | testprotected | |
63 | msgtest 'Check kernel autoremoval protection list does not include' 'old kernel' | |
64 | grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && catfail || msgpass | |
d269b88d | 65 | |
b9b0f622 DK |
66 | testprotected 1.0.0-2-generic |
67 | msgtest 'Check kernel autoremoval protection list includes' 'installed kernel' | |
68 | grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && msgpass || catfail |