-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-entrypoint.sh
executable file
·88 lines (80 loc) · 2.28 KB
/
docker-entrypoint.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
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
88
#!/bin/sh
if [ -z "${ENTRYPOINT_QUIET_LOGS:-}" ]; then
exec 3>&1
else
exec 3>/dev/null
fi
if [ "$1" = "backup" ]; then
/setup.sh || exit 1
shift
# backup only specified
if [ -n "$1" ]; then
backupProviderScript="${1}.sh"
if [ -e "/backup-providers.d/$backupProviderScript" ]; then
echo >&3 "Launching $backupProviderScript";
if /launcher.sh "/backup-providers.d/$backupProviderScript" "backup" "$@"; then
echo >&3 "Success: $backupProviderScript"
else
ERR_CODE=$?
echo >&3 "Fail: $backupProviderScript. Error code: $ERR_CODE"
exit $ERR_CODE
fi
else
echo >&2 "Not found /backup-providers.d/$backupProviderScript"
exit 1
fi
fi
# backup all
if /usr/bin/find "/backup-providers.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
ERR_CODE=0
for f in $(find "/backup-providers.d/" -follow -type f -print | sort -V); do
case "$f" in
*.sh)
prettyF=${f##*/}
if [ -x "$f" ]; then
echo >&3 "Launching $prettyF";
if /launcher.sh "$f" "backup"; then
echo >&3 "Success: $prettyF"
else
ERR_CODE=$?
echo >&3 "Fail: $prettyF. Error code: $ERR_CODE"
fi
else
echo >&3 "Ignoring $f"
fi
;;
*) echo >&3 "Ignoring $f";;
esac
done
if [ $ERR_CODE -eq 0 ]; then
echo >&3 "$1 done"
exit 0
else
echo >&3 "$1 done with errors"
exit $ERR_CODE
fi
else
echo >&3 "No files found in /backup-providers.d/"
fi
elif [ "$1" = "restore" ]; then
backupProviderScript="${2}.sh"
[ -z "$backupProviderScript" ] && echo "No backup file specified" && exit 1
shift # restore command
shift # script name
/setup.sh || exit 1
if [ -e "/backup-providers.d/$backupProviderScript" ]; then
echo >&3 "Launching $backupProviderScript";
if /launcher.sh "/backup-providers.d/$backupProviderScript" "restore" "$@"; then
echo >&3 "Success: $backupProviderScript"
else
ERR_CODE=$?
echo >&3 "Fail: $backupProviderScript. Error code: $ERR_CODE"
exit $ERR_CODE
fi
else
echo >&2 "Not found /backup-providers.d/$backupProviderScript"
exit 1
fi
else
exec "$@"
fi