-
Notifications
You must be signed in to change notification settings - Fork 490
Expand file tree
/
Copy pathconfig.sh
More file actions
126 lines (113 loc) · 2.65 KB
/
config.sh
File metadata and controls
126 lines (113 loc) · 2.65 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
shopt -s nullglob
###
# Check if current user is root
#
##
function rootCheck() {
# Root check
if [ "$(/usr/bin/whoami)" != "root" ]; then
echo "[ERROR] $* must be run as root"
exit 1
fi
}
###
# Create /docker.stdout and /docker.stderr
#
##
function createDockerStdoutStderr() {
# link stdout from docker
if [[ -n "$LOG_STDOUT" ]]; then
echo "Log stdout redirected to $LOG_STDOUT"
else
LOG_STDOUT="/proc/$$/fd/1"
fi
if [[ -n "$LOG_STDERR" ]]; then
echo "Log stderr redirected to $LOG_STDERR"
else
LOG_STDERR="/proc/$$/fd/2"
fi
ln -f -s "$LOG_STDOUT" /docker.stdout
ln -f -s "$LOG_STDERR" /docker.stderr
}
###
# Include script directory text inside a file
#
# $1 -> path
#
##
function includeScriptDir() {
if [[ -d "$1" ]]; then
for FILE in "$1"/*.sh; do
echo "-> Executing ${FILE}"
# run custom scripts, only once
. "$FILE"
done
fi
}
###
# Show deprecation notice
#
##
function deprecationNotice() {
echo ""
echo "###############################################################################"
echo "### THIS CALL IS DEPRECATED AND WILL BE REMOVED IN THE FUTURE"
echo "###"
echo "### $*"
echo "###"
echo "###############################################################################"
echo ""
}
###
# Run "entrypoint" scripts
#
##
function runEntrypoints() {
# try to find entrypoint task script
ENTRYPOINT_SCRIPT="/opt/docker/bin/entrypoint.d/${TASK}.sh"
if [ ! -f "$ENTRYPOINT_SCRIPT" ]; then
# use default
ENTRYPOINT_SCRIPT="/opt/docker/bin/entrypoint.d/default.sh"
fi
if [ ! -f "$ENTRYPOINT_SCRIPT" ]; then
exit 1
fi
. "$ENTRYPOINT_SCRIPT"
}
###
# Run "entrypoint" provisioning
#
##
function runProvisionEntrypoint() {
includeScriptDir "/opt/docker/provision/entrypoint.d"
includeScriptDir "/entrypoint.d"
}
###
# https://stackoverflow.com/questions/41451159/how-to-execute-a-script-when-i-terminate-a-docker-container
# https://hynek.me/articles/docker-signals/
#
##
function runTeardownEntrypoint() {
echo "Container stopped, performing teardown..."
includeScriptDir "/opt/docker/provision/entrypoint.d/teardown"
includeScriptDir "/entrypoint.d/teardown"
}
###
# List environment variables (based on prefix)
#
##
function envListVars() {
if [[ $# -eq 1 ]]; then
env | grep "^${1}" | cut -d= -f1
else
env | cut -d= -f1
fi
}
###
# Get environment variable (even with dots in name)
#
##
function envGetValue() {
awk "BEGIN {print ENVIRON[\"$1\"]}"
}