]> git.saurik.com Git - apt.git/blob - test/integration/test-kernel-helper-autoremove
support kfreebsd and hurd in the kernel hook
[apt.git] / test / integration / test-kernel-helper-autoremove
1 #!/bin/sh
2 set -e
3
4 TESTDIR=$(readlink -f $(dirname $0))
5 . $TESTDIR/framework
6 setupenvironment
7 configarchitecture 'amd64'
8
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
18
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'
23
24 testsuccess aptmark auto "$CURRENTKERNEL" 'linux-image-1.0.0-2-generic' 'linux-image-100.0.0-1-generic'
25
26 cat > ./fake-dpkg <<EOF
27 #!/bin/sh
28 exec $(aptconfig dump --no-empty --format='%v ' 'DPKG::options') "\$@"
29 EOF
30 chmod +x ./fake-dpkg
31 echo 'Dir::Bin::dpkg "./fake-dpkg";' > rootdir/etc/apt/apt.conf.d/99fakedpkg
32
33 # install fake-dpkg into it
34 catfail() {
35 echo >&2
36 echo >&2 '### List of protected kernels:'
37 cat >&2 protected.list
38 msgfail
39 }
40
41 testprotected() {
42 rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
43
44 testsuccess runapt sh ${TESTDIR}/../../debian/apt.auto-removal.sh "$@"
45
46 msgtest 'Check kernel autoremoval protection list' 'is created'
47 test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels && msgpass || msgfail
48
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
51
52 msgtest 'Check kernel autoremoval protection list' 'can be parsed'
53 grep -q '^[A-Z]: ' protected.list && catfail || msgpass
54
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 testequal "Reading package lists...
63 Building dependency tree...
64 Reading state information...
65 The 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)
69 0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
70 Remv linux-image-1.0.0-2-generic [1.0.0-2]
71 Remv linux-image-100.0.0-1-generic [100.0.0-1]
72 Remv $CURRENTKERNEL [1]" aptget autoremove -sV
73
74 testprotected
75 msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
76 grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && catfail || msgpass
77
78 testequal 'Reading package lists...
79 Building dependency tree...
80 Reading state information...
81 The following packages will be REMOVED:
82 linux-image-1.0.0-2-generic
83 0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
84 Remv linux-image-1.0.0-2-generic [1.0.0-2]' aptget autoremove -s
85
86 testprotected 1.0.0-2-generic
87 msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
88 grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && msgpass || catfail
89 testequal 'Reading package lists...
90 Building dependency tree...
91 Reading state information...
92 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.' aptget autoremove -s