Make one env optional and warn about optional missing envs (#110)

* Make one env optional and warn about optional missing envs

* Restrict visibility of var

* Fix warning

* Dont print empty warning list
This commit is contained in:
nettnikl
2023-05-21 10:31:11 +02:00
committed by GitHub
parent 085d722747
commit e7fe75ca47
2 changed files with 48 additions and 8 deletions
Regular → Executable
+23 -4
View File
@@ -25,10 +25,29 @@ assert_envvars() {
fi
done
}
assert_envvars \
B2_ACCOUNT_ID B2_ACCOUNT_KEY B2_CONNECTIONS \
warn_on_missing_envvars() {
local unset_envs=()
local varnames=("$@")
for varname in "${varnames[@]}"; do
if [ -z "${!varname}" ]; then
unset_envs=("${unset_envs[@]}" "$varname")
fi
done
if [ ${#unset_envs[@]} -gt 0 ]; then
printf "The following env variables are recommended, but have not been set. This script may not work as expected: %s\n" "${unset_envs[*]}" >&2
fi
}
assert_envvars\
RESTIC_PASSWORD_FILE RESTIC_REPOSITORY RESTIC_VERBOSITY_LEVEL
warn_on_missing_envvars \
B2_ACCOUNT_ID B2_ACCOUNT_KEY B2_CONNECTIONS
B2_ARG=
[ -z "${B2_CONNECTIONS+x}" ] || B2_ARG=(--option b2.connections="$B2_CONNECTIONS")
# Remove locks from other stale processes to keep the automated backup running.
# NOTE nope, don't unlock like restic_backup.sh. restic_backup.sh should take precedence over this script.
@@ -36,7 +55,7 @@ assert_envvars \
#wait $!
# Check repository for errors.
restic check \
--option b2.connections="$B2_CONNECTIONS" \
echo restic check \
"${B2_ARG[@]}" \
--verbose="$RESTIC_VERBOSITY_LEVEL" &
wait $!