diff --git a/profiles/templates/homeassistant/hass-configurator/.calculate_directory b/profiles/templates/homeassistant/hass-configurator/.calculate_directory new file mode 100644 index 0000000..ae03782 --- /dev/null +++ b/profiles/templates/homeassistant/hass-configurator/.calculate_directory @@ -0,0 +1 @@ +# Calculate env=install ac_install_merge==on mergepkg(www-servers/nginx)!= append=skip diff --git a/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/.calculate_directory b/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/.calculate_directory new file mode 100644 index 0000000..be71fb9 --- /dev/null +++ b/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/.calculate_directory @@ -0,0 +1 @@ +# Calculate append=skip grep(/etc/passwd,#-cut(1,.)-#)== diff --git a/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/hass-configurator.group b/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/hass-configurator.group new file mode 100644 index 0000000..92b4f5e --- /dev/null +++ b/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/hass-configurator.group @@ -0,0 +1,2 @@ +# Calculate path=/etc name=#-cut(1,.)-# append=after protected +hass-configurator:x:997: diff --git a/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/hass-configurator.passwd b/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/hass-configurator.passwd new file mode 100644 index 0000000..ce6a75f --- /dev/null +++ b/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/hass-configurator.passwd @@ -0,0 +1,2 @@ +# Calculate path=/etc name=#-cut(1,.)-# append=after protected +hass-configurator:x:997:997:Filesystem-browser and text-editor:/var/calculate/www/hass-configurator:/bin/bash diff --git a/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/hass-configurator.shadow b/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/hass-configurator.shadow new file mode 100644 index 0000000..9a34db4 --- /dev/null +++ b/profiles/templates/homeassistant/hass-configurator/0-adduser.hass-configurator/hass-configurator.shadow @@ -0,0 +1,2 @@ +# Calculate path=/etc name=#-cut(1,.)-# append=after protected +hass-configurator:!:19459:0:99999:7::: diff --git a/profiles/templates/homeassistant/hass-configurator/data/.calculate_directory b/profiles/templates/homeassistant/hass-configurator/data/.calculate_directory new file mode 100644 index 0000000..250bad3 --- /dev/null +++ b/profiles/templates/homeassistant/hass-configurator/data/.calculate_directory @@ -0,0 +1 @@ +# Calculate path=/var/calculate name=hass-configurator chmod=700 chown=hass-configurator:hass-configurator diff --git a/profiles/templates/homeassistant/hass-configurator/init.hass-configurator b/profiles/templates/homeassistant/hass-configurator/init.hass-configurator new file mode 100644 index 0000000..f0d6dd3 --- /dev/null +++ b/profiles/templates/homeassistant/hass-configurator/init.hass-configurator @@ -0,0 +1,22 @@ +# Calculate path=/etc/init.d name=#-cut(1,.)-# chmod=755 comment=# exists(/var/calculate/www/hass-configurator/hass-configurator-live)!= +#!/sbin/openrc-run +# Copyright 2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +description="Filesystem-browser and text-editor" + +user="hass-configurator" +group="hass-configurator" + +command="/var/calculate/www/${RC_SVCNAME}/${RC_SVCNAME}-live/.venv/bin/hass-configurator" +directory="/var/calculate/www/${RC_SVCNAME}/${RC_SVCNAME}-live" +command_args="/var/calculate/hass-configurator/settings.conf" +command_user="${user}:${group}" +command_background="yes" +pidfile="/run/${RC_SVCNAME}.pid" +output_log="/var/log/${RC_SVCNAME}.log" +error_log="${output_log}" + +start_pre() { + checkpath --file --owner $user --mode 0644 $output_log +} diff --git a/profiles/templates/homeassistant/hass-configurator/link.hass-configurator b/profiles/templates/homeassistant/hass-configurator/link.hass-configurator new file mode 100644 index 0000000..34af040 --- /dev/null +++ b/profiles/templates/homeassistant/hass-configurator/link.hass-configurator @@ -0,0 +1 @@ +# Calculate path=/etc name=#-cut(1,.)-# link=/var/calculate/#-cut(1,.)-# symbolic protected diff --git a/profiles/templates/homeassistant/hass-configurator/runlevel.hass-configurator b/profiles/templates/homeassistant/hass-configurator/runlevel.hass-configurator new file mode 100644 index 0000000..98d048b --- /dev/null +++ b/profiles/templates/homeassistant/hass-configurator/runlevel.hass-configurator @@ -0,0 +1 @@ +# Calculate path=/etc/runlevels/default name=#-cut(1,.)-# link=/etc/init.d/#-cut(1,.)-# protected symbolic exists(/var/calculate/www/#-cut(1,.)-#/#-cut(1,.)-#-live)!= diff --git a/profiles/templates/homeassistant/hass-configurator/www/.calculate_directory b/profiles/templates/homeassistant/hass-configurator/www/.calculate_directory new file mode 100644 index 0000000..814ccaf --- /dev/null +++ b/profiles/templates/homeassistant/hass-configurator/www/.calculate_directory @@ -0,0 +1 @@ +# Calculate path=/var/calculate diff --git a/profiles/templates/homeassistant/hass-configurator/www/hass-configurator/.calculate_directory b/profiles/templates/homeassistant/hass-configurator/www/hass-configurator/.calculate_directory new file mode 100644 index 0000000..bcbc890 --- /dev/null +++ b/profiles/templates/homeassistant/hass-configurator/www/hass-configurator/.calculate_directory @@ -0,0 +1 @@ +# Calculate chmod=700 chown=hass-configurator:hass-configurator diff --git a/profiles/templates/homeassistant/homeassistant/init.homeassistant b/profiles/templates/homeassistant/homeassistant/init.homeassistant index df482bb..a3b8dde 100644 --- a/profiles/templates/homeassistant/homeassistant/init.homeassistant +++ b/profiles/templates/homeassistant/homeassistant/init.homeassistant @@ -1,6 +1,6 @@ # Calculate path=/etc/init.d name=#-cut(1,.)-# chmod=755 comment=# exists(/etc/homeassistant/configuration.yaml)!= #!/sbin/openrc-run -# Copyright 2022 Gentoo Authors +# Copyright 2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 description="Open-source home automation platform" @@ -12,20 +12,20 @@ serverlog="/var/log/homeassistant/server.log" warningslog="/var/log/homeassistant/warnings.log" retry="20" -command=/var/calculate/www/homeassistant/homeassistant-live/bin/hass -directory=/var/calculate/www/homeassistant +command=/var/calculate/www/${RC_SVCNAME}/${RC_SVCNAME}-live/bin/hass +directory=/var/calculate/www/${RC_SVCNAME}/${RC_SVCNAME}-live start_stop_daemon_args="--user $user --stdout $stdoutlog --stderr $serverlog --wait 10" command_args=" - --config /var/calculate/homeassistant + --config /var/calculate/${RC_SVCNAME} --log-file $warningslog --log-rotate-days 9 ${HASS_OPTS} " command_background=yes -pidfile=/run/homeassistant.pid +pidfile=/run/${RC_SVCNAME}.pid depend() { need net nginx postgresql diff --git a/profiles/templates/homeassistant/homeassistant/www/homeassistant/.calculate_directory b/profiles/templates/homeassistant/homeassistant/www/homeassistant/.calculate_directory index cbe41bd..d405340 100644 --- a/profiles/templates/homeassistant/homeassistant/www/homeassistant/.calculate_directory +++ b/profiles/templates/homeassistant/homeassistant/www/homeassistant/.calculate_directory @@ -1 +1 @@ -# Calculate chmod=750 chown=homeassistant:homeassistant +# Calculate chmod=700 chown=homeassistant:homeassistant diff --git a/profiles/templates/homeassistant/nginx/0-ini.env b/profiles/templates/homeassistant/nginx/0-ini.env index f70918c..e47afbd 100644 --- a/profiles/templates/homeassistant/nginx/0-ini.env +++ b/profiles/templates/homeassistant/nginx/0-ini.env @@ -1,3 +1,4 @@ # Calculate format=samba path=/var/calculate name=#-cut(1)-# grep(/var/calculate/ini.env,\[nginx\])== protected [nginx] zigbee2mqtt_subpath = #-rnd(pas,32)-# +hass-configurator_subpath = #-rnd(pas,32)-# diff --git a/profiles/templates/homeassistant/nginx/homeassistant.conf b/profiles/templates/homeassistant/nginx/homeassistant.conf index 94dd393..5b82aa7 100644 --- a/profiles/templates/homeassistant/nginx/homeassistant.conf +++ b/profiles/templates/homeassistant/nginx/homeassistant.conf @@ -41,7 +41,6 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } - location /#-ini(nginx.zigbee2mqtt_subpath)-#/api { proxy_pass http://localhost:8080/api; proxy_set_header Host $host; @@ -51,4 +50,11 @@ server { proxy_set_header Connection "upgrade"; } + # HASS Configurator + location /#-ini(nginx.hass-configurator_subpath)-#/ { + proxy_pass http://localhost:3218/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } } diff --git a/profiles/templates/homeassistant/zigbee2mqtt/init.zigbee2mqtt b/profiles/templates/homeassistant/zigbee2mqtt/init.zigbee2mqtt index 5249313..9d8b200 100644 --- a/profiles/templates/homeassistant/zigbee2mqtt/init.zigbee2mqtt +++ b/profiles/templates/homeassistant/zigbee2mqtt/init.zigbee2mqtt @@ -8,7 +8,7 @@ description="Allows you to use your Zigbee devices without the vendor's bridge o user="zigbee2mqtt" group="zigbee2mqtt" -command="/var/calculate/www/zigbee2mqtt/zigbee2mqtt-live/.venv/bin/npm" +command="/var/calculate/www/${RC_SVCNAME}/${RC_SVCNAME}-live/.venv/bin/npm" directory="/var/calculate/www/${RC_SVCNAME}/${RC_SVCNAME}-live" command_args="start" command_user="${user}:${group}" @@ -16,7 +16,7 @@ command_background="yes" pidfile="/run/${RC_SVCNAME}.pid" output_log="/var/log/${RC_SVCNAME}.log" error_log="${output_log}" -export PATH="/var/calculate/www/zigbee2mqtt/zigbee2mqtt-live/.venv/bin:$PATH" +export PATH="/var/calculate/www/${RC_SVCNAME}/${RC_SVCNAME}-live/.venv/bin:$PATH" depend() { need mosquitto diff --git a/profiles/templates/homeassistant/zigbee2mqtt/runlevel.zigbee2mqtt b/profiles/templates/homeassistant/zigbee2mqtt/runlevel.zigbee2mqtt index 80af438..98d048b 100644 --- a/profiles/templates/homeassistant/zigbee2mqtt/runlevel.zigbee2mqtt +++ b/profiles/templates/homeassistant/zigbee2mqtt/runlevel.zigbee2mqtt @@ -1 +1 @@ -# Calculate path=/etc/runlevels/default name=#-cut(1,.)-# link=/etc/init.d/#-cut(1,.)-# protected symbolic exists(/var/calculate/www/zigbee2mqtt/zigbee2mqtt-live)!= +# Calculate path=/etc/runlevels/default name=#-cut(1,.)-# link=/etc/init.d/#-cut(1,.)-# protected symbolic exists(/var/calculate/www/#-cut(1,.)-#/#-cut(1,.)-#-live)!= diff --git a/profiles/templates/homeassistant/zigbee2mqtt/www/zigbee2mqtt/.calculate_directory b/profiles/templates/homeassistant/zigbee2mqtt/www/zigbee2mqtt/.calculate_directory index 0915611..15d3cfb 100644 --- a/profiles/templates/homeassistant/zigbee2mqtt/www/zigbee2mqtt/.calculate_directory +++ b/profiles/templates/homeassistant/zigbee2mqtt/www/zigbee2mqtt/.calculate_directory @@ -1 +1 @@ -# Calculate chmod=750 chown=zigbee2mqtt:zigbee2mqtt +# Calculate chmod=700 chown=zigbee2mqtt:zigbee2mqtt diff --git a/profiles/templates/homeassistant/zz-check-crashed/conf.check-crashed b/profiles/templates/homeassistant/zz-check-crashed/conf.check-crashed index 53ce28b..3e72230 100644 --- a/profiles/templates/homeassistant/zz-check-crashed/conf.check-crashed +++ b/profiles/templates/homeassistant/zz-check-crashed/conf.check-crashed @@ -1,2 +1,2 @@ # Calculate format=openrc path=/etc/conf.d name=#-cut(1,.)-# -RC_MONITOR_RESTART="zigbee2mqtt homeassistant mosquitto" +RC_MONITOR_RESTART="zigbee2mqtt homeassistant mosquitto hass-configurator" diff --git a/profiles/templates/homeassistant/zz-check-crashed/init.check-crashed b/profiles/templates/homeassistant/zz-check-crashed/init.check-crashed index 989406c..7d41452 100644 --- a/profiles/templates/homeassistant/zz-check-crashed/init.check-crashed +++ b/profiles/templates/homeassistant/zz-check-crashed/init.check-crashed @@ -1,6 +1,7 @@ # Calculate path=/etc/init.d name=#-cut(1,.)-# chmod=755 comment=# #!/sbin/openrc-run - +# Copyright 2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 pidfile="/run/check_crashed.pid" command="/var/calculate/bin/check-crashed" command_args="${RC_MONITOR_RESTART}" diff --git a/scripts/homeassistant/step/3-zigbee2mqtt.sh b/scripts/homeassistant/step/3-zigbee2mqtt.sh index 3453e6f..b20f996 100755 --- a/scripts/homeassistant/step/3-zigbee2mqtt.sh +++ b/scripts/homeassistant/step/3-zigbee2mqtt.sh @@ -52,13 +52,13 @@ echo '. ~/zigbee2mqtt-live/.venv/bin/activate' >> .bashrc echo '. ~/zigbee2mqtt-live/.venv/bin/activate' >> .bash_profile ebegin 'Setup zigbee2mqtt' -mv zigbee2mqtt-live/data/configuration.yaml zigbee2mqtt-live/data/configuration.yaml.old -cat > zigbee2mqtt-live/data/configuration.yaml << EOF +mv /etc/zigbee2mqtt/configuration.yaml /etc/zigbee2mqtt/configuration.yaml.old +cat > /etc/zigbee2mqtt/configuration.yaml << EOF # Home Assistant integration (MQTT discovery) homeassistant: true # allow new devices to join -permit_join: true +permit_join: false # MQTT settings mqtt: diff --git a/scripts/homeassistant/step/4-hass-configurator.sh b/scripts/homeassistant/step/4-hass-configurator.sh new file mode 100755 index 0000000..eae07cf --- /dev/null +++ b/scripts/homeassistant/step/4-hass-configurator.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# Guide: https://github.com/danielperna84/hass-configurator + +set -ueo pipefail +export PATH="/lib/rc/bin:$PATH" + +test -e ~/hass-configurator-live && exit + +SCRIPT=$(readlink -f $0) +[[ $UID == 0 ]] && exec su - hass-configurator -c "$SCRIPT" + +. /var/db/repos/container/scripts/functions.sh +. /var/db/repos/calculate/scripts/ini.sh + +cd +ver=$(curl -s https://api.github.com/repos/danielperna84/hass-configurator/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest hass-configurator version is ${ver}" +[[ -z $ver ]] && eerror 'The latest version of hass-configurator is not defined!' + +wget -q https://github.com/danielperna84/hass-configurator/archive/refs/tags/${ver}.zip -O hass-configurator-${ver}.zip +einfo 'Extract the archive' +unzip -q -d versions hass-configurator-${ver}.zip +rm hass-configurator-${ver}.zip +ln -sf versions/hass-configurator-${ver} hass-configurator-live + +einfo 'Install python env' +python -m venv hass-configurator-live/.venv + +einfo 'Activate environment' +. hass-configurator-live/.venv/bin/activate + +einfo 'Upgrade pip and wheel' +pip install --upgrade pip wheel + +einfo 'Install HASS Configurator' +pip install hass-configurator + +echo '. ~/hass-configurator-live/.venv/bin/activate' >> .bashrc +echo '. ~/hass-configurator-live/.venv/bin/activate' >> .bash_profile + +ebegin 'Setup HASS Configurator' +if [[ ! -e /etc/hass-configurator/settings.conf ]]; then + cat > /etc/hass-configurator/settings.conf << EOF +{ + "LISTENIP": "0.0.0.0", + "PORT": 3218, + "GIT": false, + "BASEPATH": null, + "ENFORCE_BASEPATH": false, + "SSL_CERTIFICATE": null, + "SSL_KEY": null, + "IGNORE_SSL": false, + "HASS_API": "http://127.0.0.1:8123/api/", + "HASS_WS_API": null, + "HASS_API_PASSWORD": null, + "USERNAME": null, + "PASSWORD": null, + "ALLOWED_NETWORKS": [], + "ALLOWED_DOMAINS": [], + "BANNED_IPS": [], + "BANLIMIT": 0, + "IGNORE_PATTERN": [], + "DIRSFIRST": false, + "SESAME": null, + "SESAME_TOTP_SECRET": null, + "VERIFY_HOSTNAME": null, + "ENV_PREFIX": "HC_", + "NOTIFY_SERVICE": "persistent_notification.create" +} +EOF +fi +eend diff --git a/scripts/homeassistant/step/4-config.sh b/scripts/homeassistant/step/5-config.sh similarity index 74% rename from scripts/homeassistant/step/4-config.sh rename to scripts/homeassistant/step/5-config.sh index 59d1858..38ed442 100755 --- a/scripts/homeassistant/step/4-config.sh +++ b/scripts/homeassistant/step/5-config.sh @@ -34,9 +34,13 @@ recorder: panel_iframe: zigbee: - title: "Zigbee2mqtt" - url: "${ini[homeassistant.protocol]}://${ini[homeassistant.domain]}/${ini[nginx.zigbee2mqtt_subpath]}" + title: Zigbee2mqtt + url: ${ini[homeassistant.protocol]}://${ini[homeassistant.domain]}/${ini[nginx.zigbee2mqtt_subpath]} icon: mdi:zigbee + configurator: + title: Configurator + icon: mdi:wrench + url: ${ini[homeassistant.protocol]}://${ini[homeassistant.domain]}/${ini[nginx.hass-configurator_subpath]} EOF echo