homeassistant: обновлены настройки, добавлена поддержка postgresql

master
parent 7858d0b218
commit dcd77c502c

@ -2,8 +2,10 @@
node = 12.22.12
[postgresql]
taiga_user = taiga
homeassistant_database = homeassistant
homeassistant_user = homeassistant
taiga_database = taiga
taiga_user = taiga
[rabbitmq]
taiga_user = taiga

@ -1,2 +1,2 @@
# Calculate path=/etc name=#-cut(1,.)-# append=after protected
homeassistant:x:999:999::/var/calculate/www/homeassistant:/bin/bash
homeassistant:x:999:999:Home Assistant Program User:/var/calculate/www/homeassistant:/sbin/nologin

@ -1,4 +1,4 @@
# Calculate path=/etc/init.d name=#-cut(1,.)-# chmod=755 comment=# exists(/var/calculate/www/homeassistant/.homeassistant)!=
# Calculate path=/etc/init.d name=#-cut(1,.)-# chmod=755 comment=# exists(/etc/homeassistant/configuration.yaml)!=
#!/sbin/openrc-run
# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
@ -12,12 +12,13 @@ serverlog="/var/log/homeassistant/server.log"
warningslog="/var/log/homeassistant/warnings.log"
retry="20"
command=/var/calculate/www/homeassistant/.venv/bin/hass
command=/var/calculate/www/homeassistant/.venv-live/bin/hass
directory=/var/calculate/www/homeassistant
start_stop_daemon_args="--user $user --stdout $stdoutlog --stderr $serverlog --wait 10"
command_args="
--config /etc/homeassistant
--log-file $warningslog
--log-rotate-days 9
${HASS_OPTS}
@ -27,7 +28,7 @@ command_background=yes
pidfile=/run/homeassistant.pid
depend() {
need net nginx
need net nginx postgresql
}
start_pre() {

@ -1 +1 @@
# Calculate path=/etc/runlevels/default name=#-cut(1,.)-# link=/etc/init.d/#-cut(1,.)-# protected symbolic exists(/var/calculate/www/homeassistant/.homeassistant)!=
# Calculate path=/etc/runlevels/default name=#-cut(1,.)-# link=/etc/init.d/#-cut(1,.)-# protected symbolic exists(/etc/homeassistant/configuration.yaml)!=

@ -0,0 +1 @@
# Calculate env=install ac_install_merge==on mergepkg(dev-db/postgresql)!= append=skip

@ -0,0 +1 @@
# Calculate path=/var/calculate name=postgresql chmod=700 chown=postgres:postgres

@ -0,0 +1 @@
# Calculate path=/etc name=postgresql-#-pgver(slot)-#

@ -0,0 +1,10 @@
# Calculate chmod=600 comment=# chown=postgres:postgres
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all password
# IPv4 local connections:
host all all 127.0.0.1/32 password
# IPv6 local connections:
host all all ::1/128 password

@ -0,0 +1,4 @@
# Calculate format=samba path=/var/calculate grep(/var/calculate/ini.env,postgresql)== protected
[postgresql]
postgres_password = #-rnd(pas,12)-#
homeassistant_password = #-rnd(pas,12)-#

@ -0,0 +1 @@
# Calculate path=/var/lib name=postgresql link=/var/calculate/postgresql symbolic protected

@ -0,0 +1,3 @@
# Calculate path=/root name=.pgpass chmod=600 comment=# protected
localhost:*:*:postgres:#-ini(postgresql.postgres_password)-#
localhost:*:*:homeassistant:#-ini(postgresql.homeassistant_password)-#

@ -1,2 +1,4 @@
# Calculate env=update ac_update_sync==on path=/var/lib/portage cl_update_world==merge||cl_update_world==rebuild format=world
app-misc/mosquitto
dev-db/postgresql
www-servers/nginx

@ -0,0 +1 @@
# Calculate env=install ac_install_merge==on mergepkg(www-servers/nginx)!= append=skip

@ -0,0 +1 @@
# Calculate append=skip grep(/etc/passwd,#-cut(1,.)-#)==

@ -0,0 +1,2 @@
# Calculate path=/etc name=#-cut(1,.)-# append=after protected
zigbee2mqtt:x:998:

@ -0,0 +1,2 @@
# Calculate path=/etc name=#-cut(1,.)-# append=after protected
zigbee2mqtt:x:998:998:A user for zigbee2mqtt:/var/calculate/www/zigbee2mqtt:/sbin/nologin

@ -0,0 +1,2 @@
# Calculate path=/etc name=#-cut(1,.)-# append=after protected
zigbee2mqtt:!:19450::::::

@ -0,0 +1 @@
# Calculate chmod=750 chown=zigbee2mqtt:zigbee2mqtt

@ -0,0 +1,12 @@
#!/bin/bash
set -ueo pipefail
arg=${1:-}
ver=$(ls -d /var/db/pkg/dev-db/postgresql-*); ver=${ver##*-}
if [[ "$arg" == slot ]]; then
echo ${ver%%.*}
else
echo ${ver%%-*}
fi

@ -9,16 +9,25 @@ SCRIPT=$(readlink -f $0)
. /var/db/repos/container/scripts/functions.sh
. /var/db/repos/calculate/scripts/ini.sh
if [[ ! -e ~/.venv ]]; then
if [[ ! -e ~/.venv-live ]]; then
einfo 'Create a virtualenv'
cd ~
python -m venv .venv
echo 'source ~/.venv/bin/activate' >> ~/.bashrc
source .venv/bin/activate
python -m venv ~/.venv-live
echo '. ~/.venv-live/bin/activate' >> ~/.bashrc
echo '. ~/.venv-live/bin/activate' >> ~/.bash_profile
. ~/.venv-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 ~/.venv-live ~/.venv-${ha_ver}
ln -s ~/.venv-${ha_ver} ~/.venv-live
fi

@ -0,0 +1,25 @@
#!/bin/bash
set -ueo pipefail
[[ -n "$(ls -A /var/lib/postgresql)" ]] && exit
export PATH="/lib/rc/bin:$PATH"
. /var/db/repos/container/scripts/functions.sh
. /var/db/repos/calculate/scripts/ini.sh
emerge --config postgresql
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

@ -0,0 +1,41 @@
#!/bin/bash
set -ueo pipefail
export PATH="/lib/rc/bin:$PATH"
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
if [[ ! -e ~/.venv-live ]]; then
einfo 'Clone Zigbee2MQTT repository'
git clone --depth 1 https://github.com/Koenkk/zigbee2mqtt.git ~/
chown -R zigbee2mqtt: ~/
einfo 'Create a virtualenv'
python -m venv ~/.venv-live
echo '. ~/.venv-live/bin/activate' >> ~/.bashrc
echo '. ~/.venv-live/bin/activate' >> ~/.bash_profile
. ~/.venv-live/bin/activate
einfo 'Install node environment'
python -m pip nodeenv
einfo 'Init node environment'
nodeenv -p -n 16.15.0
einfo 'Deactivate and activate environment to be sure'
deactivate
. ~/.venv-live/bin/activate
einfo 'Install dependencies'
cd
npm ci
# ha_ver=$(pip list | grep ^zigbee2mqtt | awk '{print $2}')
# mv ~/.venv-live ~/.venv-${ha_ver}
# ln -s ~/.venv-${ha_ver} ~/.venv-live
fi

@ -5,12 +5,12 @@ export PATH="/lib/rc/bin:$PATH"
SCRIPT=$(readlink -f $0)
[[ $UID == 0 ]] && exec su - homeassistant -c "$SCRIPT"
source .venv/bin/activate
source .venv-live/bin/activate
. /var/db/repos/container/scripts/functions.sh
. /var/db/repos/calculate/scripts/ini.sh
hass >/dev/null &
hass --config /etc/homeassistant >/dev/null &
id_hass=$!
echo; einfon "Check for the first start Home Assistant "
@ -20,12 +20,15 @@ while ! curl http://127.0.0.1:8123 2>/dev/null; do
done
kill $id_hass
cat >> ~/.homeassistant/configuration.yaml <<EOF
cat >> /etc/homeassistant/configuration.yaml <<EOF
http:
server_host: 127.0.0.1
use_x_forwarded_for: true
trusted_proxies: 127.0.0.1
recorder:
db_url: postgresql://${ini[postgresql.homeassistant_user]}:${ini[postgresql.homeassistant_password]}@127.0.0.1/${ini[postgresql.homeassistant_database]}
EOF
echo
Loading…
Cancel
Save