From 9a1a418f7a09a5ceeba4741498607bc0468f7873 Mon Sep 17 00:00:00 2001 From: Alexander Tratsevskiy Date: Mon, 24 Apr 2023 16:33:38 +0300 Subject: [PATCH] =?UTF-8?q?homeassistant:=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=B5=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hass-configurator.passwd | 2 +- .../data/.calculate_directory | 1 - .../www/.calculate_directory | 1 - .../hass-configurator/.calculate_directory | 1 - .../homeassistant.passwd | 2 +- .../homeassistant/data/.calculate_directory | 1 - .../homeassistant/www/.calculate_directory | 1 - .../www/homeassistant/.calculate_directory | 1 - .../versions/.calculate_directory | 1 - profiles/templates/homeassistant/world | 1 + .../0-adduser.zigbee2mqtt/zigbee2mqtt.passwd | 2 +- .../zigbee2mqtt/data/.calculate_directory | 1 - .../zigbee2mqtt/www/.calculate_directory | 1 - .../www/zigbee2mqtt/.calculate_directory | 1 - scripts/functions.sh | 18 ++ scripts/homeassistant/setup.sh | 21 ++- scripts/homeassistant/step/1-install.sh | 101 +++++++---- scripts/homeassistant/step/2-postgresql.sh | 38 ++--- scripts/homeassistant/step/3-zigbee2mqtt.sh | 157 +++++++++++------- ...onfigurator.sh => 4-hass-configurator.sh-} | 4 +- scripts/homeassistant/step/5-config.sh | 69 ++++---- 21 files changed, 268 insertions(+), 157 deletions(-) delete mode 100644 profiles/templates/homeassistant/hass-configurator/data/.calculate_directory delete mode 100644 profiles/templates/homeassistant/hass-configurator/www/.calculate_directory delete mode 100644 profiles/templates/homeassistant/hass-configurator/www/hass-configurator/.calculate_directory delete mode 100644 profiles/templates/homeassistant/homeassistant/data/.calculate_directory delete mode 100644 profiles/templates/homeassistant/homeassistant/www/.calculate_directory delete mode 100644 profiles/templates/homeassistant/homeassistant/www/homeassistant/.calculate_directory delete mode 100644 profiles/templates/homeassistant/homeassistant/www/homeassistant/versions/.calculate_directory delete mode 100644 profiles/templates/homeassistant/zigbee2mqtt/data/.calculate_directory delete mode 100644 profiles/templates/homeassistant/zigbee2mqtt/www/.calculate_directory delete mode 100644 profiles/templates/homeassistant/zigbee2mqtt/www/zigbee2mqtt/.calculate_directory mode change 100755 => 100644 scripts/homeassistant/step/1-install.sh mode change 100755 => 100644 scripts/homeassistant/step/2-postgresql.sh mode change 100755 => 100644 scripts/homeassistant/step/3-zigbee2mqtt.sh rename scripts/homeassistant/step/{4-hass-configurator.sh => 4-hass-configurator.sh-} (95%) mode change 100755 => 100644 mode change 100755 => 100644 scripts/homeassistant/step/5-config.sh 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 index ce6a75f..4c7e65d 100644 --- 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 @@ -1,2 +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 +hass-configurator:x:997:997:Filesystem-browser and text-editor:/var/calculate/www/hass-configurator:/sbin/nologin diff --git a/profiles/templates/homeassistant/hass-configurator/data/.calculate_directory b/profiles/templates/homeassistant/hass-configurator/data/.calculate_directory deleted file mode 100644 index 250bad3..0000000 --- a/profiles/templates/homeassistant/hass-configurator/data/.calculate_directory +++ /dev/null @@ -1 +0,0 @@ -# Calculate path=/var/calculate name=hass-configurator chmod=700 chown=hass-configurator:hass-configurator diff --git a/profiles/templates/homeassistant/hass-configurator/www/.calculate_directory b/profiles/templates/homeassistant/hass-configurator/www/.calculate_directory deleted file mode 100644 index 814ccaf..0000000 --- a/profiles/templates/homeassistant/hass-configurator/www/.calculate_directory +++ /dev/null @@ -1 +0,0 @@ -# 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 deleted file mode 100644 index bcbc890..0000000 --- a/profiles/templates/homeassistant/hass-configurator/www/hass-configurator/.calculate_directory +++ /dev/null @@ -1 +0,0 @@ -# Calculate chmod=700 chown=hass-configurator:hass-configurator diff --git a/profiles/templates/homeassistant/homeassistant/0-adduser.homeassistant/homeassistant.passwd b/profiles/templates/homeassistant/homeassistant/0-adduser.homeassistant/homeassistant.passwd index f8ef574..a0c0b70 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:/bin/bash +homeassistant:x:999:999:Home Assistant Program User:/var/calculate/www/homeassistant:/sbin/nologin diff --git a/profiles/templates/homeassistant/homeassistant/data/.calculate_directory b/profiles/templates/homeassistant/homeassistant/data/.calculate_directory deleted file mode 100644 index ec5a30b..0000000 --- a/profiles/templates/homeassistant/homeassistant/data/.calculate_directory +++ /dev/null @@ -1 +0,0 @@ -# Calculate path=/var/calculate name=homeassistant chmod=700 chown=homeassistant:homeassistant diff --git a/profiles/templates/homeassistant/homeassistant/www/.calculate_directory b/profiles/templates/homeassistant/homeassistant/www/.calculate_directory deleted file mode 100644 index 814ccaf..0000000 --- a/profiles/templates/homeassistant/homeassistant/www/.calculate_directory +++ /dev/null @@ -1 +0,0 @@ -# Calculate path=/var/calculate diff --git a/profiles/templates/homeassistant/homeassistant/www/homeassistant/.calculate_directory b/profiles/templates/homeassistant/homeassistant/www/homeassistant/.calculate_directory deleted file mode 100644 index d405340..0000000 --- a/profiles/templates/homeassistant/homeassistant/www/homeassistant/.calculate_directory +++ /dev/null @@ -1 +0,0 @@ -# Calculate chmod=700 chown=homeassistant:homeassistant diff --git a/profiles/templates/homeassistant/homeassistant/www/homeassistant/versions/.calculate_directory b/profiles/templates/homeassistant/homeassistant/www/homeassistant/versions/.calculate_directory deleted file mode 100644 index 2be8757..0000000 --- a/profiles/templates/homeassistant/homeassistant/www/homeassistant/versions/.calculate_directory +++ /dev/null @@ -1 +0,0 @@ -# Calculate chown=homeassistant:homeassistant diff --git a/profiles/templates/homeassistant/world b/profiles/templates/homeassistant/world index 55606bd..8651a44 100644 --- a/profiles/templates/homeassistant/world +++ b/profiles/templates/homeassistant/world @@ -1,5 +1,6 @@ # 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/jq 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 1aebc39..5e34746 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:/bin/bash +zigbee2mqtt:x:998:998:A user for zigbee2mqtt:/var/calculate/www/zigbee2mqtt:/sbin/nologin diff --git a/profiles/templates/homeassistant/zigbee2mqtt/data/.calculate_directory b/profiles/templates/homeassistant/zigbee2mqtt/data/.calculate_directory deleted file mode 100644 index 37d838e..0000000 --- a/profiles/templates/homeassistant/zigbee2mqtt/data/.calculate_directory +++ /dev/null @@ -1 +0,0 @@ -# Calculate path=/var/calculate name=zigbee2mqtt chmod=700 chown=zigbee2mqtt:zigbee2mqtt diff --git a/profiles/templates/homeassistant/zigbee2mqtt/www/.calculate_directory b/profiles/templates/homeassistant/zigbee2mqtt/www/.calculate_directory deleted file mode 100644 index 814ccaf..0000000 --- a/profiles/templates/homeassistant/zigbee2mqtt/www/.calculate_directory +++ /dev/null @@ -1 +0,0 @@ -# Calculate path=/var/calculate diff --git a/profiles/templates/homeassistant/zigbee2mqtt/www/zigbee2mqtt/.calculate_directory b/profiles/templates/homeassistant/zigbee2mqtt/www/zigbee2mqtt/.calculate_directory deleted file mode 100644 index 15d3cfb..0000000 --- a/profiles/templates/homeassistant/zigbee2mqtt/www/zigbee2mqtt/.calculate_directory +++ /dev/null @@ -1 +0,0 @@ -# Calculate chmod=700 chown=zigbee2mqtt:zigbee2mqtt diff --git a/scripts/functions.sh b/scripts/functions.sh index 0a427b3..db51fae 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -27,3 +27,21 @@ arr_to_list(){ list="[$list]" echo $list } + +get_last_ver(){ + local project=$1 + local hosting=$2 + case $hosting in + pip) + curl -s https://pypi.org/pypi/${project}/json | jq -r '.releases | keys[]' | grep -Ev [ab][0-9]+$ | tail -1 + ;; + github) + curl -s https://api.github.com/repos/${project}/releases/latest | grep tag_name | cut -d '"' -f 4 + ;; + esac +} + +get_live_ver(){ + local current_ver=$(readlink -f $1) + echo ${current_ver#*-} +} diff --git a/scripts/homeassistant/setup.sh b/scripts/homeassistant/setup.sh index 83521dc..fca53e0 100755 --- a/scripts/homeassistant/setup.sh +++ b/scripts/homeassistant/setup.sh @@ -2,13 +2,21 @@ set -ueo pipefail export PATH="/lib/rc/bin:$PATH" -scriptpath=$(dirname $(readlink -f $0)) -. /var/db/repos/calculate/scripts/ini.sh +source /var/db/repos/calculate/scripts/ini.sh +source /var/db/repos/container/scripts/functions.sh -chmod o+r /var/calculate/ini.env -for script in $scriptpath/step/*.sh; do - "$script" +action=${1:-} + +script_path=$(dirname $(readlink -f $0)) +for script in $script_path/step/*.sh; do + source "$script" + configure "$action" daemon_name + daemon_restart+=(${daemon_name:-}) +done + +for i in ${daemon_restart[@]}; do + rc-service -s $i stop done if [[ ! -e /etc/runlevels/default/homeassistant ]]; then @@ -16,6 +24,5 @@ if [[ ! -e /etc/runlevels/default/homeassistant ]]; then rc-update -u fi openrc -chmod 600 /var/calculate/ini.env -echo -e "\nAll is done! Open the link ${ini[homeassistant.protocol]}://${ini[homeassistant.domain]} on your browser." +echo "All is done! Open the link ${ini[homeassistant.protocol]}://${ini[homeassistant.domain]} on your browser." diff --git a/scripts/homeassistant/step/1-install.sh b/scripts/homeassistant/step/1-install.sh old mode 100755 new mode 100644 index c1e1716..44dbf1f --- a/scripts/homeassistant/step/1-install.sh +++ b/scripts/homeassistant/step/1-install.sh @@ -1,34 +1,71 @@ -#!/bin/bash +# +# Функция configure() устанавливает Home Assistant +# +# Параметры: +# $1 = check - проверка обновлений, в противном случае установка или обновление +# $2 - возвращает имя модуля для перезагрузки в случае выполненного обновления +configure() { + local action=$1 + local __result=$2 -set -ueo pipefail -export PATH="/lib/rc/bin:$PATH" + local home_dir=/var/calculate/www/homeassistant + local last_ver="$(get_last_ver homeassistant pip)" + local work_dir="$home_dir/versions/homeassistant-$last_ver" + local live_dir="$home_dir/homeassistant-live" + local live_ver="$(get_live_ver $live_dir)" + + if [[ $action == 'check' ]]; then + if [[ $live_ver == $last_ver ]]; then + einfo "homeassistant: the latest version is installed $live_ver" + else + einfo "homeassistant: $last_ver update available, $live_ver installed" + eval $__result=1 # наличие обновления + fi + return + fi -test -e ~/homeassistant-live && exit - -SCRIPT=$(readlink -f $0) -[[ $UID == 0 ]] && exec su - homeassistant -c "$SCRIPT" - -. /var/db/repos/container/scripts/functions.sh -. /var/db/repos/calculate/scripts/ini.sh - -cd -einfo 'Create a virtualenv' - -python -m venv homeassistant-live -. homeassistant-live/bin/activate - -einfo 'Install all Python dependencies' -python -m pip install wheel - -einfo 'Install Home Assistant' -pip install homeassistant - -einfo 'Install PostgreSQL dependencies' -pip install psycopg2 - -ha_ver=$(pip list | grep ^homeassistant | awk '{print $2}') -mv homeassistant-live versions/homeassistant-${ha_ver} -ln -sf versions/homeassistant-${ha_ver} homeassistant-live - -echo '. ~/homeassistant-live/bin/activate' >> ~/.bashrc -echo '. ~/homeassistant-live/bin/activate' >> ~/.bash_profile + if [[ ! -e $home_dir ]]; then + mkdir -p $home_dir/versions + chmod 700 $home_dir + chown homeassistant: $home_dir + fi + + if [[ $live_ver != $last_ver ]]; then + if [[ $live_ver != '' ]]; then + echo Update Home Assistant + else + echo Install Home Assistant + fi + + su - homeassistant -s /bin/bash -c "$(cat <<- EOF + set -ueo pipefail + export PATH="/lib/rc/bin:$PATH" + + ebegin 'Create a virtualenv' + test -e $work_dir && rm -rf $work_dir + python -m venv $work_dir + source $work_dir/bin/activate + eend + + ebegin 'Install all Python dependencies' + python -m pip install wheel &>>/tmp/homeassistant.log + eend + + ebegin 'Install Home Assistant $last_ver' + pip install homeassistant==$last_ver &>>/tmp/homeassistant.log + eend + + ebegin 'Install PostgreSQL dependencies' + pip install psycopg2 &>>/tmp/homeassistant.log + eend + + rm -f $live_dir + ln -s $work_dir $live_dir + EOF + )" + + if [[ $live_ver != '' ]]; then + eval $__result=homeassistant # демон который следует перезагрузить + fi + fi +} diff --git a/scripts/homeassistant/step/2-postgresql.sh b/scripts/homeassistant/step/2-postgresql.sh old mode 100755 new mode 100644 index 1d319ca..46f7422 --- a/scripts/homeassistant/step/2-postgresql.sh +++ b/scripts/homeassistant/step/2-postgresql.sh @@ -1,25 +1,25 @@ -#!/bin/bash +# +# Функция configure() настраивает PostgreSQL +# +# Параметры: +# $1 = check - пропуск настройки +configure() { + if [[ -n "$(ls -A /var/lib/postgresql)" ]]; then + return + fi -set -ueo pipefail + emerge --config postgresql -[[ -n "$(ls -A /var/lib/postgresql)" ]] && exit + pg_ver=$(ls /etc/init.d/postgresql-*); pg_ver=${pg_ver##*-} -export PATH="/lib/rc/bin:$PATH" + /etc/init.d/postgresql-$pg_ver start -. /var/db/repos/container/scripts/functions.sh -. /var/db/repos/calculate/scripts/ini.sh + psql -U postgres -c "ALTER USER postgres WITH PASSWORD '${ini[postgresql.postgres_password]}'" + createuser -U postgres ${ini[postgresql.homeassistant_user]} + createdb -U postgres ${ini[postgresql.homeassistant_database]} -O ${ini[postgresql.homeassistant_user]} + psql -U postgres -c "ALTER USER ${ini[postgresql.homeassistant_user]} WITH PASSWORD '${ini[postgresql.homeassistant_password]}'" -emerge --config postgresql + cl-core-setup -n postgresql -f -pg_ver=$(ls /etc/init.d/postgresql-*); pg_ver=${pg_ver##*-} - -/etc/init.d/postgresql-$pg_ver start - -psql -U postgres -c "ALTER USER postgres WITH PASSWORD '${ini[postgresql.postgres_password]}'" -createuser -U postgres ${ini[postgresql.homeassistant_user]} -createdb -U postgres ${ini[postgresql.homeassistant_database]} -O ${ini[postgresql.homeassistant_user]} -psql -U postgres -c "ALTER USER ${ini[postgresql.homeassistant_user]} WITH PASSWORD '${ini[postgresql.homeassistant_password]}'" - -cl-core-setup -n postgresql -f - -/etc/init.d/postgresql-$pg_ver restart + /etc/init.d/postgresql-$pg_ver restart +} diff --git a/scripts/homeassistant/step/3-zigbee2mqtt.sh b/scripts/homeassistant/step/3-zigbee2mqtt.sh old mode 100755 new mode 100644 index b20f996..767ed88 --- a/scripts/homeassistant/step/3-zigbee2mqtt.sh +++ b/scripts/homeassistant/step/3-zigbee2mqtt.sh @@ -1,59 +1,98 @@ -#!/bin/bash +# +# Функция configure() устанавливает Zigbee2MQTT +# +# Параметры: +# $1 = check - проверка обновлений, в противном случае установка или обновление +# $2 - возвращает имя модуля для перезагрузки в случае выполненного обновления +# # Guide: https://www.zigbee2mqtt.io/guide/installation/07_python_virtual_environment.html - -set -ueo pipefail -export PATH="/lib/rc/bin:$PATH" - -test -e ~/zigbee2mqtt-live && exit - -SCRIPT=$(readlink -f $0) -[[ $UID == 0 ]] && exec su - zigbee2mqtt -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/Koenkk/zigbee2mqtt/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest Zigbee2MQTT version is ${ver}" -[[ -z $ver ]] && eerror 'The latest version of zigbee2mqtt is not defined!' - -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 - -if [[ -z "$(ls -A /var/calculate/zigbee2mqtt)" ]]; then - mv versions/zigbee2mqtt-${ver}/data/* /var/calculate/zigbee2mqtt - rmdir versions/zigbee2mqtt-${ver}/data - ln -s /var/calculate/zigbee2mqtt versions/zigbee2mqtt-${ver}/data -fi - -einfo 'Install python env' -python -m venv zigbee2mqtt-live/.venv - -einfo 'Activate environment' -. zigbee2mqtt-live/.venv/bin/activate - -einfo 'Upgrade pip, wheel and setuptools' -pip install --upgrade pip wheel setuptools - -einfo 'Install node environment' -pip install nodeenv - -einfo 'Init node environment' -nodeenv -p -n ${ini[zigbee2mqtt.nodeenv]} - -einfo 'Install dependencies' -cd zigbee2mqtt-live -npm ci -cd - -echo '. ~/zigbee2mqtt-live/.venv/bin/activate' >> .bashrc -echo '. ~/zigbee2mqtt-live/.venv/bin/activate' >> .bash_profile - -ebegin 'Setup zigbee2mqtt' -mv /etc/zigbee2mqtt/configuration.yaml /etc/zigbee2mqtt/configuration.yaml.old -cat > /etc/zigbee2mqtt/configuration.yaml << EOF +configure() { + local action=$1 + local __result=$2 + + local home_dir=/var/calculate/www/zigbee2mqtt + local last_ver="$(get_last_ver Koenkk/zigbee2mqtt github)" + local work_dir="$home_dir/versions/zigbee2mqtt-$last_ver" + local live_dir="$home_dir/zigbee2mqtt-live" + local live_ver="$(get_live_ver $live_dir)" + + if [[ $action == 'check' ]]; then + if [[ $live_ver == $last_ver ]]; then + einfo "zigbee2mqtt: the latest version is installed $live_ver" + else + einfo "zigbee2mqtt: $last_ver update available, $live_ver installed" + eval $__result=1 # наличие обновления + fi + return + fi + + if [[ ! -e $home_dir ]]; then + mkdir -p $home_dir + chmod 700 $home_dir/versions + chown zigbee2mqtt: $home_dir + fi + + if [[ $live_ver != $last_ver ]]; then + if [[ $live_ver != '' ]]; then + echo Update Zigbee2MQTT + else + echo Install Zigbee2MQTT + fi + + su - zigbee2mqtt -s /bin/bash -c "$(cat <<- EOF + set -ueo pipefail + export PATH="/lib/rc/bin:$PATH" + + ebegin Download zigbee2mqtt ${last_ver} + test -e $work_dir && rm -rf $work_dir + wget -q https://github.com/Koenkk/zigbee2mqtt/archive/refs/tags/${last_ver}.zip \ + -O zigbee2mqtt-${last_ver}.zip + eend + + ebegin 'Extract the archive' + unzip -q -d versions zigbee2mqtt-${last_ver}.zip + rm zigbee2mqtt-${last_ver}.zip + ln -sf versions/zigbee2mqtt-${last_ver} zigbee2mqtt-live + eend + + # вынесем настройки + if [[ -z "$(ls -A /var/calculate/zigbee2mqtt)" ]]; then + mv versions/zigbee2mqtt-${last_ver}/data/* /var/calculate/zigbee2mqtt + fi + rm -rf versions/zigbee2mqtt-${last_ver}/data + ln -s /var/calculate/zigbee2mqtt versions/zigbee2mqtt-${last_ver}/data + + ebegin 'Create a virtualenv' + python -m venv zigbee2mqtt-live/.venv + eend + + ebegin 'Activate environment' + source zigbee2mqtt-live/.venv/bin/activate + eend + + ebegin 'Upgrade pip, wheel and setuptools' + pip install --upgrade pip wheel setuptools &>>/tmp/zigbee2mqtt.log + eend + + ebegin 'Install node environment' + pip install nodeenv &>>/tmp/zigbee2mqtt.log + eend + + ebegin 'Init node environment ${ini[zigbee2mqtt.nodeenv]}' + nodeenv -p -n ${ini[zigbee2mqtt.nodeenv]} &>>/tmp/zigbee2mqtt.log + eend + + einfo 'Install dependencies' + cd zigbee2mqtt-live + npm ci &>>/tmp/zigbee2mqtt.log + cd + EOF + )" + + if [[ $live_ver == '' ]]; then + ebegin 'Setup zigbee2mqtt' + mv /etc/zigbee2mqtt/configuration.yaml /etc/zigbee2mqtt/configuration.yaml.old + cat > /etc/zigbee2mqtt/configuration.yaml << EOF # Home Assistant integration (MQTT discovery) homeassistant: true @@ -78,4 +117,10 @@ frontend: port: 8080 host: 127.0.0.1 EOF -eend + chown zigbee2mqtt: /etc/zigbee2mqtt/configuration.yaml + eend + + eval $__result=zigbee2mqtt # демон который следует перезагрузить + fi + fi +} diff --git a/scripts/homeassistant/step/4-hass-configurator.sh b/scripts/homeassistant/step/4-hass-configurator.sh- old mode 100755 new mode 100644 similarity index 95% rename from scripts/homeassistant/step/4-hass-configurator.sh rename to scripts/homeassistant/step/4-hass-configurator.sh- index eae07cf..64b5b9f --- a/scripts/homeassistant/step/4-hass-configurator.sh +++ b/scripts/homeassistant/step/4-hass-configurator.sh- @@ -7,7 +7,7 @@ export PATH="/lib/rc/bin:$PATH" test -e ~/hass-configurator-live && exit SCRIPT=$(readlink -f $0) -[[ $UID == 0 ]] && exec su - hass-configurator -c "$SCRIPT" +[[ $UID == 0 ]] && exec su - hass-configurator -s /bin/bash -c "$SCRIPT" . /var/db/repos/container/scripts/functions.sh . /var/db/repos/calculate/scripts/ini.sh @@ -41,7 +41,7 @@ ebegin 'Setup HASS Configurator' if [[ ! -e /etc/hass-configurator/settings.conf ]]; then cat > /etc/hass-configurator/settings.conf << EOF { - "LISTENIP": "0.0.0.0", + "LISTENIP": "127.0.0.1", "PORT": 3218, "GIT": false, "BASEPATH": null, diff --git a/scripts/homeassistant/step/5-config.sh b/scripts/homeassistant/step/5-config.sh old mode 100755 new mode 100644 index 38ed442..df133c9 --- a/scripts/homeassistant/step/5-config.sh +++ b/scripts/homeassistant/step/5-config.sh @@ -1,28 +1,43 @@ -#!/bin/bash - -set -ueo pipefail -export PATH="/lib/rc/bin:$PATH" - -test -e /etc/homeassistant/configuration.yaml && exit - -SCRIPT=$(readlink -f $0) -[[ $UID == 0 ]] && exec su - homeassistant -c "$SCRIPT" -. homeassistant-live/bin/activate - -. /var/db/repos/container/scripts/functions.sh -. /var/db/repos/calculate/scripts/ini.sh - -hass --config /etc/homeassistant >/dev/null & -id_hass=$! - -echo; einfon "Check for the first start Home Assistant " -while ! curl http://127.0.0.1:8123 2>/dev/null; do - echo -n . - sleep 1 -done -kill $id_hass - -cat >> /etc/homeassistant/configuration.yaml </dev/null && return || true + + local home_dir=/var/calculate/www/homeassistant + local live_dir="$home_dir/homeassistant-live" + local config_dir="/var/calculate/homeassistant" + + if [[ -e $config_dir ]]; then + return + else + mkdir -p $config_dir + chmod 700 $config_dir + chown homeassistant: $config_dir + fi + + su - homeassistant -s /bin/bash -c "$(cat <<- EOF + set -ueo pipefail + export PATH="/lib/rc/bin:$PATH" + + source $live_dir/bin/activate + + hass --config /etc/homeassistant >/dev/null & + id_hass=\$! + + echo + einfon "Check for the first start Home Assistant " + while ! curl http://127.0.0.1:8123 2>/dev/null; do + echo -n . + sleep 1 + done + kill \$id_hass + eend + EOF + )" + + cat >> /etc/homeassistant/configuration.yaml << EOF http: server_host: 127.0.0.1 @@ -42,6 +57,4 @@ panel_iframe: icon: mdi:wrench url: ${ini[homeassistant.protocol]}://${ini[homeassistant.domain]}/${ini[nginx.hass-configurator_subpath]} EOF - -echo -eend +}