fix copy and bindfs

master
David Kebler 2024-12-07 13:42:53 -08:00
parent c6c8f9876b
commit fd8a9a7c98
4 changed files with 71 additions and 36 deletions

View File

@ -2,6 +2,7 @@
export BTRFS_BIN=$(which btrfs) export BTRFS_BIN=$(which btrfs)
module_load confirm module_load confirm
module_load helpers module_load helpers
module_load path
# NOTE: set this for sudo # NOTE: set this for sudo
# ALL ALL = (root) NOPASSWD:/bin/btrfs # ALL ALL = (root) NOPASSWD:/bin/btrfs
@ -182,7 +183,7 @@ snapshot_send() {
echo "[[ "$tsnap" ]] && sudo $BTRFS_BIN sub del $tsnap" echo "[[ "$tsnap" ]] && sudo $BTRFS_BIN sub del $tsnap"
else else
sudo $BTRFS_BIN send $([[ $tsnap ]] && echo $tsnap || echo $src) | btrfs receive $dest sudo $BTRFS_BIN send $([[ $tsnap ]] && echo $tsnap || echo $src) | btrfs receive $dest
mv $dest/$snap $dest/$name$ext sudo mv $dest/$snap $dest/$name$ext
[[ "$tsnap" ]] && sudo $BTRFS_BIN sub del $tsnap [[ "$tsnap" ]] && sudo $BTRFS_BIN sub del $tsnap
echo transfer is complete echo transfer is complete
ls -la $dest ls -la $dest

View File

@ -18,8 +18,10 @@ if [ -v PS1 ]; then
alias bfsum="dir_bind_unmount" alias bfsum="dir_bind_unmount"
alias bfse="bfs_vscode" alias bfse="bfs_vscode"
sudo mkdir $BFS_MOUNT_DIR 2> /dev/null if [[ ! -d $BFS_MOUNT_DIR ]]; then
sudo chown $USER:$USER $BFS_MOUNT_DIR sudo mkdir $BFS_MOUNT_DIR 2> /dev/null
sudo chown $USER:$USER $BFS_MOUNT_DIR
fi
fi fi
mounted () { mounted () {

View File

@ -1,6 +1,5 @@
*[Tt]rash/ *[Tt]rash/
tmp/* tmp/*
node_modules/*
*[Cc]ache/* *[Cc]ache/*
*[lL]ogs/* *[lL]ogs/*
[Ll]og/* [Ll]og/*

View File

@ -21,7 +21,7 @@ copy () {
cat <<EOF cat <<EOF
usage: usage:
rsync <script options> source destination <rsync options> -- <ssh options> rsync <script options> source destination <rsync options> -- <ssh script options> --- <ssh options>
Available Script Options Available Script Options
-r, run the command by this script uses --dry-run. When ready pass this flag. -r, run the command by this script uses --dry-run. When ready pass this flag.
@ -62,7 +62,7 @@ EOF
case "$OPTION" in case "$OPTION" in
# TODO add D and S for destion and source path # TODO add D and S for destion and source path
s) s)
usesudo=sudo usesudo="sudo -E"
;; ;;
c) c)
# clean out unneeded folders like cache, trash, log # clean out unneeded folders like cache, trash, log
@ -91,7 +91,7 @@ EOF
args+=("--exclude-from=$COPY_MODULE_PATH/cache-trash-log.exc") args+=("--exclude-from=$COPY_MODULE_PATH/cache-trash-log.exc")
Mirror=true Mirror=true
mirror=true mirror=true
usesudo=sudo usesudo="sudo -E"
;; ;;
p) p)
args+=("--mkpath") args+=("--mkpath")
@ -155,9 +155,50 @@ EOF
DPATH=$DEST DPATH=$DEST
fi fi
[[ $DHOST && $SHOST ]] && echo this script can not process remote host to remote host transfer && return 5 [[ $DHOST && $SHOST ]] && echo this script can not process remote host to remote host transfer && return 5
[[ ! $SHOST ]] && SPATH=$(realpath $SPATH)
[[ ! $DHOST ]] && DPATH=$(realpath $DPATH)
# additional argument processing
debug $( ( IFS=$','; echo all remaining arguments: "$*" ) )
value="++"
sci=$(( $(printf "%s\n" "$@" | sed -n '/^'$value'$/{=;q}') - 1 ))
value="--"
si=$(( $(printf "%s\n" "$@" | sed -n '/^'$value'$/{=;q}') - 1 ))
debug $sci $si
local sca=()
local sa=()
if [[ $sci -ge 0 ]]; then
args+=("${@:1:$sci}")
if [[ $si -ge 0 ]]; then
debug both ssh args
sca=("${@:$sci+2:$#-$si+1}")
sa=("${@:$si+1:$#}")
else
debug only script args
sca=("${@:$sci+2:$#}")
fi
else
if [[ $si -ge 0 ]]; then
debug only ssh run args
args+=("${@:1:$si}")
sa=("${@:$si+1:$#}")
else
debug in args only
args+=("${@:1:$#+1}")
fi
fi
debug args: up before ssh: ${args[*]}
# is source or destination is remote, create -e ssh sync option # is source or destination is remote, create -e ssh sync option
if [[ $DHOST || $SHOST ]]; then if [[ $DHOST || $SHOST ]]; then
# echo remote copy, loading ssh debug remote copy, loading ssh
debug ssh script args: ${sca[*]}
debug ssh run args: ${sa[*]}
debug remote host: ${DHOST:-$SHOST}
if ! module_load ssh &>/dev/null; then if ! module_load ssh &>/dev/null; then
echo unable to load ssh module echo unable to load ssh module
echo likely the uci network repo has not been installed echo likely the uci network repo has not been installed
@ -169,34 +210,23 @@ EOF
>&2 echo fatal: the host ${DHOST:-$SHOST} is not valid, aborting remote copy >&2 echo fatal: the host ${DHOST:-$SHOST} is not valid, aborting remote copy
return 1 return 1
fi fi
# else
# echo local rsync copy local sshcmd
# sshcmd="ssh -l "${ssshargs[*]}" "${sshargs[*]}""
# echo $sshcmd
# if ! sshcmd=$(ssh -l "${ssshargs[*]}" ${DHOST:-$SHOST}); then
# double quotes on array expansion not good
if ! sshcmd=$(ssh -l ${sca[*]} ${DHOST:-$SHOST} ${sa[*]}); then
echo failed to build ssh command for rsync, aborting
debug sshcmd: ${sshcmd}
return 5
fi
debug sshcmd: ${sshcmd}
args+=("-e '$sshcmd'")
debug args: inclcuding ssh: ${args[*]}
fi fi
[[ ! $SHOST ]] && SPATH=$(realpath $SPATH) # assemble remaining arguments from options
[[ ! $DHOST ]] && DPATH=$(realpath $DPATH)
# BASH_DEBUG="stdout"
debug $( ( IFS=$','; echo all remaining arguments: "$*" ) )
for ((d=1; d<$#+1; ++d)); do
echo in loop $d, ${!d}
[[ ${!d} == "--" ]] && sargs=true && break
done
if [[ $sargs ]]; then # if there are extra ssh arguments
sshargs=("${@:$d+1:$#}")
debug $( ( IFS=$','; echo "ssh arguments: ${sshargs[*]}" ) )
[[ $DHOST || $SHOST ]] && args+=( "$(remove_end_spaces "-e '$(ssh -l "${sshargs[*]}")'")")
fi
# remove --
# args=+("${@:1:$d-1}")
# debug $( ( IFS=$','; echo remaining arguments to parse: "$*" ) )
# else
# echo again: ${args[*]}
# args=("${@:1}")
# assemble arguments from options
[[ ! $exec ]] && args+=(--dry-run -v) [[ ! $exec ]] && args+=(--dry-run -v)
[[ ! $quiet ]] && args+=(--info=progress2 $verbose) [[ ! $quiet ]] && args+=(--info=progress2 $verbose)
[[ $mirror ]] && args+=(-a --numeric-ids --delete --force) [[ $mirror ]] && args+=(-a --numeric-ids --delete --force)
@ -237,6 +267,9 @@ EOF
# alias mirror="copy -i -a -M" # alias mirror="copy -i -a -M"
# custom copy commands as functions
mirror_shell () { mirror_shell () {
local dir; local dest local dir; local dest
@ -251,7 +284,7 @@ EOF
} }
rpush () { rpush () {
local dir; local dest local dir; local dest
#TODO don't overwrite hostname #TODO don't overwrite hostname