diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2023-12-26 16:14:36 -0500 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2024-01-04 16:08:54 -0500 |
commit | c3d07fa15ebf3a82b124146aebe06a318bfcc103 (patch) | |
tree | dbbfc603ec6d94e599f53105cc5d05476af4f59b | |
parent | 3134f5d10282dceaf064e614097897b6e03496ea (diff) |
handle is_in_chroot detection centrally in conf.sh
-rw-r--r-- | src/chroot-tools/chcleanup.in | 2 | ||||
-rw-r--r-- | src/chroot-tools/hooks-chcleanup.sh | 2 | ||||
-rw-r--r-- | src/chroot-tools/hooks-distcc.sh | 4 | ||||
-rwxr-xr-x | src/chroot-tools/libremakepkg | 17 | ||||
-rw-r--r-- | src/lib/conf.sh.in | 4 |
5 files changed, 16 insertions, 13 deletions
diff --git a/src/chroot-tools/chcleanup.in b/src/chroot-tools/chcleanup.in index 1cedbfe..b682050 100644 --- a/src/chroot-tools/chcleanup.in +++ b/src/chroot-tools/chcleanup.in @@ -70,7 +70,7 @@ m4_include(chcleanup.lib) ## User Interface ## DRYRUN=${DRYRUN:-false} -if [[ ! -f /.arch-chroot ]] && ! ${DRYRUN}; then +if ! is_in_chroot && ! ${DRYRUN}; then error "(chcleanup): Must be run inside of a chroot" exit 1 elif [[ "${BASH_SOURCE[0]}" != $CHCLEANUP_FILE || diff --git a/src/chroot-tools/hooks-chcleanup.sh b/src/chroot-tools/hooks-chcleanup.sh index b264811..58480ae 100644 --- a/src/chroot-tools/hooks-chcleanup.sh +++ b/src/chroot-tools/hooks-chcleanup.sh @@ -21,7 +21,7 @@ hook_pre_build+=("clean_chroot") clean_chroot() ( local copydir=$1 - if $INCHROOT; then + if is_in_chroot; then cd /startdir SANE=$SANE "$(librelib chroot/chcleanup)" else diff --git a/src/chroot-tools/hooks-distcc.sh b/src/chroot-tools/hooks-distcc.sh index a91c5ec..b5e6e68 100644 --- a/src/chroot-tools/hooks-distcc.sh +++ b/src/chroot-tools/hooks-distcc.sh @@ -58,7 +58,7 @@ distcc_start_odaemon() { # existance of programs. if $NONET && [[ -f "$copydir/bin/socat" && -f "$copydir/bin/distcc" ]]; then local home - if $INCHROOT; then + if is_in_chroot; then home=$LIBREHOME else home="$copydir/build" @@ -94,7 +94,7 @@ distcc_stop_odaemon() { local copydir=$1 local home - if $INCHROOT; then + if is_in_chroot; then home=$LIBREHOME else home="$copydir/build" diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index b75b82b..6fefacc 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -39,7 +39,6 @@ umask 0022 # Global variables: readonly _indent="$(librelib chroot/indent)" -readonly INCHROOT=$([[ -f /.arch-chroot ]] && echo true || echo false) SANE=true # can be changed with the -I flag NONET=true # can be changed with the -N flag # {PKG,SRC,SRCPKG,LOG}DEST set at runtime by makepkg.conf @@ -68,7 +67,7 @@ indent() { exit_copy() { local copydir=$1 local src_owner=$2 - if ! $INCHROOT; then + if ! is_in_chroot; then msg "Copying log and package files out of the chroot..." move_products "$copydir" "$src_owner" fi @@ -127,7 +126,7 @@ build() ( local run_ynet=() local run_nnet=() - if $INCHROOT; then + if is_in_chroot; then local _run=(sh -c "mount --bind -o ro -- ${startdir@Q} ${startdir@Q} && cd ${startdir@Q} && \$@" --) run_ynet=(unshare --mount -- "${_run[@]}") run_nnet=(unshare --mount --net -- "${_run[@]}") @@ -220,9 +219,9 @@ main() { # Parse command line options ########################################### while getopts 'n:l:w:r:INRS:h' flag ; do case "${flag}" in - n ) chroot=$OPTARG ; ! $INCHROOT || err_chflag "$flag";; - l ) copy=$OPTARG ; ! $INCHROOT || err_chflag "$flag";; - w|r) librechroot_flags+=(-$flag "$OPTARG") ; ! $INCHROOT || err_chflag "$flag";; + n ) chroot=$OPTARG ; ! is_in_chroot || err_chflag "$flag";; + l ) copy=$OPTARG ; ! is_in_chroot || err_chflag "$flag";; + w|r) librechroot_flags+=(-$flag "$OPTARG") ; ! is_in_chroot || err_chflag "$flag";; I ) SANE=false;; N ) NONET=false;; R ) repack=true; makepkg_args+=(-R);; @@ -239,7 +238,7 @@ main() { # Resolve the chroot path ############################################## local copydir - if $INCHROOT; then + if is_in_chroot; then copydir='/' else load_conf chroot.conf CHROOTDIR CHROOT || exit @@ -295,7 +294,7 @@ main() { # OK, we are starting now ############################################## # Obtain a lock on the chroot - if $INCHROOT; then + if is_in_chroot; then lock 9 "/build/.lock" \ "Waiting for existing lock on build directory to be released" else @@ -304,7 +303,7 @@ main() { fi # Create the chroot if it does not exist - if ! $INCHROOT; then + if ! is_in_chroot; then librechroot_flags+=( -n "$CHROOT" -l "$copy" diff --git a/src/lib/conf.sh.in b/src/lib/conf.sh.in index 3b1d8a2..5f72917 100644 --- a/src/lib/conf.sh.in +++ b/src/lib/conf.sh.in @@ -224,6 +224,10 @@ set_var() { return 1 # $EXIT_FAILURE } +# Usage: is_in_chroot +# Returns zero if called from with a librechroot, non-zero otherwise +is_in_chroot() { [[ -f $CHROOT_STAMP_FILE ]] ; return $? ; } + # Usage: is_nonsystemd [ chroot_dir ] # Returns zero if this host is a non-systemd OS, non-zero otherwise. # If an argument is provided, it refers to the OS under that $chroot_dir. |