summaryrefslogtreecommitdiffstats
path: root/bin/setup_borgbackup
blob: 6e857a134440757bc3dc8222eb560dfbd5906949 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh -e

BORG_SECRET=~/.borg_secret
BORG_SSH_KEY=~/.ssh/borg_key

if [ ! -f "$BORG_SECRET" ]; then
	install -m600 /dev/null "$BORG_SECRET"
	pass backups/$(hostname) > "$BORG_SECRET"
fi

if [ ! -f "$BORG_SSH_KEY" ]; then
	ssh-keygen -q -N "" -f "$BORG_SSH_KEY"
	KEY=$(< ${BORG_SSH_KEY}.pub)

	printf '%s\n' "command=\"cd /srv/borgbackup/repos/$(hostname);borg serve --restrict-to-path /srv/borgbackup/repos/$(hostname)\",restrict $KEY" | ssh "$1" "cat >> /srv/borgbackup/.ssh/authorized_keys"

	echo "Added key to remote server."
fi