init.sh: remote path parameter validation

This commit is contained in:
Ludwig Behm 2023-04-06 01:00:36 +02:00
parent 0a9a5f9a71
commit 06cf4d8bde
Signed by: l.behm
GPG key ID: D344835D63B89384

14
init.sh
View file

@ -3,7 +3,7 @@
SELF="$0" SELF="$0"
HOST="" HOST=""
PORT="22" PORT="22"
REMOTE_PATH="borg" REMOTE_PATH=""
NAME="" NAME=""
LOGIN="$(whoami)" LOGIN="$(whoami)"
@ -11,6 +11,11 @@ die () {
echo -e $1 | sed -e 's-^-! -' >&2 echo -e $1 | sed -e 's-^-! -' >&2
exit 1 exit 1
} }
usage() {
echo -e "usage: $SELF PROFILE_NAME --host=server --port=22 --login=backup-user --directory=/backup/path" >&2
exit 1
}
generate_passphrase() { generate_passphrase() {
tr -dc A-Za-z0-9 </dev/urandom | head -c 64 tr -dc A-Za-z0-9 </dev/urandom | head -c 64
} }
@ -59,7 +64,7 @@ test_repo_exists() {
} }
invoke_borg() { invoke_borg() {
# do some sandboxinng # do some sandboxinng
systemd-run --pipe --collect --unit=temp-borg-init-sandbox.service \ systemd-run --quiet --pipe --collect --unit=temp-borg-init-sandbox.service \
--working-directory=/tmp \ --working-directory=/tmp \
-p "ConfigurationDirectory=borg/$NAME" \ -p "ConfigurationDirectory=borg/$NAME" \
-p "CacheDirectory=borg/$NAME" \ -p "CacheDirectory=borg/$NAME" \
@ -83,10 +88,6 @@ show_repo() {
invoke_borg info || die "failed to access borg repo" invoke_borg info || die "failed to access borg repo"
} }
usage() {
die "Usage: $SELF PROFILE_NAME --host=server --port=22 --login=backup-user --directory=/backup/path"
}
for arg in "$@"; do for arg in "$@"; do
case "$arg" in case "$arg" in
-h*) -h*)
@ -124,6 +125,7 @@ for arg in "$@"; do
done done
[ "x$NAME" == "x" ] && usage [ "x$NAME" == "x" ] && usage
[ "x$REMOTE_PATH" == "x" ] && usage
CONFIGDIR="/etc/borg/$NAME" CONFIGDIR="/etc/borg/$NAME"