-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdocker-entrypoint.sh
executable file
·90 lines (83 loc) · 2.16 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
89
90
#!/usr/bin/env bash
OS=""
MYUPGRADE="0"
DectectOS(){
if [ -e /etc/alpine-release ]; then
OS="alpine"
elif [ -e /etc/os-release ]; then
if grep -q "NAME=\"Ubuntu\"" /etc/os-release ; then
OS="ubuntu"
fi
if grep -q "NAME=\"CentOS Linux\"" /etc/os-release ; then
OS="centos"
fi
fi
}
AutoUpgrade(){
if [ "$(id -u)" = '0' ]; then
if [ -n "${DOCKUPGRADE}" ]; then
MYUPGRADE="${DOCKUPGRADE}"
fi
if [ "${MYUPGRADE}" == 1 ]; then
if [ "${OS}" == "alpine" ]; then
apk --no-cache upgrade
rm -rf /var/cache/apk/*
elif [ "${OS}" == "ubuntu" ]; then
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y --no-install-recommends dist-upgrade
apt-get -y autoclean
apt-get -y clean
apt-get -y autoremove
rm -rf /var/lib/apt/lists/*
elif [ "${OS}" == "centos" ]; then
yum upgrade -y
yum clean all
rm -rf /var/cache/yum/*
fi
fi
fi
}
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
DockLog(){
if [ "${OS}" == "centos" ] || [ "${OS}" == "alpine" ]; then
echo "${1}"
else
logger "${1}"
fi
}
DectectOS
AutoUpgrade
if [ "${1}" == 'certbot' ]; then
if [ -z "${DOCKMAIL}" ]; then
DockLog "ERROR: administrator email is mandatory"
elif [ -z "${DOCKDOMAINS}" ]; then
DockLog "ERROR: at least one domain must be specified"
else
exec certbot certonly --verbose --noninteractive --quiet --standalone --agree-tos --email="${DOCKMAIL}" -d "${DOCKDOMAINS}"
fi
elif [ "${1}" == 'certbot-renew' ]; then
exec certbot renew
else
"$@"
fi