summaryrefslogtreecommitdiff
path: root/borg-family-0.2/src/sbin/bfenv
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2021-06-15 16:45:20 +0200
committerLudovic Pouzenc <ludovic@pouzenc.fr>2021-06-15 16:45:20 +0200
commitb9601cf46a75b373f6b6b902d7ac2be38ab2ffe8 (patch)
treedaa3ef109d6f0b1dd7884622a2b2fba8c10e32cb /borg-family-0.2/src/sbin/bfenv
parent1ada10f44e2baf28823156c006c82a076c52f530 (diff)
downloadborg-family-b9601cf46a75b373f6b6b902d7ac2be38ab2ffe8.tar.gz
borg-family-b9601cf46a75b373f6b6b902d7ac2be38ab2ffe8.tar.bz2
borg-family-b9601cf46a75b373f6b6b902d7ac2be38ab2ffe8.zip
borg-family_0.2-1
Diffstat (limited to 'borg-family-0.2/src/sbin/bfenv')
-rwxr-xr-xborg-family-0.2/src/sbin/bfenv31
1 files changed, 31 insertions, 0 deletions
diff --git a/borg-family-0.2/src/sbin/bfenv b/borg-family-0.2/src/sbin/bfenv
new file mode 100755
index 0000000..756ef62
--- /dev/null
+++ b/borg-family-0.2/src/sbin/bfenv
@@ -0,0 +1,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