Skip to content

Commit

Permalink
v6.27
Browse files Browse the repository at this point in the history
+ DietPi-Software | Home Assistant: Install latest Python version, as Python 3.6 will be deprecated in future versions: #3219
+ DietPi-Software | Home Assistant: Run su and the start script in dash to slightly reduce memory usage and shell init times
+ DietPi-Software | Home Assistant: Failsafe: In case the userdata location does not yet exist, but the users home dir config does, move data/configs to userdata location to assure nothing is lost
+ DietPi-Software | Home Assistant: Minor coding/syntax enhancements/alignment
+ DietPi-Software | Home Assistant: Inform user about possibly long install times, when selecting HA from dietpi-software menu.
  • Loading branch information
MichaIng authored Nov 6, 2019
1 parent a2e94a9 commit 569d162
Showing 1 changed file with 51 additions and 29 deletions.
80 changes: 51 additions & 29 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -6561,7 +6561,7 @@ Mycroft AI requires at least 2 GiB memory on first start. We will now increase y
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.6.3"
local ha_python_version="3.7.5"

G_DIETPI-NOTIFY 2 "ha_user: $ha_user"
G_DIETPI-NOTIFY 2 "ha_userroot: $ha_userroot"
Expand All @@ -6573,36 +6573,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
adduser --system $ha_user
addgroup $ha_user
# This allows the dietpi user to edit the files along with HA.
usermod -G dietpi,dialout -a $ha_user
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 $ha_srvroot
chown $ha_user:$ha_user $ha_srvroot

# Install pyenv
su --shell /bin/bash --command "cd $ha_userroot; curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash" $ha_user
su -s /bin/dash -c "cd $ha_userroot; curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash" $ha_user

# Install Python which is needed for HA.
su --shell /bin/bash --command "cd $ha_userroot; $ha_pyenv_activation; pyenv install $ha_python_version" $ha_user
su -s /bin/dash -c "cd $ha_userroot; $ha_pyenv_activation; pyenv install $ha_python_version" $ha_user

# Make the virtual environment.
su --shell /bin/bash --command "cd $ha_srvroot; $ha_pyenv_activation; pyenv virtualenv $ha_python_version homeassistant-$ha_python_version" $ha_user
su --shell /bin/bash --command "cd $ha_srvroot; $ha_pyenv_activation; pyenv local homeassistant-$ha_python_version" $ha_user
su --shell /bin/bash --command "cd $ha_srvroot; $ha_pyenv_activation; pyenv local" $ha_user
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 --shell /bin/bash --command "cd $ha_srvroot; $ha_pyenv_activation; pyenv activate homeassistant-$ha_python_version; pip3 install colorlog PyMySQL mysqlclient" $ha_user
su --shell /bin/bash --command "cd $ha_srvroot; $ha_pyenv_activation; pyenv activate homeassistant-$ha_python_version; pip3 install --upgrade homeassistant" $ha_user
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 --upgrade homeassistant" $ha_user

# Generate the scripts to launch HA using pyenv.
echo '#!/bin/bash' > $ha_srvroot/homeassistant-start.sh
echo "cd $ha_srvroot" >> $ha_srvroot/homeassistant-start.sh
echo "$ha_pyenv_activation" >> $ha_srvroot/homeassistant-start.sh
echo "pyenv activate homeassistant-$ha_python_version" >> $ha_srvroot/homeassistant-start.sh
echo "hass -c \"$ha_userroot/.homeassistant\"" >> $ha_srvroot/homeassistant-start.sh
#su --shell /bin/bash --command "/srv/homeassistant/homeassistant-start.sh" homeassistant
chmod +x /srv/homeassistant/homeassistant-start.sh
echo "#!/bin/dash
cd $ha_srvroot
$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

fi

