pacwrap v0.9.11

- Miscellaneous cleanup and fixes
- Interpretation of command line switches has been fixed

pacwrap-common: Additional runtime dependency conditionals
pacwrap-common: Universally defined EXEC_SCRIPT variable
pacwrap-common: get_foreign_packages()
pacwrap-common: Fixed typo
pacwrap-sync: Rudimentary argument validation
pacwrap-sync: Forcibly sync explicit packages from foreign databases with --explicit switch
pacwrap-sync: Fixed validation with manual container configuration
pacwrap-utils: Defined human parsable command switches
pacwrap-ps: Defined --kill switch
This commit is contained in:
Xavier Moffett 2023-05-10 22:51:46 -04:00
parent 828c939797
commit ee803d01e0
8 changed files with 111 additions and 109 deletions

View file

@ -20,10 +20,9 @@
source pacwrap-common source pacwrap-common
EXEC_NAME="pacwrap"
main () { main () {
parse_args "$@" parse_args "$@"
runtime_check
[[ $SWITCH != V ]] && [[ $SWITCH != h ]] && distro_warn [[ $SWITCH != V ]] && [[ $SWITCH != h ]] && distro_warn
@ -34,13 +33,11 @@ main () {
S) source $(type -P $SYNC_SCRIPT);; S) source $(type -P $SYNC_SCRIPT);;
U) source $(type -P $UTILS_SCRIPT);; U) source $(type -P $UTILS_SCRIPT);;
h|V) manual_script;; h|V) manual_script;;
*) ARGS=($@) *) log_invalid_arguments $1
log_invalid_arguments $1
esac esac
} }
parse_args () { parse_args () {
ARGS=()
for var in "$@"; do case $var in for var in "$@"; do case $var in
--process|-P) SWITCH=P;; --process|-P) SWITCH=P;;
--create|-C) SWITCH=C;; --create|-C) SWITCH=C;;
@ -52,6 +49,7 @@ parse_args () {
-h|--help) SWITCH=h;; -h|--help) SWITCH=h;;
-V|--version) SWITCH=V;; -V|--version) SWITCH=V;;
-E*|-C*|-S*|-U*|-P*) SWITCH=$(echo $var | cut -c 2-2);; -E*|-C*|-S*|-U*|-P*) SWITCH=$(echo $var | cut -c 2-2);;
*) ARGS+=("$var")
esac; done esac; done
} }

View file

