From d0056d271a3ce0eec964153b08e981ade00802b8 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Sat, 16 Nov 2019 00:37:13 +0100 Subject: [PATCH] v6.27 + DietPi-Software | Home Assistant: Skip pyenv virtualenv. pyenv itself is installed locally for the "homeassistant" user already, hence another virtualenv is overkill. This simplifies install and pyenv activation and reduces disk usage overhead. + DietPi-Software | Home Assistant: Add workaround to install home-assistant-frontend prior to first HA start: https://github.com/home-assistant/home-assistant/issues/28361#issuecomment-550070511 + DietPi-Software | Home Assistant: Install aiohttp_cors manually as well due to similar error faced with Python 3.8.0 outside of virtualenv --- dietpi/dietpi-software | 64 ++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/dietpi/dietpi-software b/dietpi/dietpi-software index 61c01f81d8..91d9dc0d7f 100644 --- a/dietpi/dietpi-software +++ b/dietpi/dietpi-software @@ -1828,7 +1828,7 @@ DietPi-Software will decrypt and use it for software installs. You can change it aSOFTWARE_TYPE[$software_id]=0 aSOFTWARE_CATEGORY_INDEX[$software_id]=18 aSOFTWARE_ONLINEDOC_URL[$software_id]='p=70#p70' - aSOFTWARE_REQUIRES_GIT[$software_id]=1 + aSOFTWARE_REQUIRES_GIT[$software_id]=1 # for Pyenv installer aSOFTWARE_REQUIRES_BUILDESSENTIAL[$software_id]=1 aSOFTWARE_REQUIRES_SQLITE[$software_id]=1 aSOFTWARE_REQUIRES_FFMPEG[$software_id]=1 @@ -1849,8 +1849,8 @@ DietPi-Software will decrypt and use it for software installs. You can change it aSOFTWARE_NAME[$software_id]='CloudPrint' aSOFTWARE_DESC[$software_id]='print server for google cloud print' - aSOFTWARE_CATEGORY_INDEX[$software_id]=19 aSOFTWARE_TYPE[$software_id]=0 + aSOFTWARE_CATEGORY_INDEX[$software_id]=19 aSOFTWARE_ONLINEDOC_URL[$software_id]='p=6630#p6630' aSOFTWARE_REQUIRES_RSYSLOG[$software_id]=1 # Not required, but comes in as package dep #------------------ @@ -6550,13 +6550,11 @@ Mycroft AI requires at least 2 GiB memory on first start. We will now increase y local ha_user='homeassistant' local ha_userroot="/home/$ha_user" - local ha_srvroot='/srv/homeassistant' - local ha_pyenv_activation="export PATH=\"$ha_userroot/.pyenv/bin:\$PATH\"; eval \"\$(pyenv init -)\"; eval \"\$(pyenv virtualenv-init -)\"" - local ha_python_version='3.7.5' + local ha_pyenv_activation="export PATH=\"$ha_userroot/.pyenv/bin:\$PATH\"; eval \"\$(pyenv init -)\"" + local ha_python_version='3.8.0' G_DIETPI-NOTIFY 2 "ha_user: $ha_user" G_DIETPI-NOTIFY 2 "ha_userroot: $ha_userroot" - G_DIETPI-NOTIFY 2 "ha_srvroot: $ha_srvroot" G_DIETPI-NOTIFY 2 "ha_pyenv_activation: $ha_pyenv_activation" G_DIETPI-NOTIFY 2 "ha_python_version: $ha_python_version" @@ -6564,36 +6562,36 @@ Mycroft AI requires at least 2 GiB memory on first start. We will now increase y G_AGI cmake daemon gcc nmap net-tools swig uuid-dev libc-ares-dev libgnutls28-dev libgnutlsxx28 libglib2.0-dev libudev-dev libusb-1.0-0 libssl-dev libffi-dev libbz2-dev zlib1g-dev libreadline-dev libsqlite3-dev libncurses5-dev libncursesw5-dev libmariadbclient-dev # Setup the user account information - local usercmd='useradd -rmU' + local usercmd='useradd -rMU' getent passwd $ha_user &> /dev/null && usercmd='usermod -a' $usercmd -G dietpi,dialout -d $ha_userroot -s $(command -v nologin) $ha_user - mkdir -p $ha_srvroot - chown $ha_user:$ha_user $ha_srvroot + # Start with fresh instance, to allow clean pyenv and Python updates and fix broken instances. All userdata and configs are preserved in: /mnt/dietpi_userdata/homeassistant + [[ -d $ha_userroot/.pyenv ]] && rm -R $ha_userroot/.pyenv - # Install pyenv - su -s /bin/dash -c "cd $ha_userroot; curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash" $ha_user + # Create home dir + mkdir -p $ha_userroot + chown $ha_user:$ha_user $ha_userroot - # Install Python which is needed for HA. - su -s /bin/dash -c "cd $ha_userroot; $ha_pyenv_activation; pyenv install $ha_python_version" $ha_user - - # Make the virtual environment. - su -s /bin/dash -c "cd $ha_srvroot; $ha_pyenv_activation; pyenv virtualenv $ha_python_version homeassistant-$ha_python_version" $ha_user - su -s /bin/dash -c "cd $ha_srvroot; $ha_pyenv_activation; pyenv local homeassistant-$ha_python_version" $ha_user - su -s /bin/dash -c "cd $ha_srvroot; $ha_pyenv_activation; pyenv local" $ha_user - - # Install Home Assistant and extra modules. - su -s /bin/dash -c "cd $ha_srvroot; $ha_pyenv_activation; pyenv activate homeassistant-$ha_python_version; pip3 install colorlog PyMySQL mysqlclient" $ha_user - su -s /bin/dash -c "cd $ha_srvroot; $ha_pyenv_activation; pyenv activate homeassistant-$ha_python_version; pip3 install -U homeassistant" $ha_user + # Install pyenv > Python > dependencies > Home Assistant + # - Workaround: Install home-assistant-frontend: https://github.com/home-assistant/home-assistant/issues/28361#issuecomment-550070511 + # - Workaround: Install aiohttp_cors for a similar error + sudo -u $ha_user dash -c " +cd $ha_userroot +curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash +$ha_pyenv_activation +pyenv install $ha_python_version +pyenv local $ha_python_version +pip3 install -U pip +pip3 install -U aiohttp_cors colorlog PyMySQL mysqlclient homeassistant home-assistant-frontend" - # Generate the scripts to launch HA using pyenv. + # Generate the script to launch HA using pyenv echo "#!/bin/dash -cd $ha_srvroot +cd $ha_userroot $ha_pyenv_activation -pyenv activate homeassistant-$ha_python_version -hass -c '$ha_userroot/.homeassistant'" > $ha_srvroot/homeassistant-start.sh - #su -s /bin/dash -c "$ha_srvroot/homeassistant-start.sh" $ha_user - chmod +x $ha_srvroot/homeassistant-start.sh +hass -c '$ha_userroot/.homeassistant'" > $ha_userroot/homeassistant-start.sh + chmod +x $ha_userroot/homeassistant-start.sh + #sudo -u $ha_user $ha_userroot/homeassistant-start.sh fi @@ -13932,20 +13930,20 @@ _EOF_ Banner_Uninstalling #apt-mark auto cmake daemon gcc nmap net-tools swig uuid-dev libc-ares-dev libgnutls28-dev libgnutlsxx28 libglib2.0-dev libudev-dev libusb-1.0-0 libssl-dev libffi-dev libbz2-dev zlib1g-dev libreadline-dev libsqlite3-dev libncurses5-dev libncursesw5-dev - # Remove the service. + # Remove the service if [[ -f '/etc/systemd/system/home-assistant.service' ]]; then systemctl disable --now home-assistant - rm /etc/systemd/system/home-assistant.service + rm -R /etc/systemd/system/home-assistant.service* fi - # Remove the user and all files. This removed pyenv for this user as well. + # Remove the user and all files which removes his home + pyenv incl. HA as well getent passwd homeassistant &> /dev/null && userdel -rf homeassistant getent group homeassistant &> /dev/null && groupdel homeassistant - # Remove installation of HA. - [[ -d '/srv/homeassistant' ]] && rm -R /srv/homeassistant + G_DIETPI-NOTIFY 2 'Home Assistant data and settings are not removed: /mnt/dietpi_userdata/homeassistant + - You might want to do this manually: rm -R /mnt/dietpi_userdata/homeassistant' fi