diff --git a/handlers/borg.in b/handlers/borg.in index aaf658e716cc7a7a2b56c6781aa92a00dfe90d07..fa309c79ca7d0ce889a97236142e8fa796cbde48 100644 --- a/handlers/borg.in +++ b/handlers/borg.in @@ -1,3 +1,6 @@ +#!/bin/bash +# shellcheck shell=bash +# shellcheck disable=SC2154 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- # vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # @@ -48,7 +51,7 @@ getconf port getconf directory # strip trailing / directory=${directory%/} -getconf archive {now:%Y-%m-%dT%H:%M:%S} +getconf archive "{now:%Y-%m-%dT%H:%M:%S}" getconf compression lz4 getconf encryption none getconf passphrase @@ -106,21 +109,23 @@ fi # check the connection at the source and destination [ -n "$test" ] || test=0 +# shellcheck disable=SC2235 if [ "$host" != "localhost" ] && ([ "$testconnect" = "yes" ] || [ "${test}" -eq 1 ]); then - debug "ssh $sshoptions -o PasswordAuthentication=no ${host}${port:+ -p ${port}} -l $user 'echo -n 1'" - local ret=`ssh $sshoptions -o PasswordAuthentication=no ${host}${port:+ -p ${port}} -l $user 'echo -n 1'` + teststr="ssh $sshoptions -o PasswordAuthentication=no ${host}${port:+ -p ${port}} -l $user 'echo -n 1'" + debug "$teststr" + ret=$(su -c "$teststr") if [ "$ret" = 1 ]; then debug "Connected to $host as $user successfully" else teststr="borg list $options --show-rc -v $execstr_repository" debug "$teststr" - output=`su -c "$teststr" 2>&1` + output=$(su -c "$teststr" 2>&1) if echo "$output" | grep "terminating with success status" \ || echo "$output" | grep "^\S\+ is not a valid repository." \ || echo "$output" | grep "^Repository \S\+ does not exist."; then debug "Connected to $host as $user successfully (forced command)" else - error $output + error "$output" fatal "Can't connect to $host as $user." fi fi @@ -132,13 +137,13 @@ if [ "$init" == "yes" ]; then initstr="borg init $options --encryption=$encryption $execstr_repository" debug "executing borg init" debug "$initstr" - if [ $test = 0 ]; then - output="`su -c "$initstr" 2>&1`" + if [ "$test" = 0 ]; then + output="$(su -c "$initstr" 2>&1)" if [ $? = 2 ]; then - debug $output + debug "$output" info "Repository was already initialized" else - warning $output + warning "$output" warning "Repository has been initialized" fi fi @@ -168,11 +173,11 @@ IFS=$SAVEIFS set +o noglob -if [ ! -z $bwlimit ]; then +if [ -n "$bwlimit" ]; then execstr="${execstr} --remote-ratelimit=${bwlimit}" fi -if [ ! -z "$create_options" ]; then +if [ -n "$create_options" ]; then execstr="${execstr} ${create_options}" fi @@ -235,14 +240,14 @@ if [ "$prune" == "yes" ]; then prunestr="borg prune $options $prune_options $execstr_repository" debug "executing borg prune" debug "$prunestr" - if [ $test = 0 ]; then - output="`su -c "$prunestr" 2>&1`" + if [ "$test" = 0 ]; then + output="$(su -c "$prunestr" 2>&1)" ret=$? if [ $ret = 0 ]; then - debug $output + debug "$output" info "Removing old backups succeeded." elif [ $ret = 1 ]; then - warning $output + warning "$output" warning "Removing old backups finished with warnings." else error $output