EOF
)
-cat > "$config_file".dpkg-new <<EOF
+generateconfig() {
+ cat <<EOF
// File autogenerated by $0, do not edit
APT
{
NeverAutoRemove
{
EOF
-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
+ apt-config dump --no-empty --format '%v%n' 'APT::VersionedKernelPackages' | while read package; do
+ for kernel in $kernels; do
+ echo " \"^${package}-${kernel}$\";"
+ done
+ done
+ cat <<EOF
};
};
EOF
-mv "$config_file".dpkg-new "$config_file"
+}
+generateconfig > "${config_file}.dpkg-new"
+mv "${config_file}.dpkg-new" "$config_file"