homeassistant: исправлено обновление

master 98
parent 876ea5eee7
commit 524202c5b8

@ -1,14 +0,0 @@
# Calculate format=samba path=/var/calculate grep(/var/calculate/ini.env,\[zigbee2mqtt\])== protected
[zigbee2mqtt]
#?exists(/dev/ttyUSB0)!=#
dev = /dev/ttyUSB0
#exists#
#?exists(/dev/ttyUSB1)!=#
dev = /dev/ttyUSB1
#exists#
#?exists(/dev/ttyACM0)!=#
dev = /dev/ttyACM0
#exists#
#?exists(/dev/ttyACM1)!=#
dev = /dev/ttyACM1
#exists#

@ -5,27 +5,33 @@ export PATH="/lib/rc/bin:$PATH"
source /var/db/repos/calculate/scripts/ini.sh
source /var/db/repos/container/scripts/functions.sh
action=${1:-}
script_path=$(dirname $(readlink -f $0))
log_dir=/var/log/calculate/cl-setup
rm -rf $log_dir
mkdir -p $log_dir
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
# Установка/настройка и проверка обновлений
configurate() {
local check=${1:-}
for i in ${daemon_restart[@]}; do
rc-service -s $i stop
done
for step in $script_path/step/*.sh; do
source "$step"
if [[ $check ]]; then
configure check result
else
configure
fi
done
if [[ $check ]]; then
return ${result:-}
fi
}
if [[ ! -e /etc/runlevels/default/homeassistant ]]; then
if [[ ! -e /var/calculate/homeassistant ]]; then
configurate
echo 'Launch preparation'
ebegin 'Final setup'
@ -36,8 +42,22 @@ if [[ ! -e /etc/runlevels/default/homeassistant ]]; then
ebegin 'Starting services'
openrc >>$log_dir/setup.log
eend
echo "All is done! Open the link \
${ini[homeassistant.protocol]}://${ini[homeassistant.domain]} \
on your browser."
else
openrc
configurate check && {
echo 'No updates available.'
} || {
echo
while true; do
read -p "Do you wish to install this update (y/n)? " answer
case $answer in
[Yy]* ) configurate; exit ;;
[Nn]* ) exit ;;
* ) echo "Please answer yes or no." ;;
esac
done
}
fi
echo "All is done! Open the link ${ini[homeassistant.protocol]}://${ini[homeassistant.domain]} on your browser."

@ -5,8 +5,8 @@
# $1 = check - проверка обновлений, в противном случае установка или обновление
# $2 - возвращает имя модуля для перезагрузки в случае выполненного обновления
configure() {
local action=$1
local __result=$2
local action=${1:-}
local __result=${2:-}
local home_dir=/var/calculate/www/homeassistant
local last_ver="$(get_last_ver homeassistant pip)"
@ -15,9 +15,7 @@ configure() {
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
if [[ $live_ver != $last_ver ]]; then
einfo "homeassistant: $last_ver update available, $live_ver installed"
eval $__result=1 # наличие обновления
fi
@ -45,7 +43,7 @@ configure() {
export PATH="/lib/rc/bin:$PATH"
ebegin 'Create a virtualenv'
test -e $work_dir && rm -rf $work_dir
test -e ${work_dir} && rm -rf ${work_dir}
python -m venv $work_dir
source $work_dir/bin/activate
eend
@ -54,21 +52,21 @@ configure() {
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
ebegin "Install Home Assistant ${last_ver}"
pip install homeassistant==${last_ver} &>>${log_dir}/homeassistant.log
eend
ebegin 'Install PostgreSQL dependencies'
pip install psycopg2 &>>${log_dir}/homeassistant.log
eend
rm -f $live_dir
ln -s $work_dir $live_dir
ln -snf versions/homeassistant-$last_ver $live_dir
EOF
)"
if [[ $live_ver != '' ]]; then
eval $__result=homeassistant # демон который следует перезагрузить
rc-service -s homeassistant restart
echo
fi
fi
}

@ -7,8 +7,8 @@
#
# Guide: https://www.zigbee2mqtt.io/guide/installation/07_python_virtual_environment.html
configure() {
local action=$1
local __result=$2
local action=${1:-}
local __result=${2:-}
local home_dir=/var/calculate/www/zigbee2mqtt
local last_ver="$(get_last_ver Koenkk/zigbee2mqtt github)"
@ -17,21 +17,25 @@ configure() {
local live_ver="$(get_live_ver $live_dir)"
local conf_dir="/var/calculate/zigbee2mqtt"
# проверим на наличие устройства
if [[ ${ini[zigbee2mqtt.dev]:-} == "" ]]; then
return
fi
if [[ $action == 'check' ]]; then
if [[ $live_ver == $last_ver ]]; then
einfo "zigbee2mqtt: the latest version is installed $live_ver"
else
if [[ $live_ver != $last_ver ]]; then
einfo "zigbee2mqtt: $last_ver update available, $live_ver installed"
eval $__result=1 # наличие обновления
fi
return
fi
# проверим на наличие устройства если сервис еще не настроен
if [[ ! -e $conf_dir ]]; then
if [[ -e /dev/ttyUSB0 ]]; then
local file_dev=/dev/ttyUSB0
elif [[ -e /dev/ttyACM0 ]]; then
local file_dev=/dev/ttyACM0
else
return
fi
fi
if [[ ! -e $home_dir ]]; then
mkdir -p $home_dir/versions
chmod 700 $home_dir
@ -58,7 +62,7 @@ configure() {
export PATH="/lib/rc/bin:$PATH"
ebegin Download zigbee2mqtt ${last_ver}
test -e $work_dir && rm -rf $work_dir
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
@ -66,7 +70,6 @@ configure() {
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
# вынесем настройки
@ -77,11 +80,11 @@ configure() {
ln -s ${conf_dir} versions/zigbee2mqtt-${last_ver}/data
ebegin 'Create a virtualenv'
python -m venv zigbee2mqtt-live/.venv
python -m venv ${work_dir}/.venv
eend
ebegin 'Activate environment'
source zigbee2mqtt-live/.venv/bin/activate
source ${work_dir}/.venv/bin/activate
eend
ebegin 'Upgrade pip, wheel and setuptools'
@ -100,11 +103,14 @@ configure() {
cd zigbee2mqtt-live
npm ci &>>${log_dir}/zigbee2mqtt.log
cd
ln -snf versions/zigbee2mqtt-${last_ver} $live_dir
EOF
)"
if [[ $live_ver != '' ]]; then
eval $__result=zigbee2mqtt # демон который следует перезагрузить
rc-service -s zigbee2mqtt restart
echo
else
ebegin 'Setup zigbee2mqtt'
mv ${conf_dir}/configuration.yaml ${conf_dir}/configuration.yaml.old
@ -128,7 +134,7 @@ mqtt:
# Serial settings
serial:
# Location of USB sniffer
port: ${ini[zigbee2mqtt.dev]}
port: ${file_dev}
frontend:
port: 8080
host: 127.0.0.1

@ -6,8 +6,8 @@
# $2 - возвращает имя модуля для перезагрузки в случае выполненного обновления
# Guide: https://github.com/danielperna84/hass-configurator
configure() {
local action=$1
local __result=$2
local action=${1:-}
local __result=${2:-}
local home_dir=/var/calculate/www/hass-configurator
local last_ver="$(get_last_ver danielperna84/hass-configurator github)"
@ -17,20 +17,13 @@ configure() {
local conf_dir="/var/calculate/hass-configurator"
if [[ $action == 'check' ]]; then
if [[ $live_ver == $last_ver ]]; then
einfo "hass-configurator: the latest version is installed $live_ver"
else
if [[ $live_ver != $last_ver ]]; then
einfo "hass-configurator: $last_ver update available, $live_ver installed"
eval $__result=1 # наличие обновления
fi
return
fi
# выйдем если все настроено
if [[ -e $conf_dir/settings.conf ]]; then
return
fi
if [[ ! -e $home_dir ]]; then
mkdir -p $home_dir/versions
chmod 700 $home_dir
@ -57,6 +50,7 @@ configure() {
export PATH="/lib/rc/bin:$PATH"
ebegin Download hass-configurator ${last_ver}
test -e ${work_dir} && rm -rf ${work_dir} # удалим если было прервано
wget https://github.com/danielperna84/hass-configurator/archive/refs/tags/${last_ver}.zip \
-O hass-configurator-${last_ver}.zip &>>${log_dir}/hass-configurator.log
eend
@ -64,15 +58,14 @@ configure() {
ebegin 'Extract the archive'
unzip -q -d versions hass-configurator-${last_ver}.zip
rm hass-configurator-${last_ver}.zip
ln -sf versions/hass-configurator-${last_ver} hass-configurator-live
eend
ebegin 'Create a virtualenv'
python -m venv hass-configurator-live/.venv
python -m venv ${work_dir}/.venv
eend
ebegin 'Activate environment'
source hass-configurator-live/.venv/bin/activate
source ${work_dir}/.venv/bin/activate
eend
ebegin 'Upgrade pip and wheel'
@ -82,15 +75,17 @@ configure() {
ebegin 'Install HASS Configurator'
pip install hass-configurator &>>${log_dir}/hass-configurator.log
eend
ln -snf versions/hass-configurator-${last_ver} $live_dir
EOF
)"
fi
if [[ $live_ver != '' ]]; then
eval $__result=hass-assistant # демон который следует перезагрузить
else
ebegin 'Setup HASS Configurator'
cat > $conf_dir/settings.conf << EOF
if [[ $live_ver != '' ]]; then
rc-service -s hass-configurator restart
echo
else
ebegin 'Setup HASS Configurator'
cat > $conf_dir/settings.conf << EOF
{
"LISTENIP": "127.0.0.1",
"PORT": 3218,
@ -118,8 +113,10 @@ configure() {
"NOTIFY_SERVICE": "persistent_notification.create"
}
EOF
chown hass-configurator: $conf_dir/settings.conf
eend
chown hass-configurator: $conf_dir/settings.conf
eend
fi
fi
}

Loading…
Cancel
Save