-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwith_repo.sh
executable file
·47 lines (34 loc) · 1.18 KB
/
with_repo.sh
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
set -euo pipefail
# Sets up environment variables and credentials for borg to open a repository.
# If repository does not exist on disk, then it'll be initialized from scratch using
# init_repo.sh script.
repo_name="${1}"
shift
: "${ZORG_USE_BORG_CACHE:=0}"
scriptdir="$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")"
source "${scriptdir}/common.sh"
repodir="${scriptdir}/repos"
_borgdir="$(mktemp --tmpdir -d borghome."${USER}".XXXXXXX)"
cleanup_borgdir () {
rm -rf "${_borgdir}" || true
}
cleanup_hooks+=(cleanup_borgdir)
repo="$(resolve_repo_dir "${repodir}" "${repo_name}")"
if [ -z "${repo}" ]; then
"${scriptdir}/init_repo.sh" "${repo_name}"
repo="$(resolve_repo_dir "${repodir}" "${repo_name}")"
[ -n "${repo}" ]
fi
"${scriptdir}/pass_repo.sh" "${repo_name}" key | write_file 400 "${_borgdir}/repo/key"
if [ "${ZORG_USE_BORG_CACHE}" = "1" ]; then
cachedir="${scriptdir}/cache"
mkdir -p "${cachedir}"
export BORG_CACHE_DIR="${cachedir}"
fi
export BORG_PASSCOMMAND="${scriptdir}/pass_repo.sh '${repo_name}' passphrase"
export BORG_KEY_FILE="${_borgdir}/repo/key"
export BORG_BASE_DIR="${_borgdir}"
export BORG_REPO="${repo}"
export BORG_SELFTEST="disabled"
"${@}"