From 82af909b7a799f9a4c41d9f5291df84100aba2cd Mon Sep 17 00:00:00 2001 From: David Kebler Date: Sat, 24 Feb 2024 08:01:41 -0800 Subject: [PATCH] add sync module fix remote spaces in helpers fix few errors in install library --- modules/scripting/helpers.lib | 4 +-- modules/uci-shell-install.lib | 11 +++++--- modules/utility/sync.lib | 52 +++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 modules/utility/sync.lib diff --git a/modules/scripting/helpers.lib b/modules/scripting/helpers.lib index a3e910f..7464494 100644 --- a/modules/scripting/helpers.lib +++ b/modules/scripting/helpers.lib @@ -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 diff --git a/modules/uci-shell-install.lib b/modules/uci-shell-install.lib index d491791..4230482 100644 --- a/modules/uci-shell-install.lib +++ b/modules/uci-shell-install.lib @@ -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 } diff --git a/modules/utility/sync.lib b/modules/utility/sync.lib new file mode 100644 index 0000000..b3f13ad --- /dev/null +++ b/modules/utility/sync.lib @@ -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 < $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 +} \ No newline at end of file