diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2023-08-15 00:47:06 +0200 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2023-08-17 21:24:20 -0400 |
commit | ba14c842e1b6b241f04377a93e68d857e8f3aaa5 (patch) | |
tree | 4ad27329ed0f989960b9b9250e2d637742397228 | |
parent | 32078c3bfac9cb7d46dafb814a385efbd993da3e (diff) |
WIP - foreign hostswip-foreign-hosts
-rw-r--r-- | src/pvm-common.sh.inc | 22 | ||||
-rwxr-xr-x | src/pvmbootstrap.sh | 23 |
2 files changed, 36 insertions, 9 deletions
diff --git a/src/pvm-common.sh.inc b/src/pvm-common.sh.inc index 1e37408..a6f5841 100644 --- a/src/pvm-common.sh.inc +++ b/src/pvm-common.sh.inc @@ -28,8 +28,26 @@ readonly MOUNTS_ERR_MSG="some PVM mountpoints are mounted - possibly orphans fro readonly MOUNTVARS_ERR_MSG="FIXME: pvm_setup_loopdev() was called in an improper state - one of [ \$bootdir , \$workdir , \$loopdev ] is already set" -# shellcheck source=/usr/lib/libretools/messages.sh -source "$(librelib messages)" +if [[ -f "$(librelib messages 2> /dev/null)" ]] +then # shellcheck source=/usr/lib/libretools/messages.sh + source "$(librelib messages)" +else # non-parabola systems: simulate libretools messages + error() { printf "[ERROR]:$@\n" ; } + warning() { printf "[WARN]: $@\n" ; } + prose() { printf " $@\n" ; } + msg() { printf " ==> $@\n" ; } + msg2() { printf " --> $@\n" ; } + CanSudo=0 ; (( EUID )) && which sudo &> /dev/null && echo "password:" && sudo msg 'parabola-vmbootstrap init' && CanSudo=1 + CanSu=0 ; (( EUID )) && (( ! CanSudo )) && echo "root password:" && su -c "msg 'parabola-vmbootstrap init' ;" && CanSu=1 + sudo() { ( (( CanSudo )) && sudo "${@}" ) || + ( (( CanSu )) && su -c "${*}" ) || ${*} ; } + alias pacman=$( ( [[ -x ./pacman-static ]] && echo './' ) || \ + ( [[ -f "${THIS_DIR}"/pacman-static ]] && echo "${THIS_DIR}"/ ) )pacman-static + alias arch-chroot=chroot + readonly EXIT_INVALIDARGUMENT=2 + readonly EXIT_SUCCESS=0 + readonly EXIT_FAILURE=1 +fi pvm_get_script() # (script_name) diff --git a/src/pvmbootstrap.sh b/src/pvmbootstrap.sh index 8ca2ad8..f0ac664 100755 --- a/src/pvmbootstrap.sh +++ b/src/pvmbootstrap.sh @@ -34,12 +34,13 @@ readonly DEF_MIRROR=https://repo.parabola.nu readonly DEF_ROOT_MB=32000 readonly DEF_BOOT_MB=150 readonly DEF_SWAP_MB=0 -readonly PKGS_ALL=( haveged net-tools ) -readonly PKGS_armv7h=( ) -readonly PKGS_i686=( grub ) -readonly PKGS_ppc64le=( ) -readonly PKGS_riscv64=( ) -readonly PKGS_x86_64=( grub ) +readonly PKGS_ALL=( haveged net-tools \ + $(which pacman &> /dev/null || echo pacman-static) ) +readonly PKGS_armv7h=( ) +readonly PKGS_i686=( grub ) +readonly PKGS_ppc64le=( ) +readonly PKGS_riscv64=( ) +readonly PKGS_x86_64=( grub ) # misc constants readonly PKGS_NETWORKING=( dhcpcd ) @@ -127,6 +128,9 @@ usage() pvm_bootstrap() # assumes: $arch $imagefile $loopdev $workdir , traps: INT TERM RETURN { + # sanity checks + sudo which losetup &> /dev/null || ! error "failed to find losetup" || return "$EXIT_FAILURE" + # prompt to clobber if the target output file already exists pvm_check_no_mounts || return "$EXIT_FAILURE" mkdir -p "$(dirname "$imagefile")" || return "$EXIT_FAILURE" @@ -232,7 +236,12 @@ pvm_bootstrap() # assumes: $arch $imagefile $loopdev $workdir , traps: INT TERM local cache_msg="caching (${#PkgsCached[*]}) packages into the work chroot:" local cachedir="$workdir/$CACHE_DIR" msg "$pacstrap_msg" ; prose "${Pkgs[*]}" ; - sudo pacstrap -GMc -C "$pacconf" "$workdir" ${Pkgs[*]} || return "$EXIT_FAILURE" + if (( ! IS_FOREIGN_HOST )) + then sudo pacstrap -GMc -C "$pacconf" "$workdir" ${Pkgs[*]} || return "$EXIT_FAILURE" + else sudo pacman -Sy --config "$pacconf" \ + --root "$workdir" --cachedir "$cachedir" \ + --noconfirm "${Pkgs[@]}" || return "$EXIT_FAILURE" + fi if (( ${#PkgsCached[*]} )) then msg2 "${cache_msg}" ; prose "${PkgsCached[*]}" ; sudo pacman -S --config "$pacconf" --downloadonly \ |