-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommon.sh
46 lines (36 loc) · 897 Bytes
/
common.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
set -e -E -o pipefail
err_exit() {
echo "$0: exit with error on line $1" >&2
}
trap 'err_exit $LINENO' ERR
[ -f "$HOME/.env.restic" ] && . $HOME/.env.restic
if [ -z "$LOGNAME" ]
then
echo LOGNAME must contain the username
exit 2
fi
if [ -z "$RESTIC_REPOSITORY" -a -z "$RESTIC_ARCHIVE_REPOSITORY" ]
then
echo one of RESTIC_REPOSITORY and RESTIC_ARCHIVE_REPOSITORY
echo must specify the restic repository.
exit 2
fi
if [ -z "$RESTIC_PASSWORD_FILE" ]
then
echo RESTIC_PASSWORD_FILE must specify the restic repository password.
exit 2
fi
use_archive_repository() {
if [ -n "$RESTIC_ARCHIVE_REPOSITORY" ]
then
export RESTIC_REPOSITORY=$RESTIC_ARCHIVE_REPOSITORY
fi
}
use_transient_repository() {
if [ -n "$RESTIC_TRANSIENT_REPOSITORY" ]
then
export RESTIC_REPOSITORY=$RESTIC_TRANSIENT_REPOSITORY
fi
}
[ -d "log" ] || mkdir log
LOG="log/$(basename $0)-$(date +%Y-%m-%d).log"