borg-backup-scripts/init.sh

26 lines
540 B
Bash
Raw Normal View History

2023-04-04 23:36:20 +02:00
#!/bin/bash
NAME="$1"
DEST="$2"
die () {
echo $1 >&2
exit 1
}
generate_passphrase() {
tr -dc A-Za-z0-9 </dev/urandom | head -c 64
}
[ "x$NAME" == "x" ] && die "Usage: $0 <name> <destination>"
[ "x$DEST" == "x" ] && die "Usage: $0 <name> <destination>"
CONFIGDIR="/etc/borg/$NAME"
[ -d "$CONFIGDIR" ] && die "Config directory already exists: $CONFIGDIR"
mkdir -p "$CONFIGDIR"
echo "BORG_REPO=$DEST" > "$CONFIGDIR/config.env"
generate_passphrase > "$CONFIGDIR/borg_passphrase"
ssh-keygen -t ed25519 -N "" -q -f "$CONFIGDIR/ssh_key"