diff --git a/profiles/homeassistant/amd64/20/parent b/profiles/homeassistant/amd64/20/parent new file mode 100644 index 0000000..044d048 --- /dev/null +++ b/profiles/homeassistant/amd64/20/parent @@ -0,0 +1,2 @@ +calculate:default/amd64/20/server +../.. diff --git a/profiles/homeassistant/amd64/parent b/profiles/homeassistant/amd64/parent new file mode 100644 index 0000000..638d06a --- /dev/null +++ b/profiles/homeassistant/amd64/parent @@ -0,0 +1,2 @@ +../../../../calculate/profiles/default/amd64/18/server +.. diff --git a/profiles/homeassistant/calculate.env b/profiles/homeassistant/calculate.env new file mode 100644 index 0000000..de39a9d --- /dev/null +++ b/profiles/homeassistant/calculate.env @@ -0,0 +1,3 @@ +[main] +os_linux_name = 'Calculate Home Assistant' +os_linux_shortname = 'homeassistant' diff --git a/profiles/homeassistant/parent b/profiles/homeassistant/parent new file mode 100644 index 0000000..f3229c5 --- /dev/null +++ b/profiles/homeassistant/parent @@ -0,0 +1 @@ +.. diff --git a/profiles/profiles.desc b/profiles/profiles.desc index 57a91c7..9785f44 100644 --- a/profiles/profiles.desc +++ b/profiles/profiles.desc @@ -7,8 +7,8 @@ #arch profile_directory status # AMD64 Profiles +amd64 homeassistant/amd64/20 dev amd64 scratch/amd64/20 stable -amd64 mastodon/amd64/20 dev amd64 taiga/amd64/20 dev # vim: set ts=8 diff --git a/scripts/homeassistant/setup.sh b/scripts/homeassistant/setup.sh new file mode 100755 index 0000000..2c4c1f8 --- /dev/null +++ b/scripts/homeassistant/setup.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Install Home Assistant + +set -ueo pipefail +export PATH="/lib/rc/bin:$PATH" +scriptpath=$(dirname $(readlink -f $0)) + +. /var/db/repos/calculate/scripts/ini.sh + +echo "Home Assistant setup" +chown homeassistant: /var/calculate/ini.env + +for script in $scriptpath/step/*.sh; do + "$script" +done + +if [[ ! -e /etc/runlevels/default/homeassistant ]]; then + cl-setup-system + rc-update -u +fi +openrc + +echo -e "\nAll 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 new file mode 100755 index 0000000..b270b1f --- /dev/null +++ b/scripts/homeassistant/step/1-install.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -ueo pipefail +export PATH="/lib/rc/bin:$PATH" + +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 + +if [[ ! -e ~/.venv ]]; then + einfo 'Create a virtualenv' + cd ~ + python -m venv .venv + source .venv/bin/activate + + echo + einfo 'Install Python dependencies' + python -m pip install wheel + + echo + einfo 'Install Home Assistant' + pip install homeassistant + + eend +fi + diff --git a/scripts/homeassistant/step/2-postgresql.sh b/scripts/homeassistant/step/2-postgresql.sh new file mode 100755 index 0000000..43f1610 --- /dev/null +++ b/scripts/homeassistant/step/2-postgresql.sh @@ -0,0 +1,33 @@ +#!/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 + +pgver() { + local ver=$(ls -d /var/db/pkg/dev-db/postgresql-*) + ver=${ver#*postgresql-} + if [[ ${1:-} == 'slot' ]]; then + echo ${ver%%.*} + else + echo ${ver%%-*} + fi +} + +emerge --config =dev-db/postgresql-$(pgver) + +/etc/init.d/postgresql-$(pgver slot) start + +psql -U postgres -c "ALTER USER postgres WITH PASSWORD '${ini[postgresql.postgres_password]}'" +psql -U postgres -c "CREATE ROLE ${ini[postgresql.homeassistant_user]} WITH login" +psql -U postgres -c "CREATE DATABASE homeassistant OWNER homeassistant" +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-$(pgver slot) restart diff --git a/scripts/homeassistant/step/3-config.sh b/scripts/homeassistant/step/3-config.sh new file mode 100755 index 0000000..cb44b40 --- /dev/null +++ b/scripts/homeassistant/step/3-config.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -ueo pipefail +export PATH="/lib/rc/bin:$PATH" + +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 ~ +timeout 5 /var/calculate/www/homeassistant/.venv/bin/hass || true + +if ! grep -q http .homeassistant/configuration.yaml; then + cat >> .homeassistant/configuration.yaml << EOF +http: + use_x_forwarded_for: true + trusted_proxies: 127.0.0.1 +EOF +fi