]> git.saurik.com Git - apt.git/commitdiff
use a configurable list of versioned kernel packages
authorDavid Kalnischkies <david@kalnischkies.de>
Mon, 10 Mar 2014 16:53:22 +0000 (17:53 +0100)
committerDavid Kalnischkies <david@kalnischkies.de>
Thu, 13 Mar 2014 12:58:46 +0000 (13:58 +0100)
With APT::VersionedKernelPackages users have the option of adding
packages like pre-build out-of-tree modules to the list of automatically
protected from being autoremoved.

debian/apt.auto-removal.sh
debian/apt.conf.autoremove
test/integration/framework
test/integration/test-bug-1078697-missing-source-hashes [deleted file]
test/integration/test-kernel-helper-autoremove
test/integration/test-kernel-helper-autoremove.fake-dpkg [deleted file]
test/integration/test-ubuntu-bug-1078697-missing-source-hashes [new file with mode: 0755]

index d105f440aa6f6601908c71ae35db247a00f8f70e..9c4a4157d5f0fed1aa55b485eac3282ad545f56c 100644 (file)
@@ -72,22 +72,23 @@ $previous_version
 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"
index 9684c9c7db0a1f8d35bc6cd089a9387cc7617611..ea68f88fc2fbe3f81c8b826e419e8e6d6e293acc 100644 (file)
@@ -9,6 +9,15 @@ APT
        "^gnumach-image.*";
   };
 
