modernize multiple seqs and fix deprecated use of endCheckEmpty

This commit is contained in:
2022-12-12 16:42:25 +01:00
parent dbb8cac539
commit 7391de1ddd
18 changed files with 199 additions and 232 deletions

View File

@@ -1,42 +1,36 @@
#!/bin/bash
toolName=backup
toolBin=rsync
readonly toolName=backup
readonly toolBin=rsync
# Get script working directory
# (when called from a different directory)
WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
APTOPT=
CONFIG=0
CONFIG_FILE_NAME="${toolName}.cfg"
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
sq_aptOpt=
sq_config=0
seq_config() {
initSeqConfig -t "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
if [ $? -eq 0 ] ; then
CONFIG=1
if initSeqConfig -t "${seq_configName:?}" "${seq_configTemplate:?}" ; then
sq_config=1
else
error -e "Check output for errors"
# End if no configuration file exists
dry || return -1
dry || return 1
fi
quiet && APTOPT="-y"
interactive || sq_aptOpt="-y"
return 0
}
step_1_info() {
echo "Backup root"
echoinfo "Essential excludes are provided in the configuration template."
echoinfo "($CONFIG_FILE_TEMPLATE)"
echoinfo "(${seq_configTemplate})"
}
step_1_options() { echo "[ADDITIONAL_EXCLUDES...]"; }
step_1_alias() { echo "buroot"; }
step_1() {
local buTarget="/backup"
if [ $CONFIG -eq 0 ] ; then
if (( ! sq_config )) ; then
error -e "Cannot backup root without properly configured excludes"
error -e " (expected config: $seq_configRoot/$CONFIG_FILE_NAME)"
error -e " (expected config: ${seq_configFile})"
else
buTarget="$BACKUP_TARGET"
fi
@@ -49,20 +43,19 @@ step_1() {
step_3_info() {
# Backup single directory recursively
local opt="[OPTION]"
local dir="<DIRECTORY>"
local tar="<TARGET>"
local exc="[EXCLUDES...]"
local opt=
local dir=
local tar=
local exc=
shift
if [ "${1:-}" == "-t" ] ; then
opt=" -t "
tar=
shift
fi
if [ -n "${1:-}" ] ; then
dir="$1"
shift
if [ -n $tar ] && [ -n "$1" ] ; then
if [ -z $opt ] && [ -n "$1" ] ; then
tar="$1"
shift
else
@@ -75,12 +68,13 @@ step_3_info() {
fi
fi
echo "Backup $opt $dir $tar $exc"
echoinfo " -t : Using configuration value as TARGET"
echoinfo " <DIRECTORY> [EXCLUDES...]"
echoinfo " -t : Using configuration value as TARGET"
echoinfo " <DIRECTORY> [EXCLUDES...]"
echoinfo "EXCLUDES path notation starts within $dir"
echoinfo "e.g. to exclude $dir/a:"
echoinfo " e.g. to exclude $dir/a:"
echoinfo " $0 budir $dir $tar /a"
}
step_3_options() { echo "[OPTION] <DIRECTORY> [TARGET] [EXCLUDES...]"; }
step_3_alias() { echo "budir"; }
step_3() {
local configTarget=0
@@ -119,7 +113,7 @@ step_3() {
buLog="backup_${buLog}"
shift
if [ $configTarget -ne 0 ] && [ $CONFIG -ne 0 ] ; then
if [ $configTarget -ne 0 ] && (( sq_config )) ; then
# Taking target from config
buTarget=$(echo "$BACKUP_TARGET" | sed 's:/*$::')
else
@@ -176,7 +170,7 @@ step_100_info() { echo "Install $toolBin"; }
step_100_alias() { echo "install"; }
step_100() {
exe apt update
exe apt install $toolBin $APTOPT
exe apt install $toolBin ${sq_aptOpt}
}
checkInstalled() {
@@ -187,6 +181,7 @@ checkInstalled() {
toolBin="$(command -v $toolBin)"
}
# shellcheck disable=SC2034 # Appears unused
readonly sqr_minVersion=16
# shellcheck disable=SC1091 # Don't follow this source
. /usr/local/bin/sequencer.sh