aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2019-08-06 22:42:31 -0300
committerSilvio Rhatto <rhatto@riseup.net>2019-08-06 22:42:31 -0300
commitb16f0b0345a898657dcec36cba3ca12df82ba55d (patch)
treedccf0c817f9474bbd627fbccf25f70b89b29e06c
parent4a09769d421994f5351851bff18c74301c8a528f (diff)
downloadborger-b16f0b0345a898657dcec36cba3ca12df82ba55d.tar.gz
borger-b16f0b0345a898657dcec36cba3ca12df82ba55d.tar.bz2
Include BORG_PASSPHRASE config for each destination in an array
-rwxr-xr-xborger39
1 files changed, 31 insertions, 8 deletions
diff --git a/borger b/borger
index 3448101..a4d2f73 100755
--- a/borger
+++ b/borger
@@ -29,6 +29,7 @@ DESTINATION="$1"
OPTION="$2"
BASE_CONFIG="$HOME/.config/borger"
CONFIG="$BASE_CONFIG/$DESTINATION"
+INTERVAL="1h"
# Print info
function info {
@@ -90,7 +91,6 @@ function borger_config {
KEEPMONTHLY="6"
ENCRYPTION="keyfile"
PLACEHOLDER="{user}"
- INTERVAL="1h"
source $CONFIG
@@ -205,8 +205,7 @@ function borger_set_lockfile {
if ( set -o noclobber; echo "$$" > "$LOCKFILE" ) &> /dev/null; then
trap 'borger_unset_lockfile' INT TERM EXIT
else
- echo "Could not create lockfile $LOCKFILE, exiting"
- exit 1
+ fatal "Could not create lockfile $LOCKFILE, exiting"
fi
fi
}
@@ -226,8 +225,7 @@ function borger_check_lockfile {
pid="`cat $LOCKFILE`"
process="`ps --no-headers -o comm $pid`"
if [ "$?" == "0" ] && [ "`ps --no-headers -o comm $$`" == "$process" ]; then
- echo "Another program is running for $LOCKFILE, skipping run"
- exit
+ fatal "Another program is running for $LOCKFILE, skipping run"
else
echo "Found old lockfile $LOCKFILE, removing it"
borger_unset_lockfile
@@ -265,6 +263,7 @@ function borger_single {
export BORG_PASSCOMMAND=""
fi
+ # Run as a subprocess so we do not exit on any fatal error
$FULLNAME $DESTINATION
}
@@ -272,10 +271,32 @@ function borger_single {
function borger_multiple {
info "Multiple destination \"$DESTINATION\" found. Processing each subconfig..."
+ # Needs bash 4
+ # https://stackoverflow.com/questions/1494178/how-to-define-hash-tables-in-bash
+ if echo $BASH_VERSION | grep -q "^3"; then
+ fatal "$BASENAME requires bash 4 or newer."
+ fi
+
+ # Passphrase array
+ declare -A BORG_PASSPHRASES
+ export BORG_PASSCOMMAND=""
+
+ # Evaluate each config
+ for config in `ls $CONFIG`; do
+ # Include BORG_PASSPHRASE config for each destination in an array
+ if grep -q "BORG_PASSCOMMAND" $CONFIG/$config; then
+ COMMAND="`grep BORG_PASSCOMMAND $CONFIG/$config | cut -d = -f 2 | sed -e "s/^'//" -e "s/'$//" -e 's/^"//' -e 's/"$//'`"
+ #BORG_PASSPHRASES[$config]="BORG_PASSPHRASE=`$COMMAND`"
+ BORG_PASSPHRASES[$config]="`$COMMAND`"
+ else
+ BORG_PASSPHRASES[$config]=""
+ fi
+ done
+
# Serial approach
- # FIXME: export BORG_PASSPHRASE config for each destination using an array
for config in `ls $CONFIG`; do
info "Calling borger for $DESTINATION/$config..."
+ export BORG_PASSPHRASE="${BORG_PASSPHRASES[$config]}"
$FULLNAME $DESTINATION/$config 2>&1 | sed -e "s/^\[borger\]/[borger] [$config]/" -e "s/^\([^\[]\)/[borger] [$config] \1/"
done
@@ -284,7 +305,10 @@ function borger_multiple {
## and call borger for each config in parallel
#for config in `ls $CONFIG`; do
# info "Calling borger for $DESTINATION/$config..."
- # ( $FULLNAME $DESTINATION/$config $MULTIPLE_OPTION 2>&1 | sed -e "s/^\[borger\]/[borger] [$config]/" -e "s/^\([^\[]\)/[borger] [$config] \1/" ) &
+ # (
+ # export BORG_PASSPHRASE="${BORG_PASSPHRASES[$config]}"
+ # $FULLNAME $DESTINATION/$config $MULTIPLE_OPTION 2>&1 | sed -e "s/^\[borger\]/[borger] [$config]/" -e "s/^\([^\[]\)/[borger] [$config] \1/"
+ # ) &
#done
## Since we dispatched everything to subprocesses,
@@ -316,7 +340,6 @@ function borger_continuous {
# Run until interruption
while true; do
- # Run as a subprocess so we do not exit on any fatal error
if [ "$MULTIPLE" == "yes" ]; then
borger_multiple
else