-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
69 lines (51 loc) · 1.49 KB
/
docker-entrypoint.sh
File metadata and controls
69 lines (51 loc) · 1.49 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
#!/bin/bash
set -e
if [ "$1" == node ]; then
: "${WORDPRESS_DB_HOST:=mysql}"
if [ ! -e config.json ]; then
awk '/^.*\"\/\/.*stop editing.*\"$/ && c == 0 { c = 1; system("cat") } { print }' config.json.example > config.json <<'EOJSON'
"//": "nothing to be added :)",
EOJSON
fi
if [ ! -e pool_configs/dash.json ]; then
awk '/^.*\"\/\/.*stop editing.*\"$/ && c == 0 { c = 1; system("cat") } { print }' pool_configs/dash.json.example > pool_configs/dash.json <<'EOJSON'
"//": "nothing to be added :)",
EOJSON
fi
# see http://stackoverflow.com/a/2705678/433558
sed_escape_lhs() {
echo "$@" | sed 's/[]\/$*.^|[]/\\&/g'
}
sed_escape_rhs() {
echo "$@" | sed 's/[\/&]/\\&/g'
}
set_config() {
file=$1
key=$2
value=$3
node <<EOJS
var jsonfile = require('jsonfile');
var _ = require('lodash');
jsonfile.spaces = 4;
var key = "$key";
var value = "$value";
// read in the JSON file
jsonfile.readFile('$file', function(err, obj) {
if (err) throw err;
// Using another variable to prevent confusion.
var fileObj = obj;
var valueInt = parseInt(value, 10);
value = (isNaN(valueInt)) ? value : valueInt;
// Modify the file at the appropriate id
_.set(fileObj, key , value);
// Write the modified obj to the file
jsonfile.writeFile('$file', fileObj, function(err) {
if (err) throw err;
});
});
EOJS
}
set_config "config.json" "website.enabled" "0"
set_config "pool_configs/dash.json" "enabled" "1"
fi
exec "$@"