summaryrefslogtreecommitdiff
path: root/borg-family-0.2/src/sbin/bfenv
blob: 756ef62988599b1b7692f7d0cd516340ff939d09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
umask 0077
source /etc/borg-family/confvars
source /etc/borg-family/envvars
PATH="/etc/borg-family:$PATH"

if [ \! -r /etc/borg-family/passphrase ]; then
	echo "No passphrase (repokey) found, creating a new one" >&2
	touch /etc/borg-family/passphrase
	chmod 600 /etc/borg-family/passphrase
	pwgen 32 1 >> /etc/borg-family/passphrase
	ls -l /etc/borg-family/passphrase >&2
	echo "You NEED to store it in a password manager to be able to restore backups" >&2
fi

if [ \! -r /etc/borg-family/id_rsa_borg ]; then
	echo "No SSH key found, creating a new one" >&2
	ssh-keygen -N "" -C "$(id -un)_borg@$(hostname)" -f /etc/borg-family/id_rsa_borg \
		&& cat /etc/borg-family/id_rsa_borg.pub
fi

borg init "${borg_init_opts[@]}" 2>&1 | grep -vE '^A repository already exists' >&2

if ! borg check "${borg_check_opts[@]}"; then
	echo "Showing BORG_* env variables (see /etc/borg-family/envvars) :" >&2
	env | grep ^BORG_ >&2
	echo "End of BORG_* env variables" >&2
	echo >&2
	echo "Can't access to or check the borg repository, exiting, no backup made" >&2
	exit 1
fi