From be12db7e43d2ee962bdf9a5736b7a14f6fc889de Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 18 Dec 2020 14:47:33 +0100 Subject: [PATCH 1/2] build.sh: add option to build in a 'bind-mount' directory This is way experimental. Trouble might arise from the automounter when it comes to expiring the wrong directory (the one bound). --- tools/build.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tools/build.sh b/tools/build.sh index e9bb81a..d4b1c2b 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -11,7 +11,7 @@ die() { } die_usage() { - die "usage: $0 example-1.2.3-0 [--purge]" + die "usage: $0 example-1.2.3-0 [--purge] [--bind directory]" } ere_quote() { @@ -23,9 +23,10 @@ log_cmd() { "$@" } -eval set -- $(getopt --options "" --longoptions purge -- "$@") +eval set -- $(getopt --options "" --longoptions purge,bind: -- "$@") while true; do case "$1" in + --bind) opt_bind=1;bind_dir=$2;shift 2;; --purge) opt_purge=1;shift;; --) shift;break;; *) die "internal error: unknown option $!" @@ -46,6 +47,8 @@ if [ ! -d "/package/pkg/$PKG" ]; then log_cmd chown build:build "/pkg/$PKG" fi +test $(grep -e "\b/pkg/$PKG\b" /proc/self/mounts | wc -l) -gt 1 && die "/pkg/$PKG mounted more than once" + if [ "$(stat -c %U "/pkg/$PKG")" != "build" ] && [ -z "$opt_purge" ] ; then echo "/pkg/$PKG is no longer owned by build user" echo "rerun with --purge if you want to build from scratch" @@ -57,10 +60,20 @@ if [ -n "$opt_purge" ]; then test -z "$PKG" && die "internal error: PKG is empty" log_cmd find "/pkg/$PKG" -mindepth 1 -delete test "$(stat -c %U "/pkg/$PKG")" = "build" || log_cmd chown build:build "/pkg/$PKG" + if [ -n "$opt_bind" -a -d $bind_dir ]; then + log_cmd find "$bind_dir" -mindepth 1 -delete + fi fi chmod a+rx "$PKG.build.sh" +if [ -n "$opt_bind" ]; then + mkdir -p "$bind_dir" + chown build:build "$bind_dir" + stat /pkg/$PKG > /dev/null # make shure /pkg/$PKG is 'auto-mounted' + log_cmd mount --bind "$bind_dir" /pkg/$PKG || die "failed to mount $bind_dir over /pkg/$PKG" +fi + echo "sudo -u build script -q -e -c \"./$PKG.build.sh\" /package/pkg/$PKG/$PKG.build.log" ( sudo -u build script -q -e -c "./$PKG.build.sh" /package/pkg/$PKG/$PKG.build.log @@ -70,3 +83,11 @@ echo "sudo -u build script -q -e -c \"./$PKG.build.sh\" /package/pkg/$PKG/$PKG.b # make double sure PKG is not empty even if bugs are introduced in code above test -z "$PKG" && die "internal error: PKG is empty" log_cmd chown -R bin:bin "/pkg/$PKG" + +if [ -n "$opt_bind" ]; then + test -z "$PKG" && die "internal error: PKG is empty" + test $(ls "/pkg/$PKG" | wc -l) = 0 && die "/pkg/$PKG contains no files" + log_cmd umount /pkg/$PKG + log_cmd cp -ax $bind_dir/* /package/pkg/$PKG + log_cmd chown bin:bin "/package/pkg/$PKG" +fi From 437d09469e5c81ea631041bfc7a9963ade487082 Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 8 Jan 2021 11:29:46 +0100 Subject: [PATCH 2/2] build.sh: use subdir for build and check mp based on dev/inode --- tools/build.sh | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/tools/build.sh b/tools/build.sh index d4b1c2b..5b029d6 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -47,8 +47,6 @@ if [ ! -d "/package/pkg/$PKG" ]; then log_cmd chown build:build "/pkg/$PKG" fi -test $(grep -e "\b/pkg/$PKG\b" /proc/self/mounts | wc -l) -gt 1 && die "/pkg/$PKG mounted more than once" - if [ "$(stat -c %U "/pkg/$PKG")" != "build" ] && [ -z "$opt_purge" ] ; then echo "/pkg/$PKG is no longer owned by build user" echo "rerun with --purge if you want to build from scratch" @@ -60,18 +58,25 @@ if [ -n "$opt_purge" ]; then test -z "$PKG" && die "internal error: PKG is empty" log_cmd find "/pkg/$PKG" -mindepth 1 -delete test "$(stat -c %U "/pkg/$PKG")" = "build" || log_cmd chown build:build "/pkg/$PKG" - if [ -n "$opt_bind" -a -d $bind_dir ]; then - log_cmd find "$bind_dir" -mindepth 1 -delete + if [ -n "$opt_bind" -a -d "$bind_dir/pkg_bindmnt" ]; then + log_cmd find "$bind_dir/pkg_bindmnt" -mindepth 1 -delete fi fi chmod a+rx "$PKG.build.sh" if [ -n "$opt_bind" ]; then - mkdir -p "$bind_dir" - chown build:build "$bind_dir" - stat /pkg/$PKG > /dev/null # make shure /pkg/$PKG is 'auto-mounted' - log_cmd mount --bind "$bind_dir" /pkg/$PKG || die "failed to mount $bind_dir over /pkg/$PKG" + mkdir -p "$bind_dir/pkg_bindmnt" + chown build:build "$bind_dir/pkg_bindmnt" + # check that '/pkg/$PKG' differs from intended location (i.e. isn't mounted already) + if [ $(stat --format=%D:%i "$bind_dir/pkg_bindmnt") != $(stat --format=%D:%i /pkg/$PKG) ]; then + log_cmd mount --bind "$bind_dir/pkg_bindmnt" /pkg/$PKG + # prevent automount from unmounting + exec 3