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

16
init.sh
View file

@ -3,14 +3,19 @@
SELF="$0"
HOST=""
PORT="22"
REMOTE_PATH="borg"
REMOTE_PATH=""
NAME=""
LOGIN="$(whoami)"
die () {
die() {
echo -e $1 | sed -e 's-^-! -' >&2
exit 1
}
usage() {
echo -e "usage: $SELF PROFILE_NAME --host=server --port=22 --login=backup-user --directory=/backup/path" >&2
exit 1
}
generate_passphrase() {
tr -dc A-Za-z0-9 </dev/urandom | head -c 64
}
@ -59,7 +64,7 @@ test_repo_exists() {
}
invoke_borg() {
# 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 \
-p "ConfigurationDirectory=borg/$NAME" \
-p "CacheDirectory=borg/$NAME" \
@ -83,10 +88,6 @@ show_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
case "$arg" in
-h*)
@ -124,6 +125,7 @@ for arg in "$@"; do
done
[ "x$NAME" == "x" ] && usage
[ "x$REMOTE_PATH" == "x" ] && usage
CONFIGDIR="/etc/borg/$NAME"