-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.sh
executable file
·60 lines (50 loc) · 1.6 KB
/
entry.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
#!/usr/bin/env bash
# Entry point to mount s3ql filesystem before exec'ing command.
# Fail on all script errors
set -e
[ "${DEBUG:-false}" == 'true' ] && { set -x; S3QL_DEBUG='--debug'; }
# Defaults
: ${S3QL_DATADIR:='/var/s3ql'}
: ${S3QL_AUTHFILE:="${S3QL_DATADIR}/authinfo2"}
: ${S3QL_CACHEDIR:="${S3QL_DATADIR}/cache"}
: ${S3QL_MOUNTPOINT:='/mnt'}
: ${S3QL_ARGS:=''}
: ${S3QL_BACKEND:='s3'}
# Configuration checks
if [ -z "$S3QL_BUCKET_URL" ]; then
echo "Error: S3QL_BUCKET_URL is not specified"
exit 128
fi
if [ -z "$S3QL_ENCRYPTION_PASSPHRASE" ]; then
echo "Error: S3QL_ENCRYPTION_PASSPHRASE not specified"
exit 128
fi
if [ -z "$S3QL_ACCESS_KEY" ]; then
echo "Error: S3QL_ACCESS_KEY not specified"
exit 128
fi
if [ -z "$S3QL_ACCESS_SECRET" ]; then
echo "Error: S3QL_ACCESS_SECRET not specified"
exit 128
fi
echo "==> Mounting S3QL Filesystem"
mkdir -p ${S3QL_MOUNTPOINT} ${S3QL_DATADIR} ${S3QL_CACHEDIR}
# Write auth file if it does not exist
if [ ! -f "${S3QL_AUTHFILE}" ]; then
(
echo "[${S3QL_BACKEND}]"
echo "storage-url: ${S3QL_BUCKET_URL}"
echo "backend-login: ${S3QL_ACCESS_KEY}"
echo "backend-password: ${S3QL_ACCESS_SECRET}"
echo "fs-passphrase: ${S3QL_ENCRYPTION_PASSPHRASE}"
) > "${S3QL_AUTHFILE}"
chmod 400 ${S3QL_AUTHFILE}
fi
if [ -z "$1" ]; then
set -ex
mount.s3ql $S3QL_DEBUG $S3QL_ARGS --cachedir $S3QL_CACHEDIR --authfile $S3QL_AUTHFILE --fg $S3QL_BUCKET_URL $S3QL_MOUNTPOINT
else
(set -ex; mount.s3ql $S3QL_DEBUG $S3QL_ARGS --cachedir $S3QL_CACHEDIR --authfile $S3QL_AUTHFILE $S3QL_BUCKET_URL $S3QL_MOUNTPOINT)
echo "Running command $@"
exec "$@"
fi