From c75ec7ddebdd85bdad5d7e33fc4c62edc9953bc8 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Sun, 28 Mar 2021 23:39:46 +0200 Subject: [PATCH] Check and install rsync if missing --- seqs/backup.sh | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/seqs/backup.sh b/seqs/backup.sh index 149d968..f3e3c21 100755 --- a/seqs/backup.sh +++ b/seqs/backup.sh @@ -1,10 +1,12 @@ #!/bin/bash toolName=backup +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" @@ -15,7 +17,12 @@ step_config() { CONFIG=1 else echoerr " [E] Check output for errors" + # End if no configuration file exists + [ $DRY -eq 0 ] && return -1 fi + + [ $QUIET -ne 0 ] && APTOPT="-y" + return 0 } step_1_info() { @@ -145,15 +152,31 @@ step_3() { echoerr " [E] Backup target (${buTarget}) is not writable" exit 1 fi - + + checkInstalled exep "mv -f ${buTarget}/${buLog}0.log /tmp/${buLog}1.log 2>/dev/null" - exep "rsync -avxHAX --delete --info=stats2 ${buExcludes[*]} ${tmpSource} ${tmpTarget} > /tmp/${buLog}0.log" + exep "$toolBin -avxHAX --delete --info=stats2 ${buExcludes[*]} ${tmpSource} ${tmpTarget} > /tmp/${buLog}0.log" exe mv -f /tmp/${buLog}*.log ${buTarget} exe sync exep "mount -o ro,remount '${buTarget}' >>/dev/null 2>&1" } -VERSION_SEQREV=10 +step_100_info() { echo "Install $toolBin"; } +step_100_alias() { ALIAS="install"; } +step_100() { + exe apt update + exe apt install $toolBin $APTOPT +} + +checkInstalled() { + command -v $toolBin >>/dev/null + if [ $? -ne 0 ] ; then + step install + fi + toolBin="$(command -v $toolBin)" +} + +VERSION_SEQREV=12 . /usr/local/bin/sequencer.sh