-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.sh
81 lines (68 loc) · 2.38 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
#!/bin/bash
function timestamp() {
date +"%Y%M%d-%H%M%S"
}
function urlencode() {
# urlencode <string>
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c"
esac
done
}
function urldecode() {
# urldecode <string>
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\\x}"
}
### user name recognition at runtime w/ an arbitrary uid - for OpenShift deployments
if ! whoami &> /dev/null; then
if [ -w /etc/passwd ]; then
echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${MULE_HOME}:/sbin/nologin" >> /etc/passwd
fi
fi
if [ "${IGNORE_TLS}" = true ]; then
export NODE_TLS_REJECT_UNAUTHORIZED=0
fi
if [ -r "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt" ]; then
#Trust OpenShift self-signed certificates
export NODE_EXTRA_CA_CERTS=/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt
fi
if [ -z "${COUCH_URL}" ]; then
echo "Missing COUCH_URL Parameter";exit 1
fi
if [ -z "${COUCH_DATABASE}" ]; then
echo "Missing COUCH_DATABASE Parameter";exit 1
fi
if [ -n "${COUCH_USERNAME}" ] || [ -n "${COUCH_PASSWORD}"]; then
ENCODED_PASSWORD=$(urlencode ${COUCH_PASSWORD})
ENCODED_USERNAME=$(urlencode ${COUCH_USERNAME})
HOSTNAME="${COUCH_URL#http://}"
HOSTNAME="${COUCH_URL#https://}"
PROTOCOL="${COUCH_URL%%://*}"
export COUCH_URL_FULL="${PROTOCOL}://${ENCODED_USERNAME}:${ENCODED_PASSWORD}@${HOSTNAME}"
else
export COUCH_URL_FULL=${COUCH_URL}
fi
if [ "$1" == "restore" ]; then
echo ""
echo "*** Restore Instructions ***"
echo "-----------------------------"
echo "1. Locate the backup to restore from in ${DESTINATION_DIRECTORY}"
echo "2. Run the following command to restore the database"
echo " cat ${DESTINATION_DIRECTORY}/${COUCH_DATABASE}.<timestamp>.txt.gz | gunzip | couchrestore -db ${COUCH_DATABASE} --url \${COUCH_URL_FULL}"
echo "-----------------------------"
exec bash
else
DESTFILE=${DESTINATION_DIRECTORY}/${COUCH_DATABASE}.$(timestamp).txt.gz
exec couchbackup \
--buffer-size ${BUFFER_SIZE} \
--mode ${MODE} \
--request-timeout ${REQUEST_TIMEOUT} \
--parallelism ${PARALLELISM} \
--url ${COUCH_URL_FULL} \
--db ${COUCH_DATABASE} | gzip > ${DESTFILE}
fi