Expand Down Expand Up @@ -11765,9 +11765,16 @@ _EOF_
# Link to the default ha location for the homeassistant user, this makes
# the configuration avaliable for the user to edit. Configuration generated
# when service is started at /home/homeassistant/.homeassistant
mkdir $G_FP_DIETPI_USERDATA/homeassistant
chown -R homeassistant:homeassistant $G_FP_DIETPI_USERDATA/homeassistant
ln -sf $G_FP_DIETPI_USERDATA/homeassistant /home/homeassistant/.homeassistant
# - Move default home location to userdata, if not existing yet
if [[ ! -d $G_FP_DIETPI_USERDATA/homeassistant ]]; then

[[ -d '/home/homeassistant/.homeassistant' ]] && mv /home/homeassistant/.homeassistant $G_FP_DIETPI_USERDATA/homeassistant
mkdir -p $G_FP_DIETPI_USERDATA/homeassistant
chown -R homeassistant:homeassistant $G_FP_DIETPI_USERDATA/homeassistant

fi
rm -Rf /home/homeassistant/.homeassistant
ln -s $G_FP_DIETPI_USERDATA/homeassistant /home/homeassistant/.homeassistant

fi

Expand Down Expand Up @@ -13939,21 +13946,26 @@ _EOF_

fi

software_id=157
software_id=157 # Home Assistant
if (( ${aSOFTWARE_INSTALL_STATE[$software_id]} == -1 )); then

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 installation of HA.
[[ -d '/srv/homeassistant' ]] && rm -R /srv/homeassistant
# Remove the service.
if [[ -f '/etc/systemd/system/home-assistant.service' ]]; then

systemctl disable --now home-assistant
rm /etc/systemd/system/home-assistant.service

fi

# Remove the user and all files. This removed pyenv for this user as well.
getent passwd homeassistant &> /dev/null && userdel -rf homeassistant
getent group homeassistant &> /dev/null && groupdel homeassistant

# Remove the service.
[[ -f '/etc/systemd/system/home-assistant.service' ]] && rm /etc/systemd/system/home-assistant.service
# Remove installation of HA.
[[ -d '/srv/homeassistant' ]] && rm -R /srv/homeassistant

fi

Expand Down Expand Up @@ -15280,7 +15292,7 @@ Once completed, select "Apply Save Changes", then exit DietPi-Config to resume s
local criteria_passed=1
local output_string='The following criteria must be met, for the installation of WiFi Hotspot to succeed:'

if ip r | grep -qi "eth$(sed -n 1p /DietPi/dietpi/.network)"; then
if ip r | grep -qi "eth$(mawk 'NR==1' /DietPi/dietpi/.network)"; then

output_string+='\n\n - Ethernet online: PASSED'

Expand All @@ -15291,7 +15303,7 @@ Once completed, select "Apply Save Changes", then exit DietPi-Config to resume s

fi

if [[ -d /sys/class/net/wlan$(sed -n 2p /DietPi/dietpi/.network) ]]; then
if [[ -d /sys/class/net/wlan$(mawk 'NR==2' /DietPi/dietpi/.network) ]]; then

output_string+='\n\n - Wifi adapter detected: PASSED'

Expand Down Expand Up @@ -15374,6 +15386,16 @@ phpMyAdmin will be deselected!'

fi

# Home Assistant: Inform about long install/build time: https://github.com/MichaIng/DietPi/issues/2897
if (( ${aSOFTWARE_INSTALL_STATE[157]} == 1 )); then

G_WHIP_MSG '[ INFO ] Home Assistant: Grab yourself a coffee
\nThe install process of Home Assistant within the virtual environment, especially the Python build, can take more than one hour, especially on slower SBCs like RPi Zero and similar.
\nPlease be patient. Meanwhile you might want to participate the discussion about reducing (re)install times, by skipping Python rebuild or installing everything outside of the pyenv environment:
- https://github.com/MichaIng/DietPi/issues/2374'

fi

# Boot Choices
if (( ${aSOFTWARE_INSTALL_STATE[23]} == 1 ||
${aSOFTWARE_INSTALL_STATE[24]} == 1 ||
Expand Down

0 comments on commit 569d162

Please sign in to comment.