From 05d8b5f25364444401fbfbfe9029539450474763 Mon Sep 17 00:00:00 2001 From: Johannes 'josch' Schauer Date: Mon, 17 Aug 2020 19:01:27 +0200 Subject: [PATCH] hooks/eatmydata: download instead of copy-ing from host --- hooks/eatmydata/README.txt | 5 ++++ hooks/eatmydata/customize.sh | 17 ++++++++++- hooks/eatmydata/extract.sh | 55 +++++++++++++++++++++++++++++++++--- 3 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 hooks/eatmydata/README.txt diff --git a/hooks/eatmydata/README.txt b/hooks/eatmydata/README.txt new file mode 100644 index 0000000..84659e9 --- /dev/null +++ b/hooks/eatmydata/README.txt @@ -0,0 +1,5 @@ +Adding this directory with --hook-directory will result in mmdebstrap using +dpkg inside an eatmydata wrapper script. This will result in spead-ups on +systems where sync() takes some time. Using --dpkgopt=force-unsafe-io will have +a lesser effect compared to eatmydata. See: +https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=613428 diff --git a/hooks/eatmydata/customize.sh b/hooks/eatmydata/customize.sh index 589b007..6dfcf62 100755 --- a/hooks/eatmydata/customize.sh +++ b/hooks/eatmydata/customize.sh @@ -4,7 +4,22 @@ set -exu rootdir="$1" -rm "$rootdir/usr/bin/eatmydata" +if [ -e "$rootdir/var/lib/dpkg/arch" ]; then + chrootarch=$(head -1 "$rootdir/var/lib/dpkg/arch") +else + chrootarch=$(dpkg --print-architecture) +fi +libdir="/usr/lib/$(dpkg-architecture -a $chrootarch -q DEB_HOST_MULTIARCH)" + +# if eatmydata was actually installed properly, then we are not removing +# anything here +if ! chroot "$rootdir" dpkg-query --list eatmydata; then + rm "$rootdir/usr/bin/eatmydata" +fi +if ! chroot "$rootdir" dpkg-query --list libeatmydata1; then + rm "$rootdir$libdir"/libeatmydata.so* +fi + mv "$rootdir/usr/bin/dpkg.orig" "$rootdir/usr/bin/dpkg" sync diff --git a/hooks/eatmydata/extract.sh b/hooks/eatmydata/extract.sh index a6f5929..593c339 100755 --- a/hooks/eatmydata/extract.sh +++ b/hooks/eatmydata/extract.sh @@ -4,10 +4,57 @@ set -exu rootdir="$1" -libdir="/usr/lib/$(dpkg-architecture -q DEB_HOST_MULTIARCH)" -mkdir -p "$rootdir$libdir" -cp -a $libdir/libeatmydata* "$rootdir$libdir" -cp -a /usr/bin/eatmydata "$rootdir/usr/bin" +if [ -e "$rootdir/var/lib/dpkg/arch" ]; then + chrootarch=$(head -1 "$rootdir/var/lib/dpkg/arch") +else + chrootarch=$(dpkg --print-architecture) +fi + +eval $(apt-config shell trusted Dir::Etc::trusted/f) +eval $(apt-config shell trustedparts Dir::Etc::trustedparts/d) +tmpfile=$(mktemp --tmpdir="$rootdir/tmp") +cat << END > "$tmpfile" +Apt::Architecture "$chrootarch"; +Apt::Architectures "$chrootarch"; +Dir "$rootdir"; +Dir::Etc::Trusted "$trusted"; +Dir::Etc::TrustedParts "$trustedparts"; +END +# we run "apt-get download --print-uris" in a temporary directory, to make sure +# that the packages do not already exist in the current directory, or otherwise +# nothing will be printed for them +tmpdir=$(mktemp --directory --tmpdir="$rootdir/tmp") +env --chdir="$tmpdir" APT_CONFIG="$tmpfile" apt-get download --print-uris eatmydata libeatmydata1 \ + | sed -ne "s/^'\([^']\+\)'\s\+\([^\s]\+\)\s\+\([0-9]\+\)\s\+\(SHA256:[a-f0-9]\+\)$/\1 \2 \3 \4/p" \ + | while read uri fname size hash; do + echo "processing $fname" >&2 + if [ -e "$tmpdir/$fname" ]; then + echo "$tmpdir/$fname already exists" >&2 + exit 1 + fi + env --chdir="$tmpdir" APT_CONFIG="$tmpfile" /usr/lib/apt/apt-helper download-file "$uri" "$fname" Checksum-FileSize:"$size" "$hash" + case "$fname" in + eatmydata_*_all.deb) + mkdir -p "$rootdir/usr/bin" + dpkg-deb --fsys-tarfile "$tmpdir/$fname" \ + | tar --directory="$rootdir/usr/bin" --strip-components=3 --extract --verbose ./usr/bin/eatmydata + ;; + libeatmydata1_*_$chrootarch.deb) + libdir="/usr/lib/$(dpkg-architecture -a $chrootarch -q DEB_HOST_MULTIARCH)" + mkdir -p "$rootdir$libdir" + dpkg-deb --fsys-tarfile "$tmpdir/$fname" \ + | tar --directory="$rootdir$libdir" --strip-components=4 --extract --verbose --wildcards ".$libdir/libeatmydata.so*" + ;; + *) + echo "unexpected filename: $fname" >&2 + exit 1 + ;; + esac + rm "$tmpdir/$fname" +done +rm "$tmpfile" +rmdir "$tmpdir" + mv "$rootdir/usr/bin/dpkg" "$rootdir/usr/bin/dpkg.orig" cat << END > "$rootdir/usr/bin/dpkg" #!/bin/sh