summaryrefslogtreecommitdiffstats
path: root/hooks/maybe-merged-usr
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xhooks/maybe-merged-usr/essential00.sh36
-rwxr-xr-xhooks/maybe-merged-usr/extract00.sh27
-rwxr-xr-xhooks/maybe-merged-usr/setup00.sh27
3 files changed, 90 insertions, 0 deletions
diff --git a/hooks/maybe-merged-usr/essential00.sh b/hooks/maybe-merged-usr/essential00.sh
new file mode 100755
index 0000000..a23f2f7
--- /dev/null
+++ b/hooks/maybe-merged-usr/essential00.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+set -eu
+
+ver=$(dpkg-query --root="$1" -f '${db:Status-Status} ${Source} ${Version}' --show usr-is-merged 2>/dev/null || printf '')
+case "$ver" in
+ '')
+ echo "no package called usr-is-merged is installed -- not running merged-usr essential hook" >&2
+ exit 0
+ ;;
+ 'installed mmdebstrap-dummy-usr-is-merged 1')
+ echo "dummy usr-is-merged package installed -- running merged-usr essential hook" >&2
+ ;;
+ 'installed usrmerge '*)
+ echo "usr-is-merged package from src:usrmerge installed -- not running merged-usr essential hook" >&2
+ exit 0
+ ;;
+ *)
+ echo "unexpected situation for package usr-is-merged: $ver" >&2
+ exit 1
+ ;;
+esac
+
+# 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/extract00.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/extract00.sh b/hooks/maybe-merged-usr/extract00.sh
new file mode 100755
index 0000000..dc88450
--- /dev/null
+++ b/hooks/maybe-merged-usr/extract00.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 extract hook" >&2
+ exit 0
+else
+ echo "package usr-is-merged found -- running merged-usr extract 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/extract00.sh" ] && [ -x "$p/merged-usr/essential00.sh" ]; then
+ "$p/merged-usr/extract00.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..a6bd712
--- /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/extract00.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