@ -18,9 +18,12 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
ARGS=()
[[ $RUNTIME_ARGS ]] && return [[ $RUNTIME_ARGS ]] && return
RUNTIME_ARGS="$0 $@" RUNTIME_ARGS="$0 $@"
EXEC_NAME="${0##*/}"
BOLD=$(tput bold) BOLD=$(tput bold)
RED=$(tput setaf 1) RED=$(tput setaf 1)
@ -36,7 +39,7 @@ ARROW="$CYAN$BOLD->$RESET"
ARROW_GREEN="$GREEN$BOLD->$RESET" ARROW_GREEN="$GREEN$BOLD->$RESET"
ARROW_RED="$RED$BOLD->$RESET" ARROW_RED="$RED$BOLD->$RESET"
VER="v0.9.10 ${BOLD}BETA$RESET" VER="v0.9.11 ${BOLD}BETA$RESET"
MAN_SCRIPT="pacwrap-man" MAN_SCRIPT="pacwrap-man"
EXEC_SCRIPT="pacwrap-exec" EXEC_SCRIPT="pacwrap-exec"
@ -49,7 +52,6 @@ LOG_ERR_HELP=1
LOG_ERR_WARN=2 LOG_ERR_WARN=2
LOG_ERR_ERROR=3 LOG_ERR_ERROR=3
declare -A INSTANCE_CONFIG
[[ ! $PACWRAP_DATA_DIR ]] && PACWRAP_DATA_DIR="$HOME/.local/share/pacwrap" [[ ! $PACWRAP_DATA_DIR ]] && PACWRAP_DATA_DIR="$HOME/.local/share/pacwrap"
[[ ! $PACWRAP_CACHE_DIR ]] && PACWRAP_CACHE_DIR="$HOME/.cache/pacwrap" [[ ! $PACWRAP_CACHE_DIR ]] && PACWRAP_CACHE_DIR="$HOME/.cache/pacwrap"
[[ ! $PACWRAP_CONFIG_DIR ]] && PACWRAP_CONFIG_DIR="$HOME/.config/pacwrap" [[ ! $PACWRAP_CONFIG_DIR ]] && PACWRAP_CONFIG_DIR="$HOME/.config/pacwrap"
@ -60,6 +62,8 @@ LOCK_FILE="$PACWRAP_DATA_DIR/pacwrap.lck"
LOG_FILE="$PACWRAP_DATA_DIR/pacwrap.log" LOG_FILE="$PACWRAP_DATA_DIR/pacwrap.log"
OUTPUT_DEST=$LOG_FILE OUTPUT_DEST=$LOG_FILE
declare -A INSTANCE_CONFIG
INSTANCE_ROOT_DIR=$PACWRAP_DATA_DIR/root INSTANCE_ROOT_DIR=$PACWRAP_DATA_DIR/root
INSTANCE_HOME_DIR=$PACWRAP_DATA_DIR/home INSTANCE_HOME_DIR=$PACWRAP_DATA_DIR/home
INSTANCE_CONFIG_DIR=$PACWRAP_CONFIG_DIR/root INSTANCE_CONFIG_DIR=$PACWRAP_CONFIG_DIR/root
@ -75,11 +79,12 @@ INSTANCE_PACMAN_CACHE="$PACWRAP_CACHE_DIR/pkg"
INSTANCE_PACMAN_CFG_DIR="$PACWRAP_CONFIG_DIR/pacman" INSTANCE_PACMAN_CFG_DIR="$PACWRAP_CONFIG_DIR/pacman"
init() { init() {
runtime_check [[ $EXEC_NAME != "pacwrap" ]] &&
runtime_check
case $SWITCH in case $SWITCH in
*n*) WITCH_NOCONFIRM=1;; *n*) WITCH_NOCONFIRM=1;;
*v*) RBOSE="/dev/stdout";; *v*) VERBOSE="/dev/stdout";;
*h*|*V*) manual_script;; *h*|*V*) manual_script;;
esac esac
@ -257,6 +262,16 @@ progress_bar() {
print_progress_bar $((PROGRESS_LENGTH+1)) $bar_percent $percent print_progress_bar $((PROGRESS_LENGTH+1)) $bar_percent $percent
} }
get_foreign_packages() {
local dbsyncpkgs=()
local deps=$(return_dependencies)
for dep in ${deps[@]}; do
dbsyncpkgs+=("$($EXEC_SCRIPT $dep --root --exec pacman -Qqe | sed -z -E "s/\<base\>//g")")
done
echo ${dbsyncpkgs[@]}
}
localized_text() { localized_text() {
eval "echo \$$1_EN" eval "echo \$$1_EN"
} }
@ -351,12 +366,14 @@ _CONFIG
runtime_check() { runtime_check() {
[[ $(id -u) -lt 1000 ]] && log_error "$EXEC_NAME cannot be executed within a privileged context." 1 [[ $(id -u) -lt 1000 ]] && log_error "$EXEC_NAME cannot be executed within a privileged context." 1
if [[ ! $(type -P bwrap) ]] || [[ ! $(type -P bwrap) ]] || [[ ! $(type -P pacman-key gpg) ]]; then if [[ ! $(type -P bwrap) ]] || [[ ! $(type -P zstd ) ]] ||
[[ ! $(type -P fakechroot) ]] || [[ ! $(type -P fakeroot) ]] ||
[[ ! $(type -P pacman-key gpg) ]]; then
cat << _WARN cat << _WARN
$BOLD${RED}error:$RESET Requisite dependencies are missing. $BOLD${RED}error:$RESET Requisite dependencies are missing.
Please make sure that the following binaries are present in \$PATH: Please make sure that the following binaries are present in \$PATH:
${BOLD}bwrap$RESET, ${BOLD}zstd$RESET, ${BOLD}pacman-key$RESET or ${BOLD}gpg$RESET. ${BOLD}bwrap$RESET, ${BOLD}fakechroot${BOLD}, ${BOLD}fakeroot$RESET, ${BOLD}zstd$RESET, ${BOLD}pacman-key$RESET or ${BOLD}gpg$RESET.
_WARN _WARN
exit 2 exit 2

View file

@ -19,20 +19,15 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
source pacwrap-common source pacwrap-common
export PACWRAP_CREATE=1
EXEC_NAME="pacwrap-create"
main () { main () {
trap exit INT trap exit INT
export PACWRAP_CREATE=1
local args=$@
parse_args "$@" parse_args "$@"
init $PACWRAP_UTILS init $PACWRAP_UTILS
local instance=$INSTANCE local instance=$INSTANCE
local args="$0 $@"
log "$BAR_GREEN Initializing container $INSTANCE..." \ log "$BAR_GREEN Initializing container $INSTANCE..." \
"Initializing container $INSTANCE running '$RUNTIME_ARGS'" "Initializing container $INSTANCE running '$RUNTIME_ARGS'"
@ -53,14 +48,12 @@ main () {
} }
parse_args () { parse_args () {
ArGS=()
for var in "$@"; do case $var in for var in "$@"; do case $var in
-V|--version) SWITCH="V";;
--dep=*) DEPEND=$(echo $var | cut -c 7-);; --dep=*) DEPEND=$(echo $var | cut -c 7-);;
--verbose) SWITCH=v$SWITCH;; --is-dep) SWITCH+="d";;
--is-dep) SWITCH=d$SWITCH ;; --is-base) SWITCH+="b";;
--is-base) SWITCH=b$SWITCH;; -C*) SWITCH+=$(echo $var | cut -c 3-);;
-C*) SWITCH=$(echo $var | cut -c 3-)$SWITCH;;
-*) SWITCH=$(echo $var | cut -c 2-)$SWITCH;;
*) ARGS+=("$var");; *) ARGS+=("$var");;
esac; CLI_INVOCATION+="$var "; done esac; CLI_INVOCATION+="$var "; done
} }
@ -79,7 +72,7 @@ script_init () {
ARCHLINUX_TARBALL="archlinux-bootstrap-x86_64.tar.gz" ARCHLINUX_TARBALL="archlinux-bootstrap-x86_64.tar.gz"
ARCHLINUX_TARBALL_CACHE="$PACWRAP_CACHE_DIR/$ARCHLINUX_TARBALL" ARCHLINUX_TARBALL_CACHE="$PACWRAP_CACHE_DIR/$ARCHLINUX_TARBALL"
PARAMS="$INSTANCE --root --exec" EXEC_SCRIPT="$EXEC_SCRIPT $INSTANCE --root --exec"
MACHINE_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1) MACHINE_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1)
case $SWITCH in case $SWITCH in
@ -283,16 +276,16 @@ get_directory_pop() {
init_trust () { init_trust () {
log "$BAR_GREEN Initializing pacman trust database..." \ log "$BAR_GREEN Initializing pacman trust database..." \
"Initializing pacman trust database" "Initializing pacman trust database"
$EXEC_SCRIPT $PARAMS pacman-key --init 1>>$OUTPUT_DEST 2>>$OUTPUT_DEST $EXEC_SCRIPT pacman-key --init 1>>$OUTPUT_DEST 2>>$OUTPUT_DEST
log "$ARROW Populating pacman trust database..." log "$ARROW Populating pacman trust database..."
$EXEC_SCRIPT $PARAMS pacman-key --populate 1>>$OUTPUT_DEST 2>>$OUTPUT_DEST $EXEC_SCRIPT pacman-key --populate 1>>$OUTPUT_DEST 2>>$OUTPUT_DEST
} }
finalise () { finalise () {
log "$ARROW Generating locale..." log "$ARROW Generating locale..."
$EXEC_SCRIPT $PARAMS locale-gen 1>>$OUTPUT_DEST 2>>$OUTPUT_DEST $EXEC_SCRIPT locale-gen 1>>$OUTPUT_DEST 2>>$OUTPUT_DEST
log "$ARROW Updating certificate trust..." log "$ARROW Updating certificate trust..."
$EXEC_SCRIPT $PARAMS update-ca-trust 1>>$OUTPUT_DEST 2p>>$OUTPUT_DEST $EXEC_SCRIPT update-ca-trust 1>>$OUTPUT_DEST 2p>>$OUTPUT_DEST
[[ $C_TYPE != "BASE" ]] && sync_foreign_database [[ $C_TYPE != "BASE" ]] && sync_foreign_database
$SYNC_SCRIPT -Sg $INSTANCE $SYNC_SCRIPT -Sg $INSTANCE
[[ $C_TYPE == "BASE" ]] && sync_base_packages [[ $C_TYPE == "BASE" ]] && sync_base_packages
@ -308,7 +301,7 @@ install_packages () {
fi fi
log_to_file "Installing specified packages" log_to_file "Installing specified packages"
$EXEC_SCRIPT $PARAMS pacman -Sy ${ARGS[@]} --logfile /tmp/pacman.log --noconfirm 2>>$VERBOSE $EXEC_SCRIPT pacman -Sy ${ARGS[@]} --logfile /tmp/pacman.log --noconfirm 2>>$VERBOSE
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
log_error $ARROW_RED "Installation failed." \ log_error $ARROW_RED "Installation failed." \
"Use pacwrap -Cv and examine stdout for details." "Use pacwrap -Cv and examine stdout for details."
@ -321,9 +314,9 @@ install_packages () {
sync_base_packages () { sync_base_packages () {
log "$ARROW Some housekeeping..." "Removing arch-install-scripts" log "$ARROW Some housekeeping..." "Removing arch-install-scripts"
$EXEC_SCRIPT $PARAMS pacman -R arch-install-scripts --noconfirm --logfile /tmp/pacman.log 2>/dev/null 1>>$VERBOSE $EXEC_SCRIPT pacman -R arch-install-scripts --noconfirm --logfile /tmp/pacman.log 2>/dev/null 1>>$VERBOSE
log "$BAR_GREEN Checking $INSTANCE for updates..." "Checking $INSTANCE for updates" log "$BAR_GREEN Checking $INSTANCE for updates..." "Checking $INSTANCE for updates"
$EXEC_SCRIPT $PARAMS pacman -Syu --logfile /tmp/pacman.log --noconfirm 2>>$VERBOSE $EXEC_SCRIPT pacman -Syu --logfile /tmp/pacman.log --noconfirm 2>>$VERBOSE
} }
sync_foreign_database () { sync_foreign_database () {
@ -333,16 +326,10 @@ sync_foreign_database () {
rm -r "$INSTANCE_ROOT/var/lib/pacman/local" rm -r "$INSTANCE_ROOT/var/lib/pacman/local"
cp -rn "$INSTANCE_DEPEND_ROOT/var/lib/pacman/local" "$INSTANCE_ROOT/var/lib/pacman/" cp -rn "$INSTANCE_DEPEND_ROOT/var/lib/pacman/local" "$INSTANCE_ROOT/var/lib/pacman/"
local deps=$(return_dependencies) local dbsyncpkgs=$(get_foreign_packages)
local dbsyncpkgs=()
local i=0
for dep in ${deps[@]}; do
dbsyncpkgs[i++]="$($EXEC_SCRIPT $dep --root --exec pacman -Qqe | sed -z -E "s/\<base\>//g")"
done
[[ ${dbsyncpkgs[@]} ]] && [[ ${dbsyncpkgs[@]} ]] &&
$EXEC_SCRIPT $PARAMS pacman -Su \ $EXEC_SCRIPT pacman -Su \
--dbonly \ --dbonly \
--logfile /tmp/pacman.log \ --logfile /tmp/pacman.log \
--noconfirm ${dbsyncpkgs[@]} 2>/dev/null 1>>$VERBOSE --noconfirm ${dbsyncpkgs[@]} 2>/dev/null 1>>$VERBOSE

View file

@ -20,17 +20,14 @@
source pacwrap-common source pacwrap-common
EXEC_NAME="pacwrap-exec"
main () { main () {
export PACWRAP_EXEC=1
parse_args "$@" parse_args "$@"
init 1 init 1
case $SWITCH in case $SWITCH in
*rc*|*cr*) execute_fakeroot "${ARGS[@]}";; *rc*|*cr*) execute_fakeroot "${ARGS[@]}";;
*rs*|*sr*) execute_fakeroot bash;; *rs*|*sr*) execute_fakeroot bash;;
s) execute_sandbox bash;; *s) execute_sandbox bash;;
*) execute_sandbox "${ARGS[@]}";; *) execute_sandbox "${ARGS[@]}";;
esac esac
} }
@ -51,17 +48,15 @@ script_init () {
} }
parse_args () { parse_args () {
ARGS=()
local sbdefined= local sbdefined=
for var in "$@"; do case $var in for var in "$@"; do case $var in
-h) SWITCH=h;; -V|--version) SWITCH="V";;
-V) SWITCH=V;; --root) SWITCH+="r";;
--root) SWITCH=r$SWITCH;; --shell) SWITCH+="s";;
--shell) SWITCH=s$SWITCH;; --dep) SWITCH+="d";;
--dep) SWITCH=d$SWITCH;; --exec) SWITCH+="rc";;
--exec) SWITCH=rc$SWITCH;; -E*) SWITCH+=$(echo $var | cut -c 3-);;
-E*) SWITCH=$(echo $var | cut -c 3-)$SWITCH;;
*) [[ $sbdefined ]] && ARGS+=("$var") && continue *) [[ $sbdefined ]] && ARGS+=("$var") && continue
INSTANCE=$var INSTANCE=$var
sbdefined=1;; sbdefined=1;;

