-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-compose-use
executable file
·100 lines (68 loc) · 2.81 KB
/
docker-compose-use
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
#!/bin/bash
# Run this preprocessor when the configuration changes to
# regenerate the .env file for docker-compose
#
# 1) cd to the directory where your configuration files are.
# 2) Invoke the specific `docker-compose-use` that belongs to your Angelbox instance
# you may have more than one!
set -ue
# Command
ANGELBOX_DIR=$(readlink -f "${BASH_SOURCE[0]%/*}")
# Argument $1 : The source *.env file (comments and blank lines allowed)
SERVICES="${1:-angelbox.env}"
# Argument $2 : A second source *.env file providing server specific environment values
VALUES="${2:-/etc/angelbox/server.env}"
# Environment variable allows alternative output file for testing
out="${DCU_OUT:-$ANGELBOX_DIR/.env}"
# Environment variable points to default server configuration file
SERVER_ENV_FILE="${SERVER_ENV_FILE:-/etc/angelbox/server.env}"
## Reset the output file
cp /dev/null ${out}
## Prepend servers own environment variables
if [[ -f "${SERVER_ENV_FILE}" ]]; then
echo "######################################################################" >> ${out}
echo "SERVER_FILE=$SERVER_ENV_FILE" > "${out}"
echo "## From: $SERVER_ENV_FILE" >> "${out}"
cat "$SERVER_ENV_FILE" >> "${out}"
fi
## Process services definition file
echo "######################################################################" >> ${out}
echo "SERVICES_FILE=$SERVICES" >> "${out}"
echo "## From: $SERVICES" >> "${out}"
# Temporary files
rand=$RANDOM
tmpA="/tmp/dcu-${rand}a"
tmpB="/tmp/dcu-${rand}b"
tmpC="/tmp/dcu-${rand}c"
# Step 1. Whitespace is trimmed
sed -E 's/^ *//;s/ *$//' "$SERVICES" > "$tmpA"
# Step 2. Lines with a single '#' are removed completely)
# This allows commenting to work within a series of \ separated lines
# not conventional, but more readable
## lines will survive this filter.
grep -vE "^#([^#]|$)" "$tmpA" > "$tmpB"
# Step 3. Remove Empty lines
grep . "$tmpB" > "$tmpA"
# Step 4. Lines ending in \ are concatenated
awk '{if (sub(/\\$/,"")) printf "%s", $0; else print $0}' "$tmpA" >> "${out}"
## Append additional environment variables
echo "######################################################################" >> ${out}
echo "PARAMETERS_FILE=$VALUES" >> "${out}"
echo "## From: $VALUES" >> "${out}"
cat "$VALUES" >> "${out}"
## Append the ANGEL environment variable
echo "######################################################################" >> ${out}
echo "## From: ANGEL_<item>" >> ${out}
printf "ANGEL=" >> ${out}
printf "%s " $(sed -n 's/^ANGEL_\(.*\)/\1/pg' "$SERVER_ENV_FILE") >> ${out}
printf "%s " $(sed -n 's/^ANGEL_\(.*\)/\1/pg' "$SERVICES") >> ${out}
printf "%s " $(sed -n 's/^ANGEL_\(.*\)/\1/pg' "$VALUES") >> ${out}
echo >> ${out}
echo >> ${out}
## Append miscellaneous items
echo "## Miscellaneous" >> ${out}
myip=$(curl -sL ipecho.net/plain)
echo "MYIP=${myip}" >> ${out}
## Report success
echo "Set ${out}" 2>&1
set +ue