-for kernel in $kernels; do
- echo " \"^linux-image-${kernel}$\";" >> "$config_file".dpkg-new
- echo " \"^linux-image-extra-${kernel}$\";" >> "$config_file".dpkg-new
- echo " \"^linux-signed-image-${kernel}$\";" >> "$config_file".dpkg-new
- echo " \"^linux-backports-modules-.*-${kernel}$\";" >> "$config_file".dpkg-new
- echo " \"^linux-headers-${kernel}$\";" >> "$config_file".dpkg-new
-done
-cat >> "$config_file".dpkg-new <<EOF
- };
-};
+ for package in $(apt-config dump --no-empty --format '%v%n' 'APT::VersionedKernelPackages'); do
+ for kernel in $kernels; do
+ echo " \"^${package}-${kernel}$\";"
+ done
+ done
+ echo '};'
+ if [ "${APT_AUTO_REMOVAL_KERNELS_DEBUG:-true}" = 'true' ]; then
+ cat <<EOF
+/* Debug information:
+# dpkg list:
+$(dpkg -l | grep '\(linux\|kfreebsd\|gnumach\)-image-')
+# list of installed kernel packages:
+$list
+# list of different kernel versions:
+$debverlist
+# Installing kernel: $installed_version ($1)
+# Running kernel: $running_version ($unamer)
+# Last kernel: $latest_version
+# Previous kernel: $previous_version
+# Kernel versions list to keep:
+$debkernels
+# Kernel packages (version part) to protect:
+$kernels
+*/