add sync module

fix remote spaces in helpers
fix few errors in install library
master
David Kebler 2024-02-24 08:01:41 -08:00
parent e36e658a69
commit 82af909b7a
3 changed files with 61 additions and 6 deletions

View File

@ -112,8 +112,8 @@ remove_end_spaces () {
del=${2:-\'}
# echo delimiter: $del
# sed -e 's/[[:space:]]\{1,\}$del/$del/' <<< "$1"
res=$(sed -e 's/^$del[[:space:]]*/$del/' <<< "$1")
sed -e 's/[[:space:]]*${del}$/$del/' <<< "$res"
res=$(sed -e 's/^'$del'[[:space:]]*/'$del'/' <<< "$1")
sed -e 's/[[:space:]]*'${del}'$/'$del'/' <<< "$res"
}
# pass any sed ' ' string and comments lines will be ignored

View File

@ -74,6 +74,7 @@ install_shell_host () {
echo note: use $BASH_SHELL_HOSTNAME/load directory to load modules and other stuff from at prompt.
fi
fi
bash $BASH_SHELL_HOST/distro/distro.inst
}
install_shell_network () {
@ -92,7 +93,7 @@ install_shell_network () {
chown -R ${1:-$USER}:${1:-$USER} $BASH_SHELL_NETWORK
chmod -R +r $BASH_SHELL_NETWORK
fi
fi
fi
}
update_shell_base () {
@ -105,11 +106,13 @@ update_shell_base () {
}
update_shell_host () {
cd $BASH_SHELL_NETWORK || { echo not directory $BASH_SHELL_NETWORK; return 2; }
git pull ${UCI_GIT_REMOTE:-origin} master
[[ ! -d $BASH_SHELL_HOST/modules ]] && echo uci shell host repo not installed, run install_shell_host first && return 1
cd $BASH_SHELL_HOST || { echo not directory $BASH_SHELL_HOST; return 2; }
git pull ${BASH_SHELL_GIT_REMOTE:-origin} master
}
update_shell_network () {
[[ ! -d $BASH_SHELL_NETWORK/modules ]] && echo uci shell host repo not installed, run install_shell_host first && return 1
cd $BASH_SHELL_NETWORK || { echo not directory $BASH_SHELL_NETWORK; return 2; }
git pull ${UCI_GIT_REMOTE:-origin} master
git pull ${BASH_SHELL_GIT_REMOTE:-origin} master
}

52
modules/utility/sync.lib Normal file
View File

@ -0,0 +1,52 @@
#!/bin/bash
mirror_rootfs () {
[[ ! $(command -v rsync) ]] && { echo rsync must be installed to use this function; return 5; }
dr="--dry-run"
dest=$(realpath -s $1)
rootfs=$(realpath -s "${2:-/}")
[ ! -d "$dest" ] && echo destination $dest is not a directory && return 3
[ ! -d "$rootfs/etc" ] && echo not root filesystem at $rootfs && return 3
echo making mirror of root filesystem to
rfse=rootfs_excludes
if sudo rsync -axHAWXS $dr --numeric-ids --delete --delete-excluded --force --exclude-from="$(rootfs_excludles)" / /mnt/adrive/nas/@rootfs; then
echo making mirror of boot partition to /mnt/adrive/nas/@rootfs
if sudo rsync -axHAWXS $dr --numeric-ids --force --delete /boot/ /mnt/adrive/nas/@boot; then
echo doit
else
echo unable to sync a copy of /boot, aborted backup
fi
else
echo unable to sync a copy of root file system, backkup failed
fi
}
rootfs_excludes () {
local list; local delete
[[ $1 == "-l" ]] && list=true && shift
[[ $1 == "-r" ]] && delete=true && shift
[[ "$1" == "-"* ]] && >&2 echo bad option, aborting && return 1
rfse=${1:-/tmp/rootfs_excludes.lst}
[[ $delete ]] && rm $rfse
cat <<EOF > $rfse
.[Tt]rash*
tmp/
cache/
log/
log[s]/
lost+found
EOF
if [[ $list ]];then
cat $rfse; rm -f $rfse
else
echo $rfse
fi
}
mountpoints () {
cat /proc/mounts | cut -d ' ' -f2 | sort
}