浏览代码

Initial setup with zigbee2mqtt

master
Dirk Alders 1年前
父节点
当前提交
9a692e4c01
共有 9 个文件被更改,包括 188 次插入0 次删除
  1. 1
    0
      .gitignore
  2. 26
    0
      Makefile
  3. 3
    0
      template/Dockerfile
  4. 14
    0
      template/docker-compose.template
  5. 10
    0
      template/start.sh
  6. 13
    0
      zigbee/Dockerfile
  7. 28
    0
      zigbee/README
  8. 20
    0
      zigbee/docker-compose.template
  9. 73
    0
      zigbee/start.sh

+ 1
- 0
.gitignore 查看文件

@@ -1,3 +1,4 @@
1
+docker-compose.yml
1 2
 # ---> Linux
2 3
 *~
3 4
 

+ 26
- 0
Makefile 查看文件

@@ -0,0 +1,26 @@
1
+DOCKER_COMP = sudo docker-compose
2
+
3
+help:
4
+	echo Help is not yet implemented...
5
+
6
+
7
+build:
8
+	$(DOCKER_COMP) build
9
+
10
+up: ## Starts the docker hub
11
+	$(DOCKER_COMP) up -d
12
+
13
+down: ## Stops the docker hub
14
+	$(DOCKER_COMP) down --remove-orphans
15
+
16
+restart: ## Restarts the docker hub
17
+	$(DOCKER_COMP) restart
18
+
19
+shell_%: ## Connects to the application container
20
+	$(DOCKER_COMP) exec $(subst shell_,,$@) bash
21
+
22
+logs_%: ## Displays the logs of the application container
23
+	$(DOCKER_COMP) logs -f $(subst logs_,,$@)
24
+
25
+cleanall:
26
+	sudo docker system prune -a

+ 3
- 0
template/Dockerfile 查看文件

@@ -0,0 +1,3 @@
1
+FROM debian:bookworm
2
+RUN echo $TESTVAR_1 > /root/test.txt
3
+COPY start.sh /root

+ 14
- 0
template/docker-compose.template 查看文件

@@ -0,0 +1,14 @@
1
+#version: '3'
2
+#services:
3
+
4
+  template:
5
+    restart: always
6
+    build: template
7
+    container_name: template
8
+    #network_mode: host
9
+    #privileged: true
10
+    #devices:
11
+    #  - /dev/ttyACM0:/dev/ttyACM0
12
+    #volumes:
13
+    #  - /opt/zigbee2mqtt:/opt/zigbee2mqtt
14
+    command: bash -c "/root/start.sh"

+ 10
- 0
template/start.sh 查看文件

@@ -0,0 +1,10 @@
1
+#!/bin/bash
2
+#
3
+echo "************************************"
4
+echo "* This is a template only!         *"
5
+echo "* No Application has been started. *"
6
+echo "************************************"
7
+for (( ; ; ))
8
+do
9
+    sleep 60
10
+done

+ 13
- 0
zigbee/Dockerfile 查看文件

@@ -0,0 +1,13 @@
1
+FROM debian:bookworm
2
+RUN apt update
3
+RUN apt upgrade -y
4
+RUN apt install curl git -y
5
+# INSTALL nodejs
6
+RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
7
+RUN apt install nodejs -y
8
+# INSTALL yarn
9
+RUN curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null
10
+RUN echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | tee /etc/apt/sources.list.d/yarn.list
11
+RUN apt update
12
+RUN apt install yarn -y
13
+COPY start.sh /root

+ 28
- 0
zigbee/README 查看文件

@@ -0,0 +1,28 @@
1
+Install intruction:
2
+===================
3
+
4
+Configuration:
5
+--------------
6
+* Append the docker-compose.template to your docker-compose.yml
7
+  * Edit the volumes section, to have a persistant zigbee2mqtt instance
8
+    at your local filesystem (fist entry is your local filesystem;
9
+    leave the second entry ontouched)
10
+  * Edit the environment variable of the added service, if you need to
11
+    create a zigbee2mqtt instance or 
12
+    delete the variables, if you want to run an existing instance.
13
+  * Check and edit (if needed) the device section  (first entry is your host filesystem)
14
+* You might want to set differing versions for the needed software:
15
+  * The base operating system is defined in the Dockerfile (very top entry)
16
+  * The nodejs is defined in the Dockerfile (curl after #INSTALL nodejs)
17
+  * The zigbee2mqtt is already defined via the docker-compose.yml
18
+
19
+Installation:
20
+-------------
21
+* Execute make build up logs_zigbee
22
+
23
+Post-Installation actions:
24
+--------------------------
25
+* You should remove the environments section espacially the credentials
26
+  from docker-compose.yml
27
+* You should "chmod go-rwx" for ...zigbee2mqtt/data/configuration.yaml
28
+

+ 20
- 0
zigbee/docker-compose.template 查看文件

@@ -0,0 +1,20 @@
1
+#version: '3'
2
+#services:
3
+
4
+  zigbee:
5
+    restart: always
6
+    build: zigbee
7
+    container_name: zigbee
8
+    volumes:
9
+      - /opt/zigbee2mqtt:/opt/zigbee2mqtt
10
+    environment:
11
+      APP_GIT_VERSION: 1.31.2
12
+      #APP_MQTT_SERVER: mqtt_server
13
+      #APP_MQTT_USER: mqtt_user
14
+      #APP_MQTT_PASSWORD: mqtt_password
15
+    network_mode: host
16
+    #privileged: true
17
+    devices:
18
+      - /dev/ttyACM0:/dev/ttyACM0
19
+    command: bash -c "/root/start.sh"
20
+

+ 73
- 0
zigbee/start.sh 查看文件

@@ -0,0 +1,73 @@
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

正在加载...
取消
保存