]>
git.saurik.com Git - apt.git/blob - debian/apt.auto-removal.sh
4 # Author: Steve Langasek <steve.langasek@canonical.com>
6 # Mark as not-for-autoremoval those kernel packages that are:
7 # - the currently booted version
8 # - the kernel version we've been called for
9 # - the latest kernel version (determined using rules copied from the grub
10 # package for deciding which kernel to boot)
11 # - the second-latest kernel version, if the booted kernel version is
12 # already the latest and this script is called for that same version,
13 # to ensure a fallback remains available in the event the newly-installed
14 # kernel at this ABI fails to boot
15 # In the common case, this results in exactly two kernels saved, but it can
16 # result in three kernels being saved. It's better to err on the side of
17 # saving too many kernels than saving too few.
19 # We generate this list and save it to /etc/apt/apt.conf.d instead of marking
20 # packages in the database because this runs from a postinst script, and apt
21 # will overwrite the db when it exits.
24 eval $(apt-config shell APT_CONF_D Dir::Etc::parts/d)
25 test -n "${APT_CONF_D}" || APT_CONF_D
="/etc/apt/apt.conf.d"
26 config_file
=${APT_CONF_D}/01autoremove
-kernels
28 eval $(apt-config shell DPKG Dir::bin::dpkg/f)
29 test -n "$DPKG" || DPKG
="/usr/bin/dpkg"
31 installed_version
="$1"
32 running_version
="$(uname -r)"
37 local version_test_gt_sedexp
="s/[._-]\(pre\|rc\|test\|git\|old\|trunk\)/~\1/g"
38 local version_a
="`echo "$1" | sed -e "$version_test_gt_sedexp"`"
39 local version_b
="`echo "$2" | sed -e "$version_test_gt_sedexp"`"
40 $DPKG --compare-versions "$version_a" gt
"$version_b"
44 list
="$(${DPKG} -l | awk '/^ii[ ]+(linux|kfreebsd|gnumach)-image-[0-9]+\./ && $2 !~ /-dbg$/ { print $2 }' | sed -e 's#\(linux\|kfreebsd\|gnumach\)-image-##')"
49 if version_test_gt
"$i" "$latest_version"; then
50 previous_version
="$latest_version"
52 elif version_test_gt
"$i" "$previous_version"; then
57 if [ "$latest_version" != "$installed_version" ] \
58 || [ "$latest_version" != "$running_version" ] \
59 || [ "$installed_version" != "$running_version" ]
61 # We have at least two kernels that we have reason to think the
62 # user wants, so don't save the second-newest version.
66 kernels
="$(echo "$latest_version
69 $previous_version" | sort -u | sed -e 's#\.#\\.#g' )"
73 // DO NOT EDIT! File autogenerated by $0
77 apt
-config dump
--no-empty --format '%v%n' 'APT::VersionedKernelPackages' | while read package
; do
78 for kernel
in $kernels; do
79 echo " \"^${package}-${kernel}$\";"
84 generateconfig
> "${config_file}.dpkg-new"
85 mv "${config_file}.dpkg-new" "$config_file"