gencode-remote 820 Bytes
Newer Older
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
#!/bin/sh

passphrase=
appendonly=

case "$(cat "${__object:?}/parameter/encryption")" in
	none)
		enc=none
		;;
	repokey)
		enc=repokey
		if [ -f "${__object:?}/parameter/passphrase" ];
		then
			passphrase="$(cat "${__object:?}/parameter/passphrase")"
		else
			echo "__borg_repo cannot use repokey encryption with no passphrase. Aborting." >&2;
			exit 1;
		fi
		;;
	*)
		echo "$enc is not a known encryption mode for __borg_repo. Aborting." >&2
		exit 1;
esac

if [ -f "${__object:?}/parameter/append-only" ];
then
	appendonly='--append-only'
fi

30 31 32 33 34
if [ -f "${__object:?}/parameter/owner" ];
then
	doas="sudo -u '$(cat "${__object:?}/parameter/owner")'"
fi

35
cat <<- EOF
36 37 38
	set -x
	if [ ! -d "/${__object_id:?}" ]; then
		$doas BORG_NEW_PASSPHRASE=$passphrase borg init -e ${enc:?} $appendonly /${__object_id:?}
39 40 41
	fi
EOF