From 2de0e6868274c8a3fe81d371cbbe3aad630cab70 Mon Sep 17 00:00:00 2001 From: Alexander Tratsevskiy Date: Tue, 2 May 2023 18:19:44 +0300 Subject: [PATCH] =?UTF-8?q?homeassistant:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - исправлено обновление когда не настроен zigbee2mqtt - добавлена проверка открытого порта postgresql --- scripts/functions.sh | 25 ++++++++++++++++--- scripts/homeassistant/setup.sh | 6 +++++ scripts/homeassistant/step/1-install.sh | 2 +- scripts/homeassistant/step/3-zigbee2mqtt.sh | 2 +- .../homeassistant/step/4-hass-configurator.sh | 2 +- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 48b6bc2..acdd779 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -1,5 +1,5 @@ # Clear stdin before reading -clear_buf(){ +clear_buf() { while read -r -t 0 do read -r done @@ -7,7 +7,7 @@ clear_buf(){ } # Convert ini.env array to Python list -arr_to_list(){ +arr_to_list() { if [[ $# == 0 || -z $1 ]] then echo "[]" @@ -28,7 +28,7 @@ arr_to_list(){ echo $list } -get_last_ver(){ +get_last_ver() { local project=$1 local hosting=$2 case $hosting in @@ -41,10 +41,27 @@ get_last_ver(){ esac } -get_live_ver(){ +get_live_ver() { if [[ ! -e $1 ]]; then exit fi local current_ver=$(readlink -f $1) echo ${current_ver##*-} } + +check_open_port() { + local check_port=$1 + if which ss &>/dev/null; then + if ss -ltn | grep -q "^LISTEN.*:${check_port}\s"; then + return 0 + else + return 1 + fi + elif which netstat &>/dev/null; then + if netstat -nlt | grep -qE "${check_port}\s+[^\s]+\s+LISTEN"; then + return 0 + else + return 1 + fi + fi +} diff --git a/scripts/homeassistant/setup.sh b/scripts/homeassistant/setup.sh index b9f8f6a..7b2f757 100755 --- a/scripts/homeassistant/setup.sh +++ b/scripts/homeassistant/setup.sh @@ -17,6 +17,7 @@ log_dir=/var/log/calculate/cl-setup rm -rf $log_dir mkdir -p $log_dir +# Выполним проверки if [[ $first_start && ! -e /dev/ttyUSB0 && ! -e /dev/ttyACM0 ]]; then while true; do read -p "Zigbee2MQTT device is not found, the configuration will be done without Zigbee to MQTT bridge (y/n)? " answer @@ -26,6 +27,11 @@ if [[ $first_start && ! -e /dev/ttyUSB0 && ! -e /dev/ttyACM0 ]]; then * ) echo "Please answer yes or no." ;; esac done + + if check_open_port 5432; then + echo Error: PostgreSQL port is busy. + exit 1 + fi fi # Установка/настройка и проверка обновлений diff --git a/scripts/homeassistant/step/1-install.sh b/scripts/homeassistant/step/1-install.sh index 3482279..ca1a468 100644 --- a/scripts/homeassistant/step/1-install.sh +++ b/scripts/homeassistant/step/1-install.sh @@ -17,7 +17,7 @@ configure() { # отобразим наличие обновления и выйдем if [[ $action == 'check' ]]; then - if [[ $live_ver != $last_ver ]]; then + if [[ $live_ver && $live_ver != $last_ver ]]; then einfo "homeassistant: $last_ver update available, $live_ver installed" eval $__result=1 fi diff --git a/scripts/homeassistant/step/3-zigbee2mqtt.sh b/scripts/homeassistant/step/3-zigbee2mqtt.sh index d1c10e7..ddb7b24 100644 --- a/scripts/homeassistant/step/3-zigbee2mqtt.sh +++ b/scripts/homeassistant/step/3-zigbee2mqtt.sh @@ -19,7 +19,7 @@ configure() { # отобразим наличие обновления и выйдем if [[ $action == 'check' ]]; then - if [[ $live_ver != $last_ver ]]; then + if [[ $live_ver && $live_ver != $last_ver ]]; then einfo "zigbee2mqtt: $last_ver update available, $live_ver installed" eval $__result=1 fi diff --git a/scripts/homeassistant/step/4-hass-configurator.sh b/scripts/homeassistant/step/4-hass-configurator.sh index 4fd4adf..e4c95ed 100644 --- a/scripts/homeassistant/step/4-hass-configurator.sh +++ b/scripts/homeassistant/step/4-hass-configurator.sh @@ -18,7 +18,7 @@ configure() { # отобразим наличие обновления и выйдем if [[ $action == 'check' ]]; then - if [[ $live_ver != $last_ver ]]; then + if [[ $live_ver && $live_ver != $last_ver ]]; then einfo "hass-configurator: $last_ver update available, $live_ver installed" eval $__result=1 fi