diff --git a/scripts/homeassistant/step/1-install.sh b/scripts/homeassistant/step/1-install.sh index b533c66..0c6d92b 100644 --- a/scripts/homeassistant/step/1-install.sh +++ b/scripts/homeassistant/step/1-install.sh @@ -30,8 +30,8 @@ configure() { chown -R homeassistant: $home_dir fi - touch $log_dir/homeassistant.log - chown homeassistant: $log_dir/homeassistant.log + touch ${log_dir}/homeassistant.log + chown homeassistant: ${log_dir}/homeassistant.log if [[ $live_ver != $last_ver ]]; then if [[ $live_ver == '' ]]; then @@ -51,15 +51,15 @@ configure() { eend ebegin 'Install all Python dependencies' - python -m pip install wheel &>>$log_dir/homeassistant.log + python -m pip install wheel &>>${log_dir}/homeassistant.log eend ebegin 'Install Home Assistant $last_ver' - pip install homeassistant==$last_ver &>>$log_dir/homeassistant.log + pip install homeassistant==$last_ver &>>${log_dir}/homeassistant.log eend ebegin 'Install PostgreSQL dependencies' - pip install psycopg2 &>>$log_dir/homeassistant.log + pip install psycopg2 &>>${log_dir}/homeassistant.log eend rm -f $live_dir diff --git a/scripts/homeassistant/step/2-postgresql.sh b/scripts/homeassistant/step/2-postgresql.sh index ddaa5c9..8231d13 100644 --- a/scripts/homeassistant/step/2-postgresql.sh +++ b/scripts/homeassistant/step/2-postgresql.sh @@ -1,8 +1,6 @@ # # Функция configure() настраивает PostgreSQL # -# Параметры: -# $1 = check - пропуск настройки configure() { if [[ -n "$(ls -A /var/lib/postgresql)" ]]; then return @@ -11,26 +9,26 @@ configure() { echo 'Setting up PostgreSQL' pg_ver=$(ls /etc/init.d/postgresql-*); pg_ver=${pg_ver##*-} - ebegin "Configuring PostgreSQL $pg_ver" - emerge --config postgresql &>>$log_dir/postgresql.log + ebegin "Configuring PostgreSQL ${pg_ver}" + emerge --config postgresql &>>${log_dir}/postgresql.log eend ebegin 'Starting PostgreSQL' - rc-service postgresql-$pg_ver start >>$log_dir/postgresql.log + rc-service postgresql-${pg_ver} start >>${log_dir}/postgresql.log eend ebegin 'Database creation' - psql -U postgres -c "ALTER USER postgres WITH PASSWORD '${ini[postgresql.postgres_password]}'" >>$log_dir/postgresql.log + psql -U postgres -c "ALTER USER postgres WITH PASSWORD '${ini[postgresql.postgres_password]}'" >>${log_dir}/postgresql.log 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]}'" >>$log_dir/postgresql.log + psql -U postgres -c "ALTER USER ${ini[postgresql.homeassistant_user]} WITH PASSWORD '${ini[postgresql.homeassistant_password]}'" >>${log_dir}/postgresql.log eend ebegin 'Updating permissions' - cl-core-setup -n postgresql -f >>$log_dir/postgresql.log + cl-core-setup -n postgresql -f >>${log_dir}/postgresql.log eend ebegin 'Restart the server' - rc-service postgresql-$pg_ver restart >>$log_dir/postgresql.log + rc-service postgresql-${pg_ver} restart >>${log_dir}/postgresql.log eend } diff --git a/scripts/homeassistant/step/3-zigbee2mqtt.sh b/scripts/homeassistant/step/3-zigbee2mqtt.sh index 2c58c06..e0ba4c9 100644 --- a/scripts/homeassistant/step/3-zigbee2mqtt.sh +++ b/scripts/homeassistant/step/3-zigbee2mqtt.sh @@ -15,6 +15,7 @@ configure() { local work_dir="$home_dir/versions/zigbee2mqtt-$last_ver" local live_dir="$home_dir/zigbee2mqtt-live" local live_ver="$(get_live_ver $live_dir)" + local conf_dir="/var/calculate/zigbee2mqtt" # проверим на наличие устройства if [[ ${ini[zigbee2mqtt.dev]:-} == "" ]]; then @@ -32,13 +33,18 @@ configure() { fi if [[ ! -e $home_dir ]]; then - mkdir -p $home_dir - chmod 700 $home_dir/versions + mkdir -p $home_dir/versions + chmod 700 $home_dir chown -R zigbee2mqtt: $home_dir fi + if [[ ! -e $conf_dir ]]; then + mkdir -p $conf_dir + chmod 700 $conf_dir + chown -R zigbee2mqtt: $conf_dir + fi - touch $log_dir/zigbee2mqtt.log - chown zigbee2mqtt: $log_dir/zigbee2mqtt.log + touch ${log_dir}/zigbee2mqtt.log + chown zigbee2mqtt: ${log_dir}/zigbee2mqtt.log if [[ $live_ver != $last_ver ]]; then if [[ $live_ver == '' ]]; then @@ -64,11 +70,11 @@ configure() { eend # вынесем настройки - if [[ -z "$(ls -A /var/calculate/zigbee2mqtt)" ]]; then - mv versions/zigbee2mqtt-${last_ver}/data/* /var/calculate/zigbee2mqtt + if [[ -z "$(ls -A $conf_dir)" ]]; then + mv versions/zigbee2mqtt-${last_ver}/data/* ${conf_dir} fi rm -rf versions/zigbee2mqtt-${last_ver}/data - ln -s /var/calculate/zigbee2mqtt versions/zigbee2mqtt-${last_ver}/data + ln -s ${conf_dir} versions/zigbee2mqtt-${last_ver}/data ebegin 'Create a virtualenv' python -m venv zigbee2mqtt-live/.venv @@ -79,20 +85,20 @@ configure() { eend ebegin 'Upgrade pip, wheel and setuptools' - pip install --upgrade pip wheel setuptools &>>$log_dir/zigbee2mqtt.log + pip install --upgrade pip wheel setuptools &>>${log_dir}/zigbee2mqtt.log eend ebegin 'Install Node environment' - pip install nodeenv &>>$log_dir/zigbee2mqtt.log + pip install nodeenv &>>${log_dir}/zigbee2mqtt.log eend ebegin 'Init Node environment ${ini[zigbee2mqtt.nodeenv]}' - nodeenv -p -n ${ini[zigbee2mqtt.nodeenv]} &>>$log_dir/zigbee2mqtt.log + nodeenv -p -n ${ini[zigbee2mqtt.nodeenv]} &>>${log_dir}/zigbee2mqtt.log eend einfo 'Install dependencies' cd zigbee2mqtt-live - npm ci &>>$log_dir/zigbee2mqtt.log + npm ci &>>${log_dir}/zigbee2mqtt.log cd EOF )" @@ -101,8 +107,8 @@ configure() { eval $__result=zigbee2mqtt # демон который следует перезагрузить else ebegin 'Setup zigbee2mqtt' - mv /var/calculate/zigbee2mqtt/configuration.yaml /var/calculate/zigbee2mqtt/configuration.yaml.old - cat > /var/calculate/zigbee2mqtt/configuration.yaml << EOF + mv ${conf_dir}/configuration.yaml ${conf_dir}/configuration.yaml.old + cat > ${conf_dir}/configuration.yaml << EOF # Home Assistant integration (MQTT discovery) homeassistant: true @@ -127,7 +133,7 @@ frontend: port: 8080 host: 127.0.0.1 EOF - chown zigbee2mqtt: /var/calculate/zigbee2mqtt/configuration.yaml + chown zigbee2mqtt: ${conf_dir}/configuration.yaml eend fi fi diff --git a/scripts/homeassistant/step/4-hass-configurator.sh b/scripts/homeassistant/step/4-hass-configurator.sh index ad28fe9..328f182 100644 --- a/scripts/homeassistant/step/4-hass-configurator.sh +++ b/scripts/homeassistant/step/4-hass-configurator.sh @@ -14,6 +14,7 @@ configure() { local work_dir="$home_dir/versions/hass-configurator-$last_ver" local live_dir="$home_dir/hass-configurator-live" local live_ver="$(get_live_ver $live_dir)" + local conf_dir="/var/calculate/hass-configurator" if [[ $action == 'check' ]]; then if [[ $live_ver == $last_ver ]]; then @@ -26,7 +27,7 @@ configure() { fi # выйдем если все настроено - if [[ -e /var/calculate/hass-configurator/settings.conf ]]; then + if [[ -e $conf_dir/settings.conf ]]; then return fi @@ -35,9 +36,14 @@ configure() { chmod 700 $home_dir chown -R hass-configurator: $home_dir fi + if [[ ! -e $conf_dir ]]; then + mkdir -p $conf_dir + chmod 700 $conf_dir + chown -R hass-configurator: $conf_dir + fi - touch $log_dir/hass-configurator.log - chown hass-configurator: $log_dir/hass-configurator.log + touch ${log_dir}/hass-configurator.log + chown hass-configurator: ${log_dir}/hass-configurator.log if [[ $live_ver != $last_ver ]]; then if [[ $live_ver == '' ]]; then @@ -52,7 +58,7 @@ configure() { ebegin Download hass-configurator ${last_ver} wget https://github.com/danielperna84/hass-configurator/archive/refs/tags/${last_ver}.zip \ - -O hass-configurator-${last_ver}.zip &>>$log_dir/hass-configurator.log + -O hass-configurator-${last_ver}.zip &>>${log_dir}/hass-configurator.log eend ebegin 'Extract the archive' @@ -70,11 +76,11 @@ configure() { eend ebegin 'Upgrade pip and wheel' - pip install --upgrade pip wheel &>>$log_dir/hass-configurator.log + pip install --upgrade pip wheel &>>${log_dir}/hass-configurator.log eend ebegin 'Install HASS Configurator' - pip install hass-configurator &>>$log_dir/hass-configurator.log + pip install hass-configurator &>>${log_dir}/hass-configurator.log eend EOF )" @@ -84,7 +90,7 @@ configure() { eval $__result=hass-assistant # демон который следует перезагрузить else ebegin 'Setup HASS Configurator' - cat > /var/calculate/hass-configurator/settings.conf << EOF + cat > $conf_dir/settings.conf << EOF { "LISTENIP": "127.0.0.1", "PORT": 3218, @@ -112,7 +118,7 @@ configure() { "NOTIFY_SERVICE": "persistent_notification.create" } EOF - chown hass-configurator: /var/calculate/hass-configurator/settings.conf + chown hass-configurator: $conf_dir/settings.conf eend fi } diff --git a/scripts/homeassistant/step/5-config.sh b/scripts/homeassistant/step/5-config.sh index 4016195..f9a9abb 100644 --- a/scripts/homeassistant/step/5-config.sh +++ b/scripts/homeassistant/step/5-config.sh @@ -2,29 +2,29 @@ # Функция configure() настраивает Home Assistant # configure() { - # выйдем если все настроено - grep -q ^http: /var/calculate/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" + local live_dir="${home_dir}/homeassistant-live" + local conf_dir="/var/calculate/homeassistant" + + # выйдем если все настроено + grep -q ^http: ${conf_dir}/configuration.yaml &>/dev/null && return || true - if [[ ! -e $config_dir ]]; then - mkdir -p $config_dir - chmod 700 $config_dir - chown homeassistant: $config_dir + if [[ ! -e $conf_dir ]]; then + mkdir -p $conf_dir + chmod 700 $conf_dir + chown homeassistant: $conf_dir fi - touch $log_dir/config.log - chown homeassistant: $log_dir/config.log + touch ${log_dir}/config.log + chown homeassistant: ${log_dir}/config.log su - homeassistant -s /bin/bash -c "$(cat <<- EOF set -ueo pipefail export PATH="/lib/rc/bin:$PATH" - source $live_dir/bin/activate + source ${live_dir}/bin/activate - hass --config /var/calculate/homeassistant &>>$log_dir/config.log & + hass --config ${conf_dir} &>>${log_dir}/config.log & id_hass=\$! echo @@ -38,7 +38,7 @@ configure() { EOF )" - cat >> /var/calculate/homeassistant/configuration.yaml << EOF + cat >> ${conf_dir}/configuration.yaml << EOF http: server_host: 127.0.0.1