+  VersionedKernelPackages
+  {
+       "linux-image";
+       "linux-image-extra";
+       "linux-signed-image";
+       "linux-backports-modules-.*";
+       "linux-headers";
+  };
+
   Never-MarkAuto-Sections
   {
        "metapackages";
index c623e62310449525542be805c81456fe4db77d44..dad8c99f01d581f941ad8ab7b0725a9dd4a384e7 100644 (file)
@@ -93,14 +93,15 @@ msgdone() {
 
 runapt() {
        msgdebug "Executing: ${CCMD}$*${CDEBUG} "
-       local CMD="$1"
+       local CMD="${BUILDDIRECTORY}/$1"
+       if [ "$1" = 'sh' ]; then CMD='sh'; fi
        shift
        if [ -f ./aptconfig.conf ]; then
-               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
+               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $CMD "$@"
        elif [ -f ../aptconfig.conf ]; then
-               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
+               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $CMD "$@"
        else
-               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
+               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${BUILDDIRECTORY} $CMD "$@"
        fi
 }
 aptconfig() { runapt apt-config "$@"; }
@@ -198,6 +199,7 @@ setupenvironment() {
        touch var/lib/dpkg/available
        mkdir -p usr/lib/apt
        ln -s ${METHODSDIR} usr/lib/apt/methods
+       ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
        cd ..
        local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
        if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
diff --git a/test/integration/test-bug-1078697-missing-source-hashes b/test/integration/test-bug-1078697-missing-source-hashes
deleted file mode 100755 (executable)
index 6fcb856..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/sh
-set -e
-
-TESTDIR=$(readlink -f $(dirname $0))
-. $TESTDIR/framework
-setupenvironment
-configarchitecture "i386"
-
-msgtest 'Test apt-ftparchive source with missing hashes in .dsc'
-
-touch aptarchive/foo_1.0.tar.gz
-cat > aptarchive/foo_1.0.dsc << EOF
-Format: 3.0 (native)
-Source: foo
-Binary: foo
-Architecture: all
-Version: 1.0
-Package-List: 
- foo deb admin extra
-Files: 
- d41d8cd98f00b204e9800998ecf8427e 0 foo_1.0.tar.gz
-EOF
-
-# check for the SHA hashes
-aptftparchive sources aptarchive/ > aptarchive/Sources  2>/dev/null || msgfail
-test -n "$(grep Checksums-Sha512 aptarchive/Sources)" && msgpass || msgfail
-
-for hash in sha512sum sha256sum sha1sum; do
-    for f in foo_1.0.tar.gz foo_1.0.dsc; do
-        SUM=$($hash aptarchive/$f | cut -d' ' -f1)
-        msgtest "Test $hash hash matches for $f"
-        NEEDLE="$SUM $(stat -c%s aptarchive/$f) $f"
-        test -n "$SUM" &&  test -n "$(grep "$NEEDLE" aptarchive/Sources)" && msgpass || msgfail 
-    done
-done
index 2b165d100d6ad962c3b98bf3ff07705bbe458707..be30c6f6e7b6d9e51b3ded3b7f56fab34ba63ef1 100755 (executable)
@@ -1,55 +1,68 @@
 #!/bin/sh
-
 set -e
 
-# setup testdir
 TESTDIR=$(readlink -f $(dirname $0))
 . $TESTDIR/framework
+setupenvironment
+configarchitecture 'native'
 
-TMPDIR=$(mktemp -d)
-cd $TMPDIR
-addtrap "cd /; rm -rf $TMPDIR"
+# the executed script would use the installed apt-config,
+# which is outside of our control
+msgtest 'Check that the installed apt-config supports' '--no-empty'
+if apt-config dump --no-empty >/dev/null 2>&1; then
+       msgpass
+else
+       msgskip
+       exit 0
+fi
 
-# create mock environment
-mkdir apt.conf.d
-cat > aptconfig.conf <<EOF
-Dir::Etc::parts "$TMPDIR/apt.conf.d";
-Dir::bin::dpkg "$TMPDIR/fake-dpkg";
+# install fake-dpkg into it
+cat > ./fake-dpkg <<EOF
+#!/bin/sh
+set -e
+if [ "\$1" = "-l" ]; then
+    echo "ii  linux-image-1.0.0-2-generic  1.0.0-2  amd64"
+    echo "ii  linux-image-\$(uname -r)  not-used  amd64"
+    echo "ii linux-image-100.0.0-1-generic  100.0.0.1-1  amd64"
+else
+    dpkg "\$@"
+fi
 EOF
-APT_CONFIG=aptconfig.conf
-export APT_CONFIG
+chmod +x ./fake-dpkg
+echo 'Dir::Bin::dpkg "./fake-dpkg";' > rootdir/etc/apt/apt.conf.d/99fakedpkg
 
-# install fake-dpkg into it
-install -m755 $TESTDIR/test-kernel-helper-autoremove.fake-dpkg $TMPDIR/fake-dpkg
+catfail() {
+       echo >&2
+       echo >&2 '### List of protected kernels:'
+       cat >&2 protected.list
+       msgfail
+}
 
-# run the helper
-sh ${TESTDIR}/../../debian/apt.auto-removal.sh
+testprotected() {
+       rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
 
-msgtest 'Check that kernel autoremoval list is correctly created'
-# and ensure its there, valid and version 10.0.0-1 is there too
-test -e $TMPDIR/apt.conf.d/01autoremove-kernels && msgpass || msgfail
+       testsuccess runapt sh ${TESTDIR}/../../debian/apt.auto-removal.sh "$@"
 
-msgtest 'Check that most recent kernel is saved from autoremoval'
-apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-10.0.0-1-generic" && msgpass || msgfail
+       msgtest 'Check kernel autoremoval protection list' 'is created'
+       test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels && msgpass || msgfail
 
-# ... and also that the running kernel is excluded
-msgtest 'Check that running kernel is saved from autoremoval'
-apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-$(uname -r)" && msgpass || msgfail
+       msgtest 'Check kernel autoremoval protection list' 'can be dumped'
+       aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove' >protected.list 2>&1 && msgpass || catfail
 
-# and that the old kernel is *not* excluded from autoremoval
-msgtest 'Check that older kernels are not excluded from autoremoval'
-apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-1\.0\.01-2-generic" && msgfail || msgpass
+       msgtest 'Check kernel autoremoval protection list' 'can be parsed'
+       grep -q '^[A-Z]: ' protected.list && catfail || msgpass
 
-msgtest "Check that the older kernel is retained when it's being installed"
-sh ${TESTDIR}/../../debian/apt.auto-removal.sh 1.0.01-2-generic
-test -e $TMPDIR/apt.conf.d/01autoremove-kernels
-if ! apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-10.0.0-1-generic" \
-   || ! apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-$(uname -r)" \
-   || ! apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-1\.0\.01-2-generic"
-then
-       msgfail
-else
-       msgpass
-fi
+       msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
+       grep -q '^\^linux-image-100\.0\.0-1-generic\$$' protected.list && msgpass || catfail
+
+       msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
+       grep -q "^\\^linux-image-$(uname -r)\\\$\$" protected.list && msgpass || catfail
+}
+
+testprotected
+msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
+grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && catfail || msgpass
 
-# done
+testprotected 1.0.0-2-generic
+msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
+grep -q '^\^linux-image-1\.0\.0-2-generic\$$' protected.list && msgpass || catfail
diff --git a/test/integration/test-kernel-helper-autoremove.fake-dpkg b/test/integration/test-kernel-helper-autoremove.fake-dpkg
deleted file mode 100644 (file)
index a365c53..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-set -e
-
-if [ "$1" = "-l" ]; then
-    echo "ii  linux-image-1.0.0-2-generic  1.0.01-2  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"
-else
-    dpkg $@
-fi
-
diff --git a/test/integration/test-ubuntu-bug-1078697-missing-source-hashes b/test/integration/test-ubuntu-bug-1078697-missing-source-hashes
new file mode 100755 (executable)
index 0000000..6fcb856
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture "i386"
+
+msgtest 'Test apt-ftparchive source with missing hashes in .dsc'
+
+touch aptarchive/foo_1.0.tar.gz
+cat > aptarchive/foo_1.0.dsc << EOF
+Format: 3.0 (native)
+Source: foo
+Binary: foo
+Architecture: all
+Version: 1.0
+Package-List: 
+ foo deb admin extra
+Files: 
+ d41d8cd98f00b204e9800998ecf8427e 0 foo_1.0.tar.gz
+EOF
+
+# check for the SHA hashes
+aptftparchive sources aptarchive/ > aptarchive/Sources  2>/dev/null || msgfail
+test -n "$(grep Checksums-Sha512 aptarchive/Sources)" && msgpass || msgfail
+
+for hash in sha512sum sha256sum sha1sum; do
+    for f in foo_1.0.tar.gz foo_1.0.dsc; do
+        SUM=$($hash aptarchive/$f | cut -d' ' -f1)
+        msgtest "Test $hash hash matches for $f"
+        NEEDLE="$SUM $(stat -c%s aptarchive/$f) $f"
+        test -n "$SUM" &&  test -n "$(grep "$NEEDLE" aptarchive/Sources)" && msgpass || msgfail 
+    done
+done