-
Notifications
You must be signed in to change notification settings - Fork 72
/
entrypoint
executable file
·87 lines (80 loc) · 2.94 KB
/
entrypoint
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
set -euo pipefail
RCLONE_CONFIG_PATH="/run/secrets/rclone.conf"
if [[ -f "$RCLONE_CONFIG_PATH" ]]; then
mkdir -p /root/.config/rclone
cp "$RCLONE_CONFIG_PATH" /root/.config/rclone/rclone.conf
fi
SSH_CONFIG_PATH="/run/secrets/.ssh"
if [[ -d "$SSH_CONFIG_PATH" ]]; then
cp -r "${SSH_CONFIG_PATH}/." /root/.ssh
chmod 700 /root/.ssh
chmod -R u+rwX,go-rwx /root/.ssh
fi
command="${1-}"
if [[ "$command" != "unlock" ]]; then
echo "Checking configured repository '${RESTIC_REPOSITORY}' ..."
if restic cat config > /dev/null; then
echo "Repository found."
else
echo "Could not access the configured repository."
if [ "${SKIP_INIT:-}" == "true" ]; then
echo "Not trying to initialize because SKIP_INIT is set in your configuration.."
else
echo "Trying to initialize (in case it has not been initialized yet) ..."
if restic init; then
echo "Repository successfully initialized."
else
if [ "${SKIP_INIT_CHECK:-}" == "true" ]; then
echo "Initialization failed. Ignoring errors because SKIP_INIT_CHECK is set in your configuration."
else
echo "Initialization failed. Please see error messages above and check your configuration. Exiting."
exit 1
fi
fi
fi
fi
echo -e "\n"
fi
if [[ $# -gt 0 ]]; then
exec restic "$@"
else
if [[ -n "${BACKUP_CRON:-}" ]] && [[ -n "${PRUNE_CRON:-}" ]]; then
>&2 echo "Environment variables BACKUP_CRON and PRUNE_CRON are mutually exclusive. Please fix your configuration. Exiting."
exit 1
fi
if [[ -n "${BACKUP_CRON:-}" ]] && [[ -n "${CHECK_CRON:-}" ]]; then
>&2 echo "Environment variables BACKUP_CRON and CHECK_CRON are mutually exclusive. Please fix your configuration. Exiting."
exit 1
fi
if [[ -n "${PRUNE_CRON:-}" ]] && [[ -n "${CHECK_CRON:-}" ]]; then
>&2 echo "Environment variables PRUNE_CRON and CHECK_CRON are mutually exclusive. Please fix your configuration. Exiting."
exit 1
fi
if [[ -n "${BACKUP_CRON:-}" ]]; then
if [ "${RUN_ON_STARTUP:-}" == "true" ]; then
echo "Executing backup on startup ..."
/usr/local/bin/backup
fi
echo "Scheduling backup job according to cron expression."
exec go-cron "$BACKUP_CRON" /usr/local/bin/backup
fi
if [[ -n "${PRUNE_CRON:-}" ]]; then
if [ "${RUN_ON_STARTUP:-}" == "true" ]; then
echo "Executing prune job on startup ..."
/usr/local/bin/prune
fi
echo "Scheduling prune job according to cron expression."
exec go-cron "$PRUNE_CRON" /usr/local/bin/prune
fi
if [[ -n "${CHECK_CRON:-}" ]]; then
if [ "${RUN_ON_STARTUP:-}" == "true" ]; then
echo "Executing check job on startup ..."
/usr/local/bin/check
fi
echo "Scheduling check job according to cron expression."
exec go-cron "$CHECK_CRON" /usr/local/bin/check
fi
>&2 echo "No valid operating mode configured! Please set either the BACKUP_CRON, PRUNE_CRON or CHECK_CRON environment variable."
exit 1
fi