Files
lxc-scripts/hasscore
ich777 23d69d7238 hasscore aktualisiert
- removed root passwd
- update for Debian 12
- minor fixes
- add optional step for openssh-server
2023-08-02 13:05:01 +02:00

76 lines
2.5 KiB
Bash

#!/bin/bash
#Update and upgrade base packages
apt-get update
apt-get -y upgrade
#Add user "homeassistant"
useradd -rm homeassistant -s /bin/bash
#Set password for user "homeassistant"
echo "+---------------------------------------+"
echo "| Set password for user 'homeassistant' |"
echo "+---------------------------------------+"
passwd homeassistant
#Install Homeassistant Core
apt-get -y install curl wget nano iputils-ping python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff6 libturbojpeg0-dev tzdata cron
mkdir -p /opt/homeassistant
chown homeassistant:homeassistant /opt/homeassistant
su homeassistant -s /bin/bash -c 'cd /opt/homeassistant; \
python3 -m venv .; \
source bin/activate; \
python3 -m pip install wheel; \
pip3 install homeassistant; \
echo; \
echo "+-----------------------------------------------------"; \
echo "| Please connect to HA through IP:8123"; \
echo "|"; \
echo "| Please note that this is the fist startup and"; \
echo "| it can take a while for the site to be reachable!"; \
echo "|"; \
echo "| Complete the installation wizzard from HomeAssistant"; \
echo "| and then press in this window CTRL + C to complete"; \
echo "| the installation."; \
echo "+-----------------------------------------------------"; \
hass 2>/dev/null'
#Create systemd service
echo "[Unit]
Description=Home Assistant
After=network-online.target
[Service]
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant
ExecStart=/opt/homeassistant/bin/hass -c "/home/%i/.homeassistant"
RestartForceExitStatus=100
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/homeassistant@homeassistant.service
#Create Update script
echo "systemctl stop homeassistant@homeassistant
su homeassistant -c 'source /opt/homeassistant/bin/activate
pip3 install --upgrade homeassistant
exit'
systemctl start homeassistant@homeassistant" > /home/homeassistant/update-ha.sh
chmod 777 /home/homeassistant/update-ha.sh
chown homeassistant:homeassistant /home/homeassistant/update-ha.sh
#Create cron job
crontab -l > /root/cron
echo "0 3 * * 0 /home/homeassistant/update-ha.sh" >> /root/cron
crontab /root/cron
rm /root/cron
#Update, enable and start services
systemctl --system daemon-reload
systemctl enable homeassistant@homeassistant
systemctl start homeassistant@homeassistant
echo "Installation complete, your Hass Core installation is now available at: IP:8123"
#Optional OpenSSH Server
#apt-get -y install openssh-server