You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

182 lines
7.8 KiB

  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'amd64'
  7. CURRENTKERNEL="linux-image-$(uname -r | tr '[A-Z]' '[a-z]')"
  8. insertinstalledpackage "$CURRENTKERNEL" 'amd64' '5-1'
  9. # debug packages do not need our protection
  10. insertinstalledpackage "${CURRENTKERNEL}-dbg" 'amd64' '5-1'
  11. # but other kernel flavours should be protected
  12. insertinstalledpackage "${CURRENTKERNEL}-686-pae" 'i386' '5-1'
  13. insertinstalledpackage "${CURRENTKERNEL}-rt" 'amd64' '5-1'
  14. # some more versions
  15. insertinstalledpackage 'linux-image-1.0.0-2-generic' 'amd64' '1.0.0-2'
  16. insertinstalledpackage 'linux-image-100.0.0-1-generic' 'amd64' '100.0.0-1'
  17. # kernel metapackages should be ignored
  18. insertinstalledpackage 'linux-image-amd64' 'amd64' '200-1'
  19. insertinstalledpackage 'linux-image-686-pae' 'i386' '300-1'
  20. # ensure that the '.' is really a dot and not a wildcard
  21. insertinstalledpackage 'linux-headers-1000000-1-generic' 'amd64' '100.0.0-1'
  22. # ensure that the '+' is really a plus and not a regexp quantifier
  23. insertinstalledpackage "${CURRENTKERNEL}+variant" 'amd64' '5-1'
  24. testsuccess aptmark auto "$CURRENTKERNEL" "${CURRENTKERNEL}-dbg" "${CURRENTKERNEL}-686-pae:i386" "${CURRENTKERNEL}-rt" \
  25. 'linux-image-1.0.0-2-generic' 'linux-image-100.0.0-1-generic' 'linux-headers-1000000-1-generic' "${CURRENTKERNEL}+variant"
  26. testsuccess aptmark hold "${CURRENTKERNEL}-rt"
  27. testprotected() {
  28. rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
  29. testsuccess runapt sh "${TESTDIR}/../../debian/apt.auto-removal.sh" "$@"
  30. testfailure test -s rootdir/tmp/testsuccess.output
  31. msgtest 'Check kernel autoremoval protection list' 'is created'
  32. testsuccess --nomsg test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels
  33. testfilestats 'rootdir/etc/apt/apt.conf.d/01autoremove-kernels' '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:444"
  34. msgtest 'Check kernel autoremoval protection list' 'can be dumped'
  35. testsuccess --nomsg aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove'
  36. cp rootdir/tmp/testsuccess.output protected.list
  37. msgtest 'Check kernel autoremoval protection list' 'can be parsed'
  38. testfailure --nomsg grep '^[A-Z]: ' protected.list
  39. msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
  40. testsuccess --nomsg grep '^\^linux-image-100\\\.0\\\.0-1-generic\$$' protected.list
  41. msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
  42. testsuccess --nomsg grep "^\\^linux-image-$(uname -r | tr '[A-Z]' '[a-z]' | sed -e 's#\.#\\\\.#g')\\\$\$" protected.list
  43. msgtest 'Check kernel autoremoval protection list does not include' 'metapackages'
  44. testfailure --nomsg grep -e '^\^linux-image-amd64\$$' -e '^\^linux-image-686-pae\$$' -e ':i386' protected.list
  45. }
  46. AUTOREMOVE='apt autoremove'
  47. if [ -n "$SUDO_USER" ]; then
  48. AUTOREMOVE="sudo $AUTOREMOVE"
  49. fi
  50. testsuccessequal "Reading package lists...
  51. Building dependency tree...
  52. Reading state information...
  53. The following packages were automatically installed and are no longer required:
  54. linux-headers-1000000-1-generic (100.0.0-1)
  55. linux-image-1.0.0-2-generic (1.0.0-2)
  56. linux-image-100.0.0-1-generic (100.0.0-1)
  57. $CURRENTKERNEL (5-1)
  58. ${CURRENTKERNEL}+variant (5-1)
  59. ${CURRENTKERNEL}-686-pae:i386 (5-1)
  60. ${CURRENTKERNEL}-dbg (5-1)
  61. Use '$AUTOREMOVE' to remove them.
  62. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV
  63. testsuccessequal "Reading package lists...
  64. Building dependency tree...
  65. Reading state information...
  66. The following packages were automatically installed and are no longer required:
  67. linux-headers-1000000-1-generic (100.0.0-1)
  68. linux-image-1.0.0-2-generic (1.0.0-2)
  69. linux-image-100.0.0-1-generic (100.0.0-1)
  70. $CURRENTKERNEL (5-1)
  71. ${CURRENTKERNEL}+variant (5-1)
  72. ${CURRENTKERNEL}-686-pae:i386 (5-1)
  73. ${CURRENTKERNEL}-dbg (5-1)
  74. ${CURRENTKERNEL}-rt (5-1)
  75. Use '$AUTOREMOVE' to remove them.
  76. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -sV --ignore-hold
  77. testequal "Reading package lists...
  78. Building dependency tree...
  79. Reading state information...
  80. 7 packages were automatically installed and are no longer required.
  81. Use '$AUTOREMOVE' to remove them.
  82. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." aptget install -s -o APT::Get::HideAutoRemove=small
  83. testequal "Reading package lists...
  84. Building dependency tree...
  85. Reading state information...
  86. The following packages will be REMOVED:
  87. linux-headers-1000000-1-generic (100.0.0-1)
  88. linux-image-1.0.0-2-generic (1.0.0-2)
  89. linux-image-100.0.0-1-generic (100.0.0-1)
  90. $CURRENTKERNEL (5-1)
  91. ${CURRENTKERNEL}+variant (5-1)
  92. ${CURRENTKERNEL}-686-pae:i386 (5-1)
  93. ${CURRENTKERNEL}-dbg (5-1)
  94. 0 upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
  95. Remv linux-headers-1000000-1-generic [100.0.0-1]
  96. Remv linux-image-1.0.0-2-generic [1.0.0-2]
  97. Remv linux-image-100.0.0-1-generic [100.0.0-1]
  98. Remv $CURRENTKERNEL [5-1]
  99. Remv ${CURRENTKERNEL}+variant [5-1]
  100. Remv ${CURRENTKERNEL}-686-pae:i386 [5-1]
  101. Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -sV
  102. msgmsg "run without parameter"
  103. testprotected
  104. msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
  105. testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
  106. export COLUMNS=99999
  107. testsuccessequal "Reading package lists...
  108. Building dependency tree...
  109. Reading state information...
  110. The following packages will be REMOVED:
  111. linux-headers-1000000-1-generic linux-image-1.0.0-2-generic ${CURRENTKERNEL}-dbg
  112. 0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
  113. Remv linux-headers-1000000-1-generic [100.0.0-1]
  114. Remv linux-image-1.0.0-2-generic [1.0.0-2]
  115. Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
  116. unset COLUMNS
  117. msgmsg "install unknown kernel"
  118. # even if installed/uname reports a kernel which we can't find via dpkg,
  119. # ensure that we still protect it just in case as these are kernels we
  120. # know for sure without complicated detection mechanisms
  121. testprotected 1.0.0-2-ungeneric
  122. msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
  123. testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
  124. msgtest 'Check kernel autoremoval protection list does include' 'unknown installed kernel'
  125. testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-ungeneric\$$' protected.list
  126. export COLUMNS=9
  127. testsuccessequal "Reading package lists...
  128. Building dependency tree...
  129. Reading state information...
  130. The following packages will be REMOVED:
  131. linux-headers-1000000-1-generic
  132. linux-image-1.0.0-2-generic
  133. ${CURRENTKERNEL}-dbg
  134. 0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
  135. Remv linux-headers-1000000-1-generic [100.0.0-1]
  136. Remv linux-image-1.0.0-2-generic [1.0.0-2]
  137. Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
  138. unset COLUMNS
  139. msgmsg "install an old kernel"
  140. testprotected 1.0.0-2-generic
  141. msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
  142. testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
  143. export COLUMNS=9
  144. testsuccessequal "Reading package lists...
  145. Building dependency tree...
  146. Reading state information...
  147. The following packages will be REMOVED:
  148. linux-headers-1000000-1-generic
  149. ${CURRENTKERNEL}-dbg
  150. 0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
  151. Remv linux-headers-1000000-1-generic [100.0.0-1]
  152. Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
  153. unset COLUMNS
  154. # rt kernel was put on hold while the protected list was generated
  155. testsuccess aptmark unhold "${CURRENTKERNEL}-rt"
  156. export COLUMNS=99999
  157. testsuccessequal "Reading package lists...
  158. Building dependency tree...
  159. Reading state information...
  160. The following packages will be REMOVED:
  161. linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg
  162. 0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
  163. Remv linux-headers-1000000-1-generic [100.0.0-1]
  164. Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
  165. unset COLUMNS