From 013c7763dc4332c468c38295d8e9bb72ec1ca6a7 Mon Sep 17 00:00:00 2001 From: Alexander Tratsevskiy Date: Sat, 8 Apr 2023 22:39:01 +0300 Subject: [PATCH] =?UTF-8?q?homeassistant:=20=D0=BD=D0=B0=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=B9=D0=BA=D0=B0=20zigbee2mqtt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homeassistant.passwd | 2 +- .../homeassistant/homeassistant/ini.env | 2 +- profiles/templates/homeassistant/world | 1 + .../0-adduser.zigbee2mqtt/zigbee2mqtt.passwd | 2 +- .../homeassistant/zigbee2mqtt/ini.env | 4 ++ scripts/homeassistant/setup.sh | 2 + scripts/homeassistant/step/3-zigbee2mqtt.sh | 66 +++++++++++++------ 7 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 profiles/templates/homeassistant/zigbee2mqtt/ini.env diff --git a/profiles/templates/homeassistant/homeassistant/0-adduser.homeassistant/homeassistant.passwd b/profiles/templates/homeassistant/homeassistant/0-adduser.homeassistant/homeassistant.passwd index a0c0b70..f8ef574 100644 --- a/profiles/templates/homeassistant/homeassistant/0-adduser.homeassistant/homeassistant.passwd +++ b/profiles/templates/homeassistant/homeassistant/0-adduser.homeassistant/homeassistant.passwd @@ -1,2 +1,2 @@ # Calculate path=/etc name=#-cut(1,.)-# append=after protected -homeassistant:x:999:999:Home Assistant Program User:/var/calculate/www/homeassistant:/sbin/nologin +homeassistant:x:999:999:Home Assistant Program User:/var/calculate/www/homeassistant:/bin/bash diff --git a/profiles/templates/homeassistant/homeassistant/ini.env b/profiles/templates/homeassistant/homeassistant/ini.env index a47e25f..de612b0 100644 --- a/profiles/templates/homeassistant/homeassistant/ini.env +++ b/profiles/templates/homeassistant/homeassistant/ini.env @@ -1,4 +1,4 @@ -# Calculate format=samba path=/var/calculate chmod=600 chown=homeassistant:homeassistant grep(/var/calculate/ini.env,homeassistant_sites_domain)== protected +# Calculate format=samba path=/var/calculate chmod=600 grep(/var/calculate/ini.env,homeassistant_sites_domain)== protected [homeassistant] protocol = http domain = home.example.org diff --git a/profiles/templates/homeassistant/world b/profiles/templates/homeassistant/world index 43e22ef..55606bd 100644 --- a/profiles/templates/homeassistant/world +++ b/profiles/templates/homeassistant/world @@ -1,4 +1,5 @@ # Calculate env=update ac_update_sync==on path=/var/lib/portage cl_update_world==merge||cl_update_world==rebuild format=world +app-arch/unzip app-misc/mosquitto dev-db/postgresql www-servers/nginx diff --git a/profiles/templates/homeassistant/zigbee2mqtt/0-adduser.zigbee2mqtt/zigbee2mqtt.passwd b/profiles/templates/homeassistant/zigbee2mqtt/0-adduser.zigbee2mqtt/zigbee2mqtt.passwd index 5e34746..1aebc39 100644 --- a/profiles/templates/homeassistant/zigbee2mqtt/0-adduser.zigbee2mqtt/zigbee2mqtt.passwd +++ b/profiles/templates/homeassistant/zigbee2mqtt/0-adduser.zigbee2mqtt/zigbee2mqtt.passwd @@ -1,2 +1,2 @@ # Calculate path=/etc name=#-cut(1,.)-# append=after protected -zigbee2mqtt:x:998:998:A user for zigbee2mqtt:/var/calculate/www/zigbee2mqtt:/sbin/nologin +zigbee2mqtt:x:998:998:A user for zigbee2mqtt:/var/calculate/www/zigbee2mqtt:/bin/bash diff --git a/profiles/templates/homeassistant/zigbee2mqtt/ini.env b/profiles/templates/homeassistant/zigbee2mqtt/ini.env new file mode 100644 index 0000000..4d002d1 --- /dev/null +++ b/profiles/templates/homeassistant/zigbee2mqtt/ini.env @@ -0,0 +1,4 @@ +# Calculate format=samba path=/var/calculate chmod=600 grep(/var/calculate/ini.env,zigbee2mqtt)== protected +[zigbee2mqtt] +dev = /dev/ttyACM0 +nodeenv = 16.15.0 diff --git a/scripts/homeassistant/setup.sh b/scripts/homeassistant/setup.sh index 6607085..7e826cb 100755 --- a/scripts/homeassistant/setup.sh +++ b/scripts/homeassistant/setup.sh @@ -6,9 +6,11 @@ scriptpath=$(dirname $(readlink -f $0)) . /var/db/repos/calculate/scripts/ini.sh +chmod o+rw /var/calculate/ini.env for script in $scriptpath/step/*.sh; do "$script" done +chmod o-rw /var/calculate/ini.env if [[ ! -e /etc/runlevels/default/homeassistant ]]; then cl-setup-system diff --git a/scripts/homeassistant/step/3-zigbee2mqtt.sh b/scripts/homeassistant/step/3-zigbee2mqtt.sh index bf6a476..a24d61d 100755 --- a/scripts/homeassistant/step/3-zigbee2mqtt.sh +++ b/scripts/homeassistant/step/3-zigbee2mqtt.sh @@ -9,33 +9,61 @@ SCRIPT=$(readlink -f $0) . /var/db/repos/container/scripts/functions.sh . /var/db/repos/calculate/scripts/ini.sh -if [[ ! -e ~/.venv-live ]]; then +if [[ ! -e ~/zigbee2mqtt-live ]]; then + cd einfo 'Clone Zigbee2MQTT repository' - git clone --depth 1 https://github.com/Koenkk/zigbee2mqtt.git ~/ - chown -R zigbee2mqtt: ~/ + ver=$(curl -s https://api.github.com/repos/Koenkk/zigbee2mqtt/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest Zigbee2MQTT version is ${ver}" + wget -q https://github.com/Koenkk/zigbee2mqtt/archive/refs/tags/${ver}.zip -O zigbee2mqtt-${ver}.zip + einfo 'Extract the archive' + unzip -q -d versions zigbee2mqtt-${ver}.zip + rm zigbee2mqtt-${ver}.zip + ln -sf versions/zigbee2mqtt-${ver} zigbee2mqtt-live + + einfo 'Install python env' + python -m venv zigbee2mqtt-live/.venv + + einfo 'Activate environment' + . zigbee2mqtt-live/.venv/bin/activate - einfo 'Create a virtualenv' - python -m venv ~/.venv-live - echo '. ~/.venv-live/bin/activate' >> ~/.bashrc - echo '. ~/.venv-live/bin/activate' >> ~/.bash_profile - - . ~/.venv-live/bin/activate + einfo 'Upgrade pip, wheel and setuptools' + pip install --upgrade pip wheel setuptools einfo 'Install node environment' - python -m pip nodeenv + pip install nodeenv einfo 'Init node environment' - nodeenv -p -n 16.15.0 - - einfo 'Deactivate and activate environment to be sure' - deactivate - . ~/.venv-live/bin/activate + nodeenv -p -n ${ini[zigbee2mqtt.nodeenv]} einfo 'Install dependencies' - cd + cd zigbee2mqtt-live npm ci + cd + + echo '. ~/zigbee2mqtt-live/.venv/bin/activate' >> .bashrc + echo '. ~/zigbee2mqtt-live/.venv/bin/activate' >> .bash_profile + + einfo 'Setup zigbee2mqtt' + mv zigbee2mqtt-live/data/configuration.yaml zigbee2mqtt-live/data/configuration.yaml.old + cat > zigbee2mqtt-live/data/configuration.yaml << EOF +# Home Assistant integration (MQTT discovery) +homeassistant: false + +# allow new devices to join +permit_join: true + +# MQTT settings +mqtt: + # MQTT base topic for zigbee2mqtt MQTT messages + base_topic: zigbee2mqtt + # MQTT server URL + server: 'mqtt://localhost' + # MQTT server authentication, uncomment if required: + # # user: my_user + # password: my_password -# ha_ver=$(pip list | grep ^zigbee2mqtt | awk '{print $2}') -# mv ~/.venv-live ~/.venv-${ha_ver} -# ln -s ~/.venv-${ha_ver} ~/.venv-live +# Serial settings +serial: + # Location of USB sniffer + port: ${ini[zigbee2mqtt.dev]} +EOF fi