From 3db3779b6a37c5682bf11a1801c66d9542b4d93f Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Mon, 16 Jan 2023 08:15:07 +0100 Subject: [PATCH] add hooks/maybe-jessie-or-older and hooks/maybe-merged-usr --- hooks/maybe-jessie-or-older/extract00.sh | 28 +++++++++++++++++++++ hooks/maybe-jessie-or-older/extract01.sh | 31 ++++++++++++++++++++++++ hooks/maybe-merged-usr/essential00.sh | 25 +++++++++++++++++++ hooks/maybe-merged-usr/setup00.sh | 27 +++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100755 hooks/maybe-jessie-or-older/extract00.sh create mode 100755 hooks/maybe-jessie-or-older/extract01.sh create mode 100755 hooks/maybe-merged-usr/essential00.sh create mode 100755 hooks/maybe-merged-usr/setup00.sh diff --git a/hooks/maybe-jessie-or-older/extract00.sh b/hooks/maybe-jessie-or-older/extract00.sh new file mode 100755 index 0000000..dbd3af8 --- /dev/null +++ b/hooks/maybe-jessie-or-older/extract00.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +set -eu + +# if dpkg is new enough, do nothing +# we cannot ask dpkg-query about the version because dpkg is only extracted +# but not installed at this point +dpkg_ver="$(chroot "$1" dpkg --version | grep --extended-regexp --only-matching '[0-9]+\.[0-9.]+')" +if dpkg --compare-versions "$dpkg_ver" ge 1.17.11; then + echo "dpkg version $dpkg_ver is >= 1.17.11 -- not running jessie-or-older extract00 hook" >&2 + exit 0 +else + echo "dpkg version $dpkg_ver is << 1.17.11 -- running jessie-or-older extract00 hook" >&2 +fi + +# resolve the script path using several methods in order: +# 1. using dirname -- "$0" +# 2. using ./hooks +# 3. using /usr/share/mmdebstrap/hooks/ +for p in "$(dirname -- "$0")/.." ./hooks /usr/share/mmdebstrap/hooks; do + if [ -x "$p/jessie-or-older/extract00.sh" ] && [ -x "$p/jessie-or-older/extract01.sh" ]; then + "$p/jessie-or-older/extract00.sh" "$1" + exit 0 + fi +done + +echo "cannot find jessie-or-older hook anywhere" >&2 +exit 1 diff --git a/hooks/maybe-jessie-or-older/extract01.sh b/hooks/maybe-jessie-or-older/extract01.sh new file mode 100755 index 0000000..1d26475 --- /dev/null +++ b/hooks/maybe-jessie-or-older/extract01.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +set -eu + +# If the init package has not been extracted, then it is not part of the +# Essential:yes set and we do not need this workaround. This holds true for the +# init package version 1.34 and later. Instead of asking apt about the init +# version (which might not be the same version that was picked to be installed) +# we check for the presence of the init package by checking whether +# /usr/share/doc/init/copyright exists. + +if [ -e "$1/usr/share/doc/init/copyright" ]; then + echo "the init package is not Essential:yes -- not running jessie-or-older extract01 hook" >&2 + exit 0 +else + echo "the init package is Essential:yes -- running jessie-or-older extract01 hook" >&2 +fi + +# resolve the script path using several methods in order: +# 1. using dirname -- "$0" +# 2. using ./hooks +# 3. using /usr/share/mmdebstrap/hooks/ +for p in "$(dirname -- "$0")/.." ./hooks /usr/share/mmdebstrap/hooks; do + if [ -x "$p/jessie-or-older/extract00.sh" ] && [ -x "$p/jessie-or-older/extract01.sh" ]; then + "$p/jessie-or-older/extract01.sh" "$1" + exit 0 + fi +done + +echo "cannot find jessie-or-older hook anywhere" >&2 +exit 1 diff --git a/hooks/maybe-merged-usr/essential00.sh b/hooks/maybe-merged-usr/essential00.sh new file mode 100755 index 0000000..e7f9c6c --- /dev/null +++ b/hooks/maybe-merged-usr/essential00.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +set -eu + +# if the usr-is-merged package cannot be installed with apt, do nothing +if ! env --chdir="$1" APT_CONFIG="$MMDEBSTRAP_APT_CONFIG" apt-cache show --no-all-versions usr-is-merged > /dev/null 2>&1; then + echo "no package called usr-is-merged found -- not running merged-usr essential hook" >&2 + exit 0 +else + echo "package usr-is-merged found -- running merged-usr essential hook" >&2 +fi + +# resolve the script path using several methods in order: +# 1. using dirname -- "$0" +# 2. using ./hooks +# 3. using /usr/share/mmdebstrap/hooks/ +for p in "$(dirname -- "$0")/.." ./hooks /usr/share/mmdebstrap/hooks; do + if [ -x "$p/merged-usr/setup00.sh" ] && [ -x "$p/merged-usr/essential00.sh" ]; then + "$p/merged-usr/essential00.sh" "$1" + exit 0 + fi +done + +echo "cannot find merged-usr hook anywhere" >&2 +exit 1 diff --git a/hooks/maybe-merged-usr/setup00.sh b/hooks/maybe-merged-usr/setup00.sh new file mode 100755 index 0000000..56afc13 --- /dev/null +++ b/hooks/maybe-merged-usr/setup00.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +set -eu + +env --chdir="$1" APT_CONFIG="$MMDEBSTRAP_APT_CONFIG" apt-get update --error-on=any + +# if the usr-is-merged package cannot be installed with apt, do nothing +if ! env --chdir="$1" APT_CONFIG="$MMDEBSTRAP_APT_CONFIG" apt-cache show --no-all-versions usr-is-merged > /dev/null 2>&1; then + echo "no package called usr-is-merged found -- not running merged-usr setup hook" >&2 + exit 0 +else + echo "package usr-is-merged found -- running merged-usr setup hook" >&2 +fi + +# resolve the script path using several methods in order: +# 1. using dirname -- "$0" +# 2. using ./hooks +# 3. using /usr/share/mmdebstrap/hooks/ +for p in "$(dirname -- "$0")/.." ./hooks /usr/share/mmdebstrap/hooks; do + if [ -x "$p/merged-usr/setup00.sh" ] && [ -x "$p/merged-usr/essential00.sh" ]; then + "$p/merged-usr/setup00.sh" "$1" + exit 0 + fi +done + +echo "cannot find merged-usr hook anywhere" >&2 +exit 1