|
@@ -1,73 +0,0 @@
|
1
|
|
-#!/bin/bash
|
2
|
|
-#
|
3
|
|
-
|
4
|
|
-APP_TARGET_PATH=/opt/zigbee2mqtt
|
5
|
|
-
|
6
|
|
-my_print()
|
7
|
|
-{
|
8
|
|
- echo `date` $HOST [$$]: $1
|
9
|
|
-}
|
10
|
|
-
|
11
|
|
-fail_loop()
|
12
|
|
-{
|
13
|
|
- my_print "Start script failed..."
|
14
|
|
- for (( ; ; ))
|
15
|
|
- do
|
16
|
|
- sleep 60
|
17
|
|
- done
|
18
|
|
-}
|
19
|
|
-
|
20
|
|
-check_environment()
|
21
|
|
-{
|
22
|
|
- fail=0
|
23
|
|
- # returns 0 if environment is not okay
|
24
|
|
- if [[ -z $APP_GIT_VERSION ]]; then
|
25
|
|
- my_print "Environment variable APP_GIT_VERSION does not exist!"
|
26
|
|
- fail=1
|
27
|
|
- fi
|
28
|
|
- if [[ -z $APP_MQTT_SERVER ]]; then
|
29
|
|
- my_print "Environment variable APP_MQTT_SERVER does not exist!"
|
30
|
|
- fail=1
|
31
|
|
- fi
|
32
|
|
- #
|
33
|
|
- if [[ $fail -ne 0 ]]; then
|
34
|
|
- fail_loop
|
35
|
|
- fi
|
36
|
|
-}
|
37
|
|
-
|
38
|
|
-
|
39
|
|
-
|
40
|
|
-if [[ ! -d $APP_TARGET_PATH ]]; then
|
41
|
|
- my_print "Directory \"$APP_TARGET_PATH\" does not exist."
|
42
|
|
-fi
|
43
|
|
-if [[ ! -d $APP_TARGET_PATH/.git ]]; then
|
44
|
|
- check_environment
|
45
|
|
- my_print "Cloning zigbee2mqtt repository..."
|
46
|
|
- git clone https://github.com/Koenkk/zigbee2mqtt.git $APP_TARGET_PATH
|
47
|
|
- my_print "Changing to directory $APP_TARGET_PAT"
|
48
|
|
- cd $APP_TARGET_PATH
|
49
|
|
- my_print "Changing to git version $APP_GIT_VERSION"
|
50
|
|
- git checkout $APP_GIT_VERSION
|
51
|
|
- my_print "Replacing MQTT servername in $APP_TARGET_PATH/data/configuration.yaml"
|
52
|
|
- sed -i "s|mqtt://localhost|mqtt://$APP_MQTT_SERVER|g" $APP_TARGET_PATH/data/configuration.yaml
|
53
|
|
- if [[ ! -z $APP_MQTT_USER ]]; then
|
54
|
|
- my_print "Adding MQTT username in $APP_TARGET_PATH/data/configuration.yaml"
|
55
|
|
- sed -i "s|# user: my_user|user: $APP_MQTT_USER|g" $APP_TARGET_PATH/data/configuration.yaml
|
56
|
|
- fi
|
57
|
|
- if [[ ! -z $APP_MQTT_PASSWORD ]]; then
|
58
|
|
- my_print "Adding MQTT password in $APP_TARGET_PATH/data/configuration.yaml"
|
59
|
|
- sed -i "s|# password: my_password|password: $APP_MQTT_PASSWORD|g" $APP_TARGET_PATH/data/configuration.yaml
|
60
|
|
- fi
|
61
|
|
- my_print "Preparing application (npm ci)"
|
62
|
|
- npm ci
|
63
|
|
-fi
|
64
|
|
-
|
65
|
|
-cd $APP_TARGET_PATH
|
66
|
|
-my_print "Starting zigbee2mqtt..."
|
67
|
|
-npm start
|
68
|
|
-
|
69
|
|
-my_print "**********************************************************"
|
70
|
|
-my_print "* Start of zigbee2mqtt failed. *"
|
71
|
|
-my_print "* Check running npm ci and npm start in /opt/zigbee2mqtt *"
|
72
|
|
-my_print "**********************************************************"
|
73
|
|
-fail_loop
|