From 8faaf0922a2e6bf0893cdf2d551a7c63b9bccd12 Mon Sep 17 00:00:00 2001 From: Jonas Forsberg Date: Tue, 13 Oct 2020 09:13:20 +0200 Subject: [PATCH] shellchecking --- bin/borg.sh | 17 +++++++++++++++-- bin/genwgQR | 8 ++++---- bin/initDesktop | 4 ++-- bin/setupWireguard | 8 ++++---- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/bin/borg.sh b/bin/borg.sh index 2c177f8..b52a62f 100755 --- a/bin/borg.sh +++ b/bin/borg.sh @@ -2,13 +2,13 @@ [[ ! -f "$HOME/.borgbackup.env" ]] && printf "\$HOME/.borgbackup.env doesn't exist!\n" && exit 1 -if [[ "$(stat -c %A $HOME/.borgbackup.env)" != "-rw-------" ]]; then +if [[ "$(stat -c "$HOME/.borgbackup.env")" != "-rw-------" ]]; then printf "WARNING!!!! \$HOME/.borgbackup.env has the wrong permissions!\n" printf "\nrun : chmod 0600 \$HOME/.borgbackup.env\n" exit 1 fi -source "$HOME/.borgbackup.env" +source "${HOME}/.borgbackup.env" # some helpers and error handling: @@ -78,3 +78,16 @@ borg prune \ --keep-monthly 6 \ prune_exit=$? + +# use highest exit code as global exit code +global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) + +if [ ${global_exit} -eq 0 ]; then + info "Backup and Prune finished successfully" +elif [ ${global_exit} -eq 1 ]; then + info "Backup and/or Prune finished with warnings" +else + info "Backup and/or Prune finished with errors" +fi + +exit ${global_exit} diff --git a/bin/genwgQR b/bin/genwgQR index dd0c0ce..a235442 100755 --- a/bin/genwgQR +++ b/bin/genwgQR @@ -4,15 +4,15 @@ keepassdb="$HOME/Nextcloud/passwords/Passwords.kdbx" type qrencode >/dev/null 2>&1 || { printf "qrencode is not installed\n" >&2; exit 1; } type keepassxc-cli >/dev/null 2>&1 || { printf "KeepassXC is not installed\n" >&2; exit 1; } -printf "Enter password for $keepassdb: " -read -s password +printf "Enter password for %s: " "$keepassdb" +read -r -s password printf "\n" printf "Enter device name you want to generate the code for: " -read device +read -r device printf "Enter the tunnel name: " -read tunnel +read -r tunnel echo "$password" | keepassxc-cli show -q --attributes Notes "$keepassdb" /Wireguard/"$device"/"$tunnel" | qrencode -t ansiutf8 diff --git a/bin/initDesktop b/bin/initDesktop index e76eb1e..def1a6c 100755 --- a/bin/initDesktop +++ b/bin/initDesktop @@ -134,7 +134,7 @@ function firefox_config(){ set +e pkill -f firefox set -e - $HOME/bin/install_firefox_addon + "$HOME"/bin/install_firefox_addon } function chrome_config(){ @@ -231,7 +231,7 @@ while :; do break ;; -?*) - printf "'$1' is not a valid option\n" >&2 + printf "'%s' is not a valid option\n" "$1" >&2 exit 1 ;; *) #Break out of case, no more options diff --git a/bin/setupWireguard b/bin/setupWireguard index b540916..dae11bb 100755 --- a/bin/setupWireguard +++ b/bin/setupWireguard @@ -5,14 +5,14 @@ type wg >/dev/null 2>&1 || { printf "wireguard is not installed\n" >&2; exit 1; type keepassxc-cli >/dev/null 2>&1 || { printf "KeepassXC is not installed\n" >&2; exit 1; } -printf "Enter password for $keepassdb: " -read -s password +printf "Enter password for %s: " "$keepassdb": +read -s -r password printf "\n" -networks=$(echo "$password" | keepassxc-cli ls "$keepassdb" /Wireguard/$HOSTNAME) +networks=$(echo "$password" | keepassxc-cli ls "$keepassdb" /Wireguard/"$HOSTNAME") umask 077 for network in $networks;do echo "configuring /etc/wireguard/${network}.conf" - echo "$password" | keepassxc-cli show -q --attributes Notes "$keepassdb" /Wireguard/$HOSTNAME/$network | sudo tee /etc/wireguard/${network}.conf > /dev/null + echo "$password" | keepassxc-cli show -q --attributes Notes "$keepassdb" /Wireguard/"$HOSTNAME"/"$network" | sudo tee /etc/wireguard/"${network}".conf > /dev/null done unset password