From 7ee14620856fdfa9cf422f4d43ace25b1e35565a Mon Sep 17 00:00:00 2001 From: Xavier Date: Thu, 11 May 2023 21:54:17 -0400 Subject: [PATCH] pacwrap v0.9.12 pacwrap-sync: -g and -p options to manually invoke container configuration pacwrap-sync: Setting the environment variable PACWRAP_PASSTHROUGH will passthrough pacwrap-sync parameters to 'sudo pacman' at the end of transaction. pacwrap-sync: Renamed --explicit to --explicit-foreign to diambiguate and differentiate from pacwrap --explicit pacwrap: --explicit to passthrough -S, -Q, and -R to pacwrap-exec pacwrap-exec: -p/--pacman option to execute pacman in specificed instance with stated arguments pacwrap-common: PACWRAP_PACCACHE_ARGUMENTS variable. It can be set in the environment to override. pacwrap-man: Updated documentation to reflect current feature sets. pacwrap-man: Fixed distro_check() to not output garbage when being packaged. Among other miscallenous fixes and cleanup. --- bin/pacwrap | 5 +- bin/pacwrap-common | 3 +- bin/pacwrap-exec | 22 +++++++-- bin/pacwrap-man | 112 ++++++++++++++++++++++++++++----------------- bin/pacwrap-sync | 52 +++++++++++++++------ bin/pacwrap-utils | 2 +- 6 files changed, 132 insertions(+), 64 deletions(-) diff --git a/bin/pacwrap b/bin/pacwrap index c3fb328..80930f8 100755 --- a/bin/pacwrap +++ b/bin/pacwrap @@ -29,7 +29,7 @@ main () { case $SWITCH in P) source $(type -P $PS_SCRIPT);; C) source $(type -P $CREATE_SCRIPT);; - E) source $(type -P $EXEC_SCRIPT);; + E*) source $(type -P $EXEC_SCRIPT);; S) source $(type -P $SYNC_SCRIPT);; U) source $(type -P $UTILS_SCRIPT);; h|V) manual_script;; @@ -39,6 +39,7 @@ main () { parse_args () { for var in "$@"; do case $var in + --explicit) SWITCH=Ep;; --process|-P) SWITCH=P;; --create|-C) SWITCH=C;; --execute|-E) SWITCH=E;; @@ -50,7 +51,7 @@ parse_args () { -V|--version) SWITCH=V;; -E*|-C*|-S*|-U*|-P*) SWITCH=$(echo $var | cut -c 2-2);; *) ARGS+=("$var") - esac; done + esac; [[ $SWITCH ]] && break; done } main $@ diff --git a/bin/pacwrap-common b/bin/pacwrap-common index 471fbae..48c52c4 100755 --- a/bin/pacwrap-common +++ b/bin/pacwrap-common @@ -39,7 +39,7 @@ ARROW="$CYAN$BOLD->$RESET" ARROW_GREEN="$GREEN$BOLD->$RESET" ARROW_RED="$RED$BOLD->$RESET" -VER="v0.9.11 ${BOLD}BETA$RESET" +VER="v0.9.12 ${BOLD}BETA$RESET" MAN_SCRIPT="pacwrap-man" EXEC_SCRIPT="pacwrap-exec" @@ -55,6 +55,7 @@ LOG_ERR_ERROR=3 [[ ! $PACWRAP_DATA_DIR ]] && PACWRAP_DATA_DIR="$HOME/.local/share/pacwrap" [[ ! $PACWRAP_CACHE_DIR ]] && PACWRAP_CACHE_DIR="$HOME/.cache/pacwrap" [[ ! $PACWRAP_CONFIG_DIR ]] && PACWRAP_CONFIG_DIR="$HOME/.config/pacwrap" +[[ ! $PACWRAP_PACCACHE_ARGUMENTS ]] && PACWRAP_PACCACHE_ARGUMENTS="-rk 1" VERBOSE="/dev/null" diff --git a/bin/pacwrap-exec b/bin/pacwrap-exec index e7cd450..4bdf3ce 100755 --- a/bin/pacwrap-exec +++ b/bin/pacwrap-exec @@ -23,8 +23,9 @@ source pacwrap-common main () { parse_args "$@" init 1 - + case $SWITCH in + *pS*|*pQ*|*pR*) execute_pacman;; *rc*|*cr*) execute_fakeroot "${ARGS[@]}";; *rs*|*sr*) execute_fakeroot bash;; *s) execute_sandbox bash;; @@ -51,18 +52,33 @@ parse_args () { local sbdefined= for var in "$@"; do case $var in + --explicit) continue;; + --pacman) SWITCH+="p";; -V|--version) SWITCH="V";; --root) SWITCH+="r";; --shell) SWITCH+="s";; - --dep) SWITCH+="d";; - --exec) SWITCH+="rc";; + --exec) SWITCH+="rc";; -E*) SWITCH+=$(echo $var | cut -c 3-);; + -*|-Q*|-R*) if [[ $SWITCH == Ep* ]]; then SWITCH+=$(echo $var | cut -c 2-); else ARGS+=("$var"); fi;; *) [[ $sbdefined ]] && ARGS+=("$var") && continue INSTANCE=$var sbdefined=1;; esac; done } +execute_pacman() { + local runtime_args="pacman -$(echo $SWITCH | cut -c 3-)" + + [[ ${#ARGS[@]} > 0 ]] && runtime_args+=" ${ARGS[@]}" + ([[ $SWITCH == *S* ]] || [[ $SWITCH == *R* ]]) && + [[ ! $(query_confirm_yN "Execute $RESET'$YELLOW$runtime_args$RESET'$BOLD on $INSTANCE") ]] && return + + execute_fakeroot $runtime_args --noconfirm --log=/tmp/pacman.log 2>$VERBOSE + [[ $? == 0 ]] && + ([[ $SWITCH == *S ]] || [[ $SWITCH == *R* ]]) && + $SYNC_SCRIPT -Sgp $INSTANCE +} + execute_sandbox () { [[ ! -f $INSTANCE_SCRIPT ]] && log_error $LOG_ERR_HELP "Script $INSTANCE_SCRIPT not found." 1 diff --git a/bin/pacwrap-man b/bin/pacwrap-man index 8ab8ac2..018f254 100755 --- a/bin/pacwrap-man +++ b/bin/pacwrap-man @@ -34,8 +34,6 @@ main () { *V*) version;; *) log_invalid_arguments $1 esac - - distro_warn } parse_args () { @@ -82,8 +80,8 @@ cat << _VERSION $VER_DISPLAY $VER Copyright (C) 2023 Xavier R.M. -Website: https://pacwrap.sapphirus.org/ -Github: https://git.sapphirus.org/ +Website: https://git.sapphirus.org/pacwrap +Github: https://github.com/sapphirusberyl/pacwrap This program may be freely redistributed under the terms of the GNU General Public License v3. @@ -110,44 +108,30 @@ _USAGE man_execute() { cat <<_USAGE ${HEADER}EXECUTE OPTIONS$HEADER_RESET -${SUB_HEADER}--sandbox=TARGET$RESET -${SUB_TEXT}Specify the target sandbox to execute with bubblewrap. - ${SUB_HEADER}-r, --root$RESET ${SUB_TEXT}Execute operation with fakeroot. Facilitates a command with faked root privileges. ${SUB_HEADER}-s, --shell$RESET ${SUB_TEXT}Invoke a bash shell +${SUB_HEADER}-p, --pacman$RESET +${SUB_TEXT}Execute arguments with pacman in specified target. + +${SUB_HEADER}-c, --exec$RESET +${SUB_TEXT}Execute application with arguments in specified target. + _USAGE } - - - man_sync() { cat << _USAGE ${HEADER}SYNCHRONIZAtION OPTIONS$HEADER_RESET -_USAGE -case $HELP in - Sy*) - - cat << _USAGE -${SUB_HEADER}-[yyyy], --sync$RESET -${SUB_TEXT}Synchronize containers and their databases. Additional suffixes will force synchronization operations. -_USAGE - ;; - *) -cat << _USAGE -${SUB_HEADER}-[yyyy], --sync$RESET -${SUB_TEXT}Synchronize containers and their databases. Additional suffixes will force synchronization operations. +${SUB_HEADER}-y, --sync$RESET +${SUB_TEXT}Synchronize containers and their databases. Specify up to 4 times to force synchronization operations. ${SUB_HEADER}-u, --update$RESET -${SUB_TEXT}Executes chroot update routine. - -${SUB_HEADER}-y$RESET -${SUB_TEXT}Trigger a container synchronization event. +${SUB_TEXT}Execute container update routine. ${SUB_HEADER}-n, --no-confirm$RESET ${SUB_TEXT}Override confirmation prompts and confirm all operations. @@ -156,7 +140,6 @@ ${SUB_HEADER}-g, --generate-config$RESET ${SUB_TEXT}Generate a new pacman.conf for specified targets. _USAGE -esac } man_utils() { @@ -165,29 +148,68 @@ ${HEADER}UTILITY OPTIONS$HEADER_RESET ${SUB_HEADER}-d, --delete$RESET ${SUB_TEXT}Deletes the root and home directories of specified targets. +${SUB_HEADER}-ls, --summarylist$RESET +${SUB_TEXT}Summarize information on container filesystems and their associated dependencies. + +$TAB${SUB_HEADER}-d$RESET +$TAB${SUB_TEXT}Specify up to 4 times to display different sets of space consumption statistics. + +${SUB_HEADER}-e, --edit$RESET +${SUB_TEXT}Edit configuration files associated with pacwrap and containers in specified $EDITOR. + +$TAB${SUB_HEADER}-c$RESET +$TAB${SUB_TEXT}Edit container configuration for target. + +$TAB${SUB_HEADER}-p$RESET +$TAB${SUB_TEXT}Edit global pacman.conf template. + +$TAB${SUB_HEADER}-pt$RESET +$TAB${SUB_TEXT}Edit pacman.conf template for target. + +${SUB_HEADER}-v, --view$RESET +${SUB_TEXT}View configuration files associated with pacwrap and containers in specified $EDITOR. + +$TAB${SUB_HEADER}-ip$RESET +$TAB${SUB_TEXT}View sync pacman.conf for target. + +$TAB${SUB_HEADER}-ips$RESET +$TAB${SUB_TEXT}View syncdb pacman.conf for target. + +$TAB${SUB_HEADER}-l$RESET +$TAB${SUB_TEXT}View pacwrap.log + ${SUB_HEADER}-r, --replicate$RESET ${SUB_TEXT}Replicate target container from configuration. + +${SUB_HEADER}-t, --tar$RESET +${SUB_TEXT}Grab configuration files from specified tar archive. ${SUB_HEADER}-l, --link$RESET ${SUB_TEXT}Create a symbolic link of a target container's filesystem directory and initialize a home directory. ${SUB_HEADER}-i, --initialize$RESET -${SUB_TEXT}Re-initialize configuration files. This can be used to synchronize pacwrap's mirrorlist with your system. +${SUB_TEXT}Initialize configuration files. This can be used to synchronize pacwrap's mirrorlist with your system. -${SUB_HEADER}-ls, --summarylist$RESET -${SUB_TEXT}SUmmarize information on container filesystems and their associated dependencies. +_USAGE +} -${SUB_HEADER}-e, --edit$RESET -${SUB_TEXT}Edit configuration files associated with pacwrap and containers. +man_copyright() { +cat << _USAGE +${HEADER}AUTHORS$HEADER_RESET +${SUB_TEXT}Copyright (c) 2023 - Xavier R.M. + +${HEADER}LICENSE$HEADER_RESET +${SUB_TEXT}This program may be freely redistributed under +$TAB${TAB}the terms of the GNU General Public License v3. _USAGE } man_version() { cat << _USAGE - ${HEADER}VERSION$HEADER_RESET - ${SUB_TEXT}pacwrap $VER$RESET - +${HEADER}VERSION$HEADER_RESET +${SUB_TEXT}pacwrap $VER$RESET + _USAGE } @@ -207,14 +229,16 @@ ${SUB_HEADER}-C, --create$RESET ${SUB_TEXT}Facilitates the creation of container filesystems. ${SUB_HEADER}-S, --sync$RESET -${SUB_TEXT}Synhcronize package databases and update packages in target chroots. -$TAB${TAB}pacwrap-sync is invoked which facilitates an update and synchronization operation on specified targets. +${SUB_TEXT}Synchronize package databases and update packages in target containers. + +${SUB_HEADER}--explicit$RESET +${SUB_TEXT}Passes through arguments to pacman in specified target. ${SUB_HEADER}-U, --utils$RESET ${SUB_TEXT}Invoke miscellaneous utilities to manage containers. ${SUB_HEADER}-P, --process$RESET -${SUB_TEXT}Report information and manage running container processes +${SUB_TEXT}Report information and manage running container processes. ${SUB_HEADER}-E, --execute$RESET ${SUB_TEXT}Executes application in target container using bubblewrap. @@ -239,6 +263,7 @@ print_manual() { man_summary case $HELP in + COPYRIGHT|copyright|cr) man_copyright;; VERSION|version|V|v) man_version;; UTILS|utils|U|u) man_utils;; SYNC|sync|s*|S*) man_sync;; @@ -248,10 +273,13 @@ print_manual() { man_execute man_sync man_utils - man_version;; - *) - [[ $HELP ]] && log_error "Operation '$HELP' not documented" 1 + man_version + man_copyright;; + *) + [[ $HELP ]] && log_error "Operation '$HELP' not documented" 1 esac + + if [[ ! $HELP ]]; then distro_warn; fi } main $@ diff --git a/bin/pacwrap-sync b/bin/pacwrap-sync index 2358afe..7fad78e 100755 --- a/bin/pacwrap-sync +++ b/bin/pacwrap-sync @@ -40,14 +40,17 @@ main () { init $PACWRAP_CREATE [[ ! $SWITCH ]] || - ([[ ! $SYNC_UPDATE ]] && [[ ! $SYNC_UPGRADE ]] && [[ ! $SYNC_CONFIG ]]) && - log_invalid_arguments $@ + ([[ ! $SYNC_UPDATE ]] && [[ ! $SYNC_UPGRADE ]] && + [[ ! $SYNC_CONFIG ]] && [[ ! $UPDATE_CONFIG ]]) && + log_invalid_arguments $@ - if [[ $SYNC_CONFIG ]]; then + if [[ $UPDATE_CONFIG ]] || [[ $SYNC_CONFIG ]]; then local instance=${ARGS[0]} [[ ! $instance ]] || [[ ! -d $INSTANCE_ROOT_DIR/$instance ]] && return log "$ARROW Configuring container..." - sync_pacman_conf && return + [[ $SYNC_CONFIG ]] && sync_pacman_conf + [[ $UPDATE_CONFIG ]] && update_config + return fi if [[ $SYNC_UPGRADE ]] || ([[ $SYNC_UPDATE ]] && [[ ! $SYNC_FORCE ]]); then @@ -61,8 +64,7 @@ main () { [[ ${#roots[@]} > 0 ]] && [[ ! $SYNC_FORCE ]] && log "$BAR_GREEN Starting contingent container upgrade..." - for b in ${baserootdeps[@]}; do - [[ ${syncreq[$(return_base)]} ]] && syncreq=1 && break; done + for b in ${baserootdeps[@]}; do [[ ${syncreq[$(return_base)]} ]] && syncreq=1 && break; done if [[ $SYNC_OVERRIDE ]] || [[ $syncreq ]]; then update_links ${syncroots[@]} @@ -70,15 +72,22 @@ main () { [[ $SYNC_FORCE ]] && return fi - [[ ${#roots[@]} -le 0 ]] && return + if [[ ${#roots[@]} -le 0 ]]; then + [[ $PACWRAP_PASSTHROUGH ]] && system_update + log "$ARROW_GREEN Transaction complete." + return + fi if [[ $SYNC_UPGRADE ]] || [[ $SYNC_UPDATE ]]; then configure_containers ${roots[@]} update ${roots[@]} - [[ -f /usr/bin/paccache ]] && - paccache --cachedir $INSTANCE_PACMAN_CACHE -r -k 1 --min-mtime "14 days ago" - + [[ $(type -p paccache) ]] && + paccache --cachedir $INSTANCE_PACMAN_CACHE $PACWRAP_PACCACHE_ARGUMENTS fi + + [[ $PACWRAP_PASSTHROUGH ]] && system_update + + log "$ARROW_GREEN Transaction complete." } parse_args () { @@ -87,7 +96,7 @@ parse_args () { --generate-config|-g) SWITCH+="g";; --update|-u) SWITCH+="u";; --noconfirm|-n) SWITCH+="n";; - --explicit|-e) SWITCH+="e";; + --explicit-foreign|-ef) SWITCH+="ef";; --sync|-y) SWITCH+="y";; -S*) SWITCH+=$(echo $var | cut -c 3-);; *) ARGS+=("$var");; @@ -97,13 +106,14 @@ parse_args () { script_init () { log_to_file "Running '$RUNTIME_ARGS'" - [[ $SWITCH == g ]] && SYNC_CONFIG=1 + [[ $SWITCH == *g ]] && SYNC_CONFIG=1 + [[ $SWITCH == *gp ]] && UPDATE_CONFIG=1 [[ $SWITCH == *y* ]] && SYNC_UPDATE=1 [[ $SWITCH == *u* ]] && SYNC_UPGRADE=1 [[ $SWITCH == *yy* ]] && SYNC_FOREIGN=1 [[ $SWITCH == *yyy* ]] && SYNC_OVERRIDE=1 [[ $SWITCH == *yyyy* ]] && SYNC_FORCE=1 - [[ $SWITCH == *e* ]] && SYNC_EXPLICIT_FOREIGN=1 + [[ $SWITCH == *ef* ]] && SYNC_EXPLICIT_FOREIGN=1 syncroots=(${roots[@]}) @@ -283,8 +293,7 @@ update_config() { [[ "$(echo ${package_list[@]})" != "$(echo ${old_local_pkgs[@]})" ]] && generate_config ${package_list[@]} - ((amt_done++)) - progress_bar + advance_progress 1 } sync_pacman_conf () { @@ -438,6 +447,19 @@ update () { log_to_file "Updated containers: $(echo $@)" } +system_update() { + local pacman_args="S" + + [[ $SYNC_UPDATE ]] && pacman_args+="y" + [[ $SYNC_FOREIGN ]] && pacman_args+="y" + [[ $SYNC_UPGRADE ]] && pacman_args+="u" + + local pacman="sudo pacman -$pacman_args" + + [[ ${#pacman_args} > 0 ]] && + [[ $(query_confirm_Yn "Execute $RESET'$YELLOW$pacman$RESET'$BOLD on system") ]] && + $pacman +} configure_containers () { local amt=$((${#@}*3)) diff --git a/bin/pacwrap-utils b/bin/pacwrap-utils index 0424a3f..6eaceb8 100755 --- a/bin/pacwrap-utils +++ b/bin/pacwrap-utils @@ -38,7 +38,7 @@ main () { [[ $SWITCH != Uls* ]] && log_to_file "Running '$RUNTIME_ARGS'" case $SWITCH in - Uc*) [[ -f /usr/bin/paccache ]] && + Uc*) [[ $(type -p paccache) ]] && paccache --cachedir $INSTANCE_CACHE_DIR ${ARGS[@]};; Ui*) initialize_data_directory;; Ur*) replicate ${baserootdeps[@]} ${rootdeps[@]} ${roots[@]};;