test-kernel-helper-autoremove 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/sh
  2. set -e
  3. TESTDIR=$(readlink -f $(dirname $0))
  4. . $TESTDIR/framework
  5. setupenvironment
  6. configarchitecture 'native'
  7. # the executed script would use the installed apt-config,
  8. # which is outside of our control
  9. msgtest 'Check that the installed apt-config supports' '--no-empty'
  10. if apt-config dump --no-empty >/dev/null 2>&1; then
  11. msgpass
  12. else
  13. msgskip
  14. exit 0
  15. fi
  16. # install fake-dpkg into it
  17. cat > ./fake-dpkg <<EOF
  18. #!/bin/sh
  19. set -e
  20. if [ "\$1" = "-l" ]; then
  21. echo "ii linux-image-1.0.0-2-generic 1.0.0-2 amd64"
  22. echo "ii linux-image-\$(uname -r) not-used amd64"
  23. echo "ii linux-image-100.0.0-1-generic 100.0.0.1-1 amd64"
  24. else
  25. dpkg "\$@"
  26. fi
  27. EOF
  28. chmod +x ./fake-dpkg
  29. echo 'Dir::Bin::dpkg "./fake-dpkg";' > rootdir/etc/apt/apt.conf.d/99fakedpkg
  30. catfail() {
  31. echo >&2
  32. echo >&2 '### List of protected kernels:'
  33. cat >&2 protected.list
  34. msgfail
  35. }
  36. testprotected() {
  37. rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
  38. testsuccess runapt sh ${TESTDIR}/../../debian/apt.auto-removal.sh "$@"
  39. msgtest 'Check kernel autoremoval protection list' 'is created'
  40. test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels && msgpass || msgfail
  41. msgtest 'Check kernel autoremoval protection list' 'can be dumped'
  42. aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove' >protected.list 2>&1 && msgpass || catfail
  43. msgtest 'Check kernel autoremoval protection list' 'can be parsed'
  44. grep -q '^[A-Z]: ' protected.list && catfail || msgpass
  45. msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
  46. grep -q '^\^linux-image-100\.0\.0-1-generic\$$' protected.list && msgpass || catfail
  47. msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
  48. grep -q "^\\^linux-image-$(uname -r)\\\$\$" protected.list && msgpass || catfail
  49. }
  50. testprotected
  51. msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
  52. grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && catfail || msgpass
  53. testprotected 1.0.0-2-generic
  54. msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
  55. grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && msgpass || catfail