Skip to content

Commit

Permalink
v6.27
Browse files Browse the repository at this point in the history
+ 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: home-assistant/core#28361 (comment)
+ DietPi-Software | Home Assistant: Install aiohttp_cors manually as well due to similar error faced with Python 3.8.0 outside of virtualenv
  • Loading branch information
MichaIng authored Nov 15, 2019
1 parent 84f6888 commit d0056d2
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
#------------------
Expand Down Expand Up @@ -6550,50 +6550,48 @@ 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"

# Install needed libraries
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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d0056d2

Please sign in to comment.