View file

@ -20,8 +20,6 @@
source pacwrap-common source pacwrap-common
EXEC_NAME="pacwrap-man"
HEADER=$BOLD HEADER=$BOLD
HEADER_RESET=$RESET HEADER_RESET=$RESET
TAB=$(echo -e '\t') TAB=$(echo -e '\t')
@ -41,12 +39,11 @@ main () {
} }
parse_args () { parse_args () {
ARGS=()
for var in "$@"; do case $var in for var in "$@"; do case $var in
--help=*) HELP=("$(echo $var | cut -c 8-)") --help=*) HELP=("$(echo $var | cut -c 8-)")
SWITCH=h;; SWITCH="h";;
-h|--help) SWITCH=h;; -h|--help) SWITCH="h";;
-V|--version) SWITCH=V;; -V|--version) SWITCH="V";;
*) ARGS+=("$var") *) ARGS+=("$var")
esac; done esac; done
} }

View file

@ -23,14 +23,12 @@ source pacwrap-common
declare -A PROCESS declare -A PROCESS
declare -A INSTANCE declare -A INSTANCE
declare -A START declare -A START
declare -A RUNTIME_ARGS declare -A RUNTIME
declare -A PROCESS_CHILDREN declare -A PROCESS_CHILDREN
EXEC_NAME="pacwrap-ps"
KILL_PARAM="-1" KILL_PARAM="-1"
main () { main () {
export PACWRAP_UTILS=1
trap exit INT trap exit INT
local roots=() local roots=()
@ -42,17 +40,17 @@ main () {
parse_args $@ parse_args $@
init 1 init 1
[[ $SWITCH != s* ]] && log_to_file "Running '$RUNTIME_ARGS'" [[ $SWITCH != Ps* ]] && log_to_file "Running '$RUNTIME_ARGS'"
case $SWITCH in case $SWITCH in
k*) kill_instance ${roots[@]};; Pk*) kill_instance ${roots[@]};;
*) summary; local sum=$? *) summary; local sum=$?
[[ $sum == 1 ]] && log_invalid_arguments $1 [[ $sum == 1 ]] && log_invalid_arguments $1
esac esac
} }
script_init () { script_init () {
[[ $SWITCH == s* ]] && SHOW_HEADER=1 [[ $SWITCH == Ps* ]] && SHOW_HEADER=1
[[ $SWITCH == *n* ]] || [[ $SHOW_HEADER ]] && SHOW_CONTAINER=1 [[ $SWITCH == *n* ]] || [[ $SHOW_HEADER ]] && SHOW_CONTAINER=1
[[ $SWITCH == *id* ]] || [[ $SHOW_HEADER ]] && SHOW_PID=1 [[ $SWITCH == *id* ]] || [[ $SHOW_HEADER ]] && SHOW_PID=1
[[ $SWITCH == *x* ]] && SHOW_RUNTIME=1 [[ $SWITCH == *x* ]] && SHOW_RUNTIME=1
@ -80,17 +78,19 @@ script_init () {
parse_args () { parse_args () {
for var in "$@"; do case $var in for var in "$@"; do case $var in
-[0-9]*) KILL_PARAM="$var";; -[0-9]|-[0-9][0-9]) KILL_PARAM="$var";;
-V|--version) SWITCH=V;; -n|--noconfirm) SWITCH+="n";;
-P*) SWITCH=$(echo $var | cut -c 3-);; -k|--kill) SWITCH="k";;
*) ARGS+=("$var");; -V|--version) SWITCH="V";;
-P*) SWITCH+=$(echo $var | cut -c 3-);;
*) ARGS+=("$var");;
esac; done esac; done
} }
summary() { summary() {
IFS=; local ps_list=$(enumerate_ps_list ${roots[@]}) IFS=; local ps_list=$(enumerate_ps_list ${roots[@]})
[[ ! $ps_list ]] && return 1 [[ ! $ps_list ]] && return 1
echo -e $([[ $SHOW_HEADER ]] && column_headers)$ps_list | column -t -s ' ' echo -e $([[ $SHOW_HEADER ]] && column_headers)$ps_list | column -t -s $(echo -e '\t')
} }
populate_process_array() { populate_process_array() {
@ -125,12 +125,12 @@ populate_process_array() {
source $INSTANCE_RUNTIME_DIR/$pid source $INSTANCE_RUNTIME_DIR/$pid
INSTANCE[$pid]="$instance" INSTANCE[$pid]="$instance"
START[$pid]="$start" START[$pid]="$start"
RUNTIME_ARGS[$pid]="$runtime_args" RUNTIME[$pid]="$runtime_args"
else else
log_error $LOG_ERR_WARN "Runtime metadata for $pid was modified or not found." log_error $LOG_ERR_WARN "Runtime metadata for $pid was modified or not found."
INSTANCE[$pid]="$instance" INSTANCE[$pid]="$instance"
START[$pid]="$pmod" START[$pid]="$pmod"
RUNTIME_ARGS[$pid]="${cmdlist[@]}" RUNTIME[$pid]="${cmdlist[@]}"
fi fi
PROCESS[$pid]="${pid}" PROCESS[$pid]="${pid}"
@ -219,7 +219,7 @@ enumerate_ps_list() {
[[ $SHOW_CONTAINER ]] && vars+=($instance) [[ $SHOW_CONTAINER ]] && vars+=($instance)
[[ $SHOW_UPTIME ]] && vars+=($time) [[ $SHOW_UPTIME ]] && vars+=($time)
[[ $SHOW_PIDS ]] && vars+=($pids) [[ $SHOW_PIDS ]] && vars+=($pids)
[[ $SHOW_RUNTIME ]] && vars+=(${RUNTIME_ARGS[$pid]}) [[ $SHOW_RUNTIME ]] && vars+=(${RUNTIME[$pid]})
[[ ${#vars[@]} > 0 ]] && printf "\n%s\t%s\t%s\t%s\t%s" ${vars[@]} [[ ${#vars[@]} > 0 ]] && printf "\n%s\t%s\t%s\t%s\t%s" ${vars[@]}
done done
} }

View file

@ -24,13 +24,10 @@ declare -A updated
declare -A synced declare -A synced
declare -A syncreq declare -A syncreq
EXEC_NAME="pacwrap-sync" EXEC_SCRIPT="$EXEC_SCRIPT --root --exec"
EXEC_SCRIPT="pacwrap-exec --root --exec"
LINKFILES=("bin" "lib" "lib32" "share") LINKFILES=("bin" "lib" "lib32" "share")
main () { main () {
export PACWRAP_UTILS=1
trap abort INT trap abort INT
local roots=() local roots=()
@ -42,13 +39,13 @@ main () {
parse_args $@ parse_args $@
init $PACWRAP_CREATE init $PACWRAP_CREATE
[[ ! $SWITCH ]] && log_invalid_arguments [[ ! $SWITCH ]] ||
([[ ! $SYNC_UPDATE ]] && [[ ! $SYNC_UPGRADE ]] && [[ ! $SYNC_CONFIG ]]) &&
log_invalid_arguments $@
if [[ $SWITCH == *g* ]]; then if [[ $SYNC_CONFIG ]]; then
local instance=${ARGS[0]} local instance=${ARGS[0]}
[[ ! $instance ]] || [[ ! -d $INSTANCE_ROOT_DIR/$instance ]] && return
[[ ! -d $INSTANCE_ROOT_DIR/$instance ]] && return
log "$ARROW Configuring container..." log "$ARROW Configuring container..."
sync_pacman_conf && return sync_pacman_conf && return
fi fi
@ -86,11 +83,13 @@ main () {
parse_args () { parse_args () {
for var in "$@"; do case $var in for var in "$@"; do case $var in
--generate-config|-g) SWITCH=g$SWITCH;; -V|--version) SWITCH="V";;
--update|-u) SWITCH=u$SWITCH;; --generate-config|-g) SWITCH+="g";;
--no-confirm|-n) SWITCH=n$SWITCH;; --update|-u) SWITCH+="u";;
--sync|-y) SWITCH=y$SWITCH;; --noconfirm|-n) SWITCH+="n";;
-S*) SWITCH=$(echo $var | cut -c 3-);; --explicit|-e) SWITCH+="e";;
--sync|-y) SWITCH+="y";;
-S*) SWITCH+=$(echo $var | cut -c 3-);;
*) ARGS+=("$var");; *) ARGS+=("$var");;
esac; done esac; done
} }
@ -98,11 +97,13 @@ parse_args () {
script_init () { script_init () {
log_to_file "Running '$RUNTIME_ARGS'" log_to_file "Running '$RUNTIME_ARGS'"
[[ $SWITCH == g ]] && SYNC_CONFIG=1
[[ $SWITCH == *y* ]] && SYNC_UPDATE=1 [[ $SWITCH == *y* ]] && SYNC_UPDATE=1
[[ $SWITCH == *u* ]] && SYNC_UPGRADE=1 [[ $SWITCH == *u* ]] && SYNC_UPGRADE=1
[[ $SWITCH == *yy* ]] && SYNC_FOREIGN=1 [[ $SWITCH == *yy* ]] && SYNC_FOREIGN=1
[[ $SWITCH == *yyy* ]] && SYNC_OVERRIDE=1 [[ $SWITCH == *yyy* ]] && SYNC_OVERRIDE=1
[[ $SWITCH == *yyyy* ]] && SYNC_FORCE=1 [[ $SWITCH == *yyyy* ]] && SYNC_FORCE=1
[[ $SWITCH == *e* ]] && SYNC_EXPLICIT_FOREIGN=1
syncroots=(${roots[@]}) syncroots=(${roots[@]})
@ -259,7 +260,6 @@ check_root() {
update_config() { update_config() {
declare -A skip declare -A skip
local i=
local old_local_pkgs=$(return_packages) local old_local_pkgs=$(return_packages)
local package_list=() local package_list=()
local local_pkgs=$($EXEC_SCRIPT $instance pacman -Qqe) local local_pkgs=$($EXEC_SCRIPT $instance pacman -Qqe)
@ -277,7 +277,7 @@ update_config() {
for pkg in $local_pkgs; do for pkg in $local_pkgs; do
[[ ${skip[$pkg]} ]] && continue [[ ${skip[$pkg]} ]] && continue
package_list[i++]="$pkg" package_list+=("$pkg")
done done
[[ "$(echo ${package_list[@]})" != "$(echo ${old_local_pkgs[@]})" ]] && [[ "$(echo ${package_list[@]})" != "$(echo ${old_local_pkgs[@]})" ]] &&
@ -351,6 +351,7 @@ syncdb_pacman_conf() {
invoke_update() { invoke_update() {
local instance=$1 local instance=$1
local dbsyncpkgs=
[[ ${updated[$instance]} ]] && return [[ ${updated[$instance]} ]] && return
updated[$instance]=1 updated[$instance]=1
@ -381,15 +382,16 @@ invoke_update() {
[[ $(return_type) != "BASE" ]]; then [[ $(return_type) != "BASE" ]]; then
log "$ARROW Synchronizing database against foreign packages..." \ log "$ARROW Synchronizing database against foreign packages..." \
"Synchronizing $instance against foreign packages" "Synchronizing $instance against foreign packages"
[[ $SYNC_EXPLICIT_FOREIGN ]] && dbsyncpkgs=$(get_foreign_packages)
$EXEC_SCRIPT $instance pacman -Su \ $EXEC_SCRIPT $instance pacman -Su \
--logfile /tmp/pacman.log \ --logfile /tmp/pacman.log \
--dbonly --noconfirm \ --dbonly --noconfirm \
--config=/tmp/pacman.conf 2>/dev/null 1>$VERBOSE --config=/tmp/pacman.conf ${dbsyncpkgs[@]} 2>/dev/null 1>$VERBOSE
[[ $? != 0 ]] && [[ $? != 0 ]] &&
log_error $ARROW_RED "Foreign database synchronization failed." \ log_error $ARROW_RED "Foreign database synchronization failed." \
"Use pacwrap -Sv and examine stdout for details." 1 "Use pacwrap -Sv and examine stdout for details." 1
log " Database synchronization complete!" log " Database synchronization complete!"
fi fi

View file

@ -19,12 +19,11 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
source pacwrap-common source pacwrap-common
export PACWRAP_UTILS=1
EXEC_NAME="pacwrap-utils"
NUMFMT="numfmt --to=si --suffix=B --round=nearest --from-unit=1000 --format=%2f " NUMFMT="numfmt --to=si --suffix=B --round=nearest --from-unit=1000 --format=%2f "
main () { main () {
export PACWRAP_UTILS=1
trap exit INT trap exit INT
local roots=() local roots=()
@ -36,18 +35,18 @@ main () {
parse_args $@ parse_args $@
init init
[[ $SWITCH != ls* ]] && log_to_file "Running '$RUNTIME_ARGS'" [[ $SWITCH != Uls* ]] && log_to_file "Running '$RUNTIME_ARGS'"
case $SWITCH in case $SWITCH in
c*) [[ -f /usr/bin/paccache ]] && Uc*) [[ -f /usr/bin/paccache ]] &&
paccache --cachedir $INSTANCE_CACHE_DIR ${ARGS[@]};; paccache --cachedir $INSTANCE_CACHE_DIR ${ARGS[@]};;
i*) initialize_data_directory;; Ui*) initialize_data_directory;;
r*) replicate ${baserootdeps[@]} ${rootdeps[@]} ${roots[@]};; Ur*) replicate ${baserootdeps[@]} ${rootdeps[@]} ${roots[@]};;
v*) edit_file 1;; Uv*) edit_file 1;;
e*) edit_file;; Ue*) edit_file;;
ls*) summary;; Uls*) summary;;
l*) link_root;; Ul*) link_root;;
d*) [[ $SWITCH == *r* ]] && delete "root" "$INSTANCE_ROOT_DIR" Ud*) [[ $SWITCH == *r* ]] && delete "root" "$INSTANCE_ROOT_DIR"
[[ $SWITCH == *h* ]] && delete "home" "$INSTANCE_HOME_DIR";; [[ $SWITCH == *h* ]] && delete "home" "$INSTANCE_HOME_DIR";;
*) log_invalid_arguments $1 *) log_invalid_arguments $1
esac esac
@ -76,7 +75,7 @@ summary() {
parse_du parse_du
if [[ $SWITCH != *ddd* ]]; then if [[ $SWITCH != *ddd* ]]; then
list_root ${baserootdeps[@]} ${rootdeps[@]} ${roots[@]} ${links[@]} | column -t -s ' ' list_root ${baserootdeps[@]} ${rootdeps[@]} ${roots[@]} ${links[@]} | column -t -s "$(echo -e '\t')"
fi fi
if [[ $SWITCH == *d* ]]; then if [[ $SWITCH == *d* ]]; then
@ -97,9 +96,16 @@ summary() {
parse_args () { parse_args () {
for var in "$@"; do case $var in for var in "$@"; do case $var in
--list|-l) SWITCH=l$SWITCH;; --noconfirm|-n) SWITCH+="n";;
-V|--version) SWITCH=V;; --list|-ls) SWITCH+="ls";;
-U*) SWITCH=$(echo $var | cut -c 3-);; --edit|-e) SWITCH+="e";;
--view|-v) SWITCH+="v";;
--replicate|-r) SWITCH+="r";;
--delete|-d) SWITCH+="d";;
--link|-l) SWITCH+="l";;
--tar|-t) SWITCH+="t";;
-V|--version) SWITCH="V";;
-U*) SWITCH+=$(echo $var | cut -c 3-);;
--cfg-dir=*) REPLICATION_CONFIG_DIR=$(echo $var | cut -c 11-);; --cfg-dir=*) REPLICATION_CONFIG_DIR=$(echo $var | cut -c 11-);;
*) ARGS+=("$var");; *) ARGS+=("$var");;
esac; done esac; done
@ -404,10 +410,10 @@ edit_file() {
log "$ARROW_GREEN Changes written." \ log "$ARROW_GREEN Changes written." \
"Changes written to $file." "Changes written to $file."
else else
log "$BAR_GREEN No changes made" log "$ARROW No changes made"
fi fi
else else
log "$BAR_GREEN No changes made." log "$ARROW No changes made."
fi fi
rm $tmpfile rm $tmpfile