From 7be20755641a83a51c0d41820170966c931b5415 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 5 Nov 2012 10:18:18 +0100 Subject: use apt-config to get the /etc/apt/apt.conf.d dir --- debian/apt.auto-removal.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debian/apt.auto-removal.sh b/debian/apt.auto-removal.sh index 8f6fc2efc..741183c41 100644 --- a/debian/apt.auto-removal.sh +++ b/debian/apt.auto-removal.sh @@ -17,7 +17,8 @@ set -e # packages in the database because this runs from a postinst script, and apt # will overwrite the db when it exits. -config_file=/etc/apt/apt.conf.d/01autoremove-kernels +eval $(apt-config shell APT_CONF_D Dir::Etc::parts/d) +config_file=${APT_CONF_D}/01autoremove-kernels installed_version="$1" running_version="$(uname -r)" -- cgit v1.2.3 From c1719bdbe919ae5814cbcfe5afc3f04d3ccd7efb Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 5 Nov 2012 10:27:17 +0100 Subject: get dpkg from apt-config as well and add robustness against missing/failing apt-config (for paranoia) --- debian/apt.auto-removal.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/debian/apt.auto-removal.sh b/debian/apt.auto-removal.sh index 741183c41..2094372df 100644 --- a/debian/apt.auto-removal.sh +++ b/debian/apt.auto-removal.sh @@ -17,9 +17,15 @@ set -e # packages in the database because this runs from a postinst script, and apt # will overwrite the db when it exits. + +# eval $(apt-config shell APT_CONF_D Dir::Etc::parts/d) +test -n "${APT_CONF_D}" || APT_CONF_D="/etc/apt/apt.conf.d" config_file=${APT_CONF_D}/01autoremove-kernels +eval $(apt-config shell DPKG Dir::bin::dpkg/f) +test -n "$DPKG" || DPKG="/usr/bin/dpkg" + installed_version="$1" running_version="$(uname -r)" @@ -29,11 +35,11 @@ version_test_gt () local version_test_gt_sedexp="s/[._-]\(pre\|rc\|test\|git\|old\|trunk\)/~\1/g" local version_a="`echo "$1" | sed -e "$version_test_gt_sedexp"`" local version_b="`echo "$2" | sed -e "$version_test_gt_sedexp"`" - dpkg --compare-versions "$version_a" gt "$version_b" + $DPKG --compare-versions "$version_a" gt "$version_b" return "$?" } -list=$(dpkg -l 'linux-image-[0-9]*'|awk '/^ii/ { print $2 }' | sed -e's/linux-image-//') +list=$($DPKG -l 'linux-image-[0-9]*'|awk '/^ii/ { print $2 }' | sed -e's/linux-image-//') latest_version="" for i in $list; do -- cgit v1.2.3 From 0b9f0e9bba678c3e5327a260faee96ea3a71df79 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 5 Nov 2012 11:31:29 +0100 Subject: add testcase for the autoremove feature --- debian/apt.auto-removal.sh | 3 +- test/integration/test-kernel-helper-autoremove | 33 ++++++++++++++++++++++ .../test-kernel-helper-autoremove.fake-dpkg | 13 +++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100755 test/integration/test-kernel-helper-autoremove create mode 100644 test/integration/test-kernel-helper-autoremove.fake-dpkg diff --git a/debian/apt.auto-removal.sh b/debian/apt.auto-removal.sh index 2094372df..e1b1c92d4 100644 --- a/debian/apt.auto-removal.sh +++ b/debian/apt.auto-removal.sh @@ -18,7 +18,6 @@ set -e # will overwrite the db when it exits. -# eval $(apt-config shell APT_CONF_D Dir::Etc::parts/d) test -n "${APT_CONF_D}" || APT_CONF_D="/etc/apt/apt.conf.d" config_file=${APT_CONF_D}/01autoremove-kernels @@ -39,7 +38,7 @@ version_test_gt () return "$?" } -list=$($DPKG -l 'linux-image-[0-9]*'|awk '/^ii/ { print $2 }' | sed -e's/linux-image-//') +list=$(${DPKG} -l 'linux-image-[0-9]*'|awk '/^ii/ { print $2 }' | sed -e's/linux-image-//') latest_version="" for i in $list; do diff --git a/test/integration/test-kernel-helper-autoremove b/test/integration/test-kernel-helper-autoremove new file mode 100755 index 000000000..a4c31283e --- /dev/null +++ b/test/integration/test-kernel-helper-autoremove @@ -0,0 +1,33 @@ +#!/bin/sh + +set -e + +# setup testdir +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +TMPDIR=$(mktemp -d) +cd $TMPDIR +addtrap "cd /; rm -rf $TMPDIR" + +# create mock environment +mkdir apt.conf.d +cat > aptconfig.conf < Date: Mon, 5 Nov 2012 11:39:47 +0100 Subject: also check that the running kernel is kept --- test/integration/test-kernel-helper-autoremove | 4 +++- test/integration/test-kernel-helper-autoremove.fake-dpkg | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/integration/test-kernel-helper-autoremove b/test/integration/test-kernel-helper-autoremove index a4c31283e..4c0571b13 100755 --- a/test/integration/test-kernel-helper-autoremove +++ b/test/integration/test-kernel-helper-autoremove @@ -28,6 +28,8 @@ sh ${TESTDIR}/../../debian/apt.auto-removal.sh # and ensure its there, valid and version 10.0.0-1 is there too test -e $TMPDIR/apt.conf.d/01autoremove-kernels apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-10.0.0-1-generic\.\*" +# ... and also that the running kernel is exlucded +apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-$(uname -r)\.\*" # done -msgpass \ No newline at end of file +msgpass diff --git a/test/integration/test-kernel-helper-autoremove.fake-dpkg b/test/integration/test-kernel-helper-autoremove.fake-dpkg index aec6d4418..a365c5370 100644 --- a/test/integration/test-kernel-helper-autoremove.fake-dpkg +++ b/test/integration/test-kernel-helper-autoremove.fake-dpkg @@ -3,7 +3,7 @@ set -e if [ "$1" = "-l" ]; then echo "ii linux-image-1.0.0-2-generic 1.0.01-2 amd64" - echo "ii linux-image-3.5.0-17-generic 3.5.0-17 amd64" + echo "ii linux-image-$(uname -r) not-used amd64" echo "ii linux-image-10.0.0-1-generic 10.0.0.1-1 amd64" elif [ "$1" = "--compare-versions" ]; then dpkg "$1" "$2" "$3" "$4" -- cgit v1.2.3