forked from AppDaemon/appdaemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockerStart.sh
49 lines (39 loc) · 1.63 KB
/
dockerStart.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
#!/bin/sh
CONF=/conf
CONF_SRC=/usr/src/app/conf
# if configuration file doesn't exist, copy the default
if [ ! -f $CONF/appdaemon.yaml ]; then
cp $CONF_SRC/appdaemon.yaml.example $CONF/appdaemon.yaml
fi
# if apps folder doesn't exist, copy the default
if [ ! -d $CONF/apps ]; then
cp -r $CONF_SRC/apps $CONF/apps
fi
# if apps file doesn't exist, copy the default
if [ ! -f $CONF/apps/apps.yaml ]; then
cp $CONF_SRC/apps/apps.yaml.example $CONF/apps/apps.yaml
fi
# if dashboards folder doesn't exist, copy the default
if [ ! -d $CONF/dashboards ]; then
cp -r $CONF_SRC/dashboards $CONF/dashboards
fi
# if ENV HA_URL is set, change the value in appdaemon.yaml
if [ -n "$HA_URL" ]; then
sed -i "s/^ ha_url:.*/ ha_url: $(echo $HA_URL | sed -e 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')/" $CONF/appdaemon.yaml
fi
# if ENV HA_KEY is set, change the value in appdaemon.yaml
if [ -n "$TOKEN" ]; then
sed -i "s/^ token:.*/ token: $(echo $TOKEN | sed -e 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')/" $CONF/appdaemon.yaml
fi
# if ENV DASH_URL is set, change the value in appdaemon.yaml
if [ -n "$DASH_URL" ]; then
if grep -q "^ url" $CONF/appdaemon.yaml; then
sed -i "s/^ url:.*/ url: $(echo $DASH_URL | sed -e 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')/" $CONF/appdaemon.yaml
else
sed -i "s/# Apps/HADashboard:\r\n url: $(echo $DASH_URL | sed -e 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')\r\n# Apps/" $CONF/appdaemon.yaml
fi
fi
#check recursively under CONF for additional python dependencies defined in requirements.txt
find $CONF -name requirements.txt -exec pip3 install --upgrade -r {} \;
# Lets run it!
exec appdaemon -c $CONF "$@"