ebackup - modernize implementation

This commit is contained in:
2022-11-29 21:09:48 +01:00
parent 22d6de9fb0
commit 5279eb7032

View File

@@ -1,28 +1,27 @@
#!/bin/bash #!/bin/bash
toolName=duplicity readonly toolName=duplicity
readonly toolCronDir="/etc/cron.d"
readonly toolPrefix="encBackup_"
toolBin= toolBin=
toolPpa="ppa:duplicity-team/duplicity-release-git"
toolCronDir="/etc/cron.d"
toolPrefix="encBackup_"
toolSyslogTag= toolSyslogTag=
# Get script working directory sq_aptOpt=
# (when called from a different directory) sq_config=0
WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd )"
CONFIG=0
SCRIPT_NAME=$(basename -- $0)
SCRIPT_NAME=${SCRIPT_NAME%%.*}
CONFIG_FILE_TEMPLATE="$WDIR/${SCRIPT_NAME}.cfg.example"
seq_config() { seq_config() {
initSeqConfig -p "$SCRIPT_NAME" "$CONFIG_FILE_TEMPLATE" if initSeqConfig -p "${seq_fileName:?}" "${seq_configTemplate:?}" ; then
if [ $? -eq 0 ] ; then sq_config=1
CONFIG=1
else else
dry || return 1 dry || return 1
fi fi
toolSyslogTag="${SCRIPT_NAME}-$seq_profileName"
## Apt cmdline option to suppress user interaction
interactive || sq_aptOpt="-y"
toolSyslogTag="${seq_fileName:?}-$seq_profileName"
return 0
} }
step_1_info() { step_1_info() {
@@ -213,7 +212,9 @@ step_22() {
fi fi
checkInstalled checkInstalled
setPassphrase
exe $toolBin list-current-files "$ebuTarget" exe $toolBin list-current-files "$ebuTarget"
unsetPassphrase
} }
@@ -235,7 +236,7 @@ step_70() {
local cronRemove=0 local cronRemove=0
local cronScript="$toolCronDir/${toolPrefix}$seq_profileName" local cronScript="$toolCronDir/${toolPrefix}$seq_profileName"
local cronLog='>/dev/null' local cronLog='>/dev/null'
local cronEntry="$EBU_CRONTIME $(whoami) $WDIR/$(basename -- $0) -qq -p $seq_profileName" local cronEntry="$EBU_CRONTIME $(whoami) ${seq_self:?} -qq -p $seq_profileName"
for arg in "$@" ; do for arg in "$@" ; do
case "$1" in case "$1" in
@@ -273,25 +274,20 @@ step_72_info() { echo "Update all profile cron files"; }
step_72_alias() { echo "reload"; } step_72_alias() { echo "reload"; }
step_72() { step_72() {
for seq in "$seq_configRoot/"* ; do for seq in "$seq_configRoot/"* ; do
seq=$(basename ${seq}) seq="$(basename -- "${seq}")"
$WDIR/$(basename -- $0) $sqr_args -qq -p ${seq%%.*} cron exe "${seq_self}" -qq -p ${seq%%.*} cron
done done
} }
step_100_info() { echo "Install $toolName $toolPpa"; } step_100_info() { echo "Install $toolName"; }
step_100_alias() { echo "install"; } step_100_alias() { echo "install"; }
step_100() { step_100() {
local aptOpt= exe apt update
if quiet ; then exe apt install $toolName ${sq_aptOpt}
aptOpt="-y"
fi
exe add-apt-repository $toolPpa $aptOpt
exe apt install $toolName $aptOpt
} }
setPassphrase() { setPassphrase() {
if [ -z "${PASSPHRASE:-}" ] && [ ! -z "${EBU_PASSPHRASE:-}" ] ; then if [ -z "${PASSPHRASE:-}" ] && [ -n "${EBU_PASSPHRASE:-}" ] ; then
export PASSPHRASE="$EBU_PASSPHRASE" export PASSPHRASE="$EBU_PASSPHRASE"
fi fi
} }
@@ -321,13 +317,14 @@ syslogEntry() {
checkInstalled() { checkInstalled() {
if [ -z "$toolBin" ] ; then if [ -z "$toolBin" ] ; then
command -v $toolName >>/dev/null if ! command -v $toolName >>/dev/null ; then
if [ $? -ne 0 ] ; then
step install step install
fi fi
toolBin="${EBU_PRECMD:-} $(escpath "$(command -v $toolName)")" toolBin="${EBU_PRECMD:-} $(escpath "$(command -v $toolName)")"
fi fi
} }
# shellcheck disable=SC2034 # Appears unused
readonly sqr_minVersion=16 readonly sqr_minVersion=16
# shellcheck disable=SC1091 # Don't follow this source
. /usr/local/bin/sequencer.sh . /usr/local/bin/sequencer.sh