mirror of
https://github.com/YunoHost-Apps/homeassistant_ynh.git
synced 2024-09-03 19:26:16 +02:00
106 lines
3.7 KiB
Bash
106 lines
3.7 KiB
Bash
#!/bin/bash
|
|
# to test the functionnality :
|
|
# yunohost backup create -n "homeassistant-test" --apps homeassistant
|
|
# yunohost app remove homeassistant --purge
|
|
# yunohost backup restore "homeassistant-test"
|
|
# yunohost backup delete "homeassistant-test"
|
|
|
|
source ../settings/scripts/_common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# RESTORE THE APP MAIN DIR
|
|
#=================================================
|
|
|
|
ynh_script_progression "Restoring the app main directory..."
|
|
ynh_restore "$install_dir"
|
|
|
|
#=================================================
|
|
# RESTORE THE DATA DIRECTORY
|
|
#=================================================
|
|
|
|
ynh_script_progression "Restoring the data directory..."
|
|
ynh_restore "$data_dir"
|
|
mkdir -p $data_dir
|
|
|
|
#=================================================
|
|
# RESTORE THE MYSQL DATABASE
|
|
#=================================================
|
|
|
|
ynh_script_progression "Restoring the MySQL database..."
|
|
ynh_mysql_db_shell < ./db.sql
|
|
|
|
#=================================================
|
|
# RESTORE SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
|
|
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
ynh_restore "/etc/systemd/system/$app.service"
|
|
# add --verbose to track restart
|
|
sed -i 's/ExecStart=.*/& --verbose/g' "/etc/systemd/system/$app.service"
|
|
systemctl enable $app.service --quiet
|
|
|
|
yunohost service add $app --description="Home Assistant server" --log="$log_file"
|
|
|
|
ynh_restore "/etc/logrotate.d/$app"
|
|
|
|
ynh_script_progression "Restoring the Fail2Ban configuration..."
|
|
ynh_restore "/etc/fail2ban/jail.d/$app.conf"
|
|
ynh_restore "/etc/fail2ban/filter.d/$app.conf"
|
|
ynh_systemctl --action=restart --service=fail2ban
|
|
|
|
ynh_restore "/etc/sudoers.d/$app"
|
|
ynh_restore "$(dirname "$log_file")"
|
|
|
|
#=================================================
|
|
# SPECIFIC RESTORATION
|
|
#=================================================
|
|
# CHECK PYTHON VERSION AND COMPILE IF NEEDED
|
|
#=================================================
|
|
|
|
ynh_script_progression "Restoring Python..."
|
|
myynh_install_python --python="$python"
|
|
|
|
#=================================================
|
|
# IF NEEDED UPDATE THE PYHTON LINK IN THE VIRUTAL ENV.
|
|
#=================================================
|
|
|
|
ynh_script_progression "Updating the pyhton link in the pyhton virtual environment..."
|
|
hass_python_link=$(head -1 /var/www/homeassistant/bin/hass | sed 's/#!//')
|
|
if [ ! -e "$hass_python_link" ] ; then
|
|
hass_python_new_dest=$(which `basename "$hass_python_link"`)
|
|
ln -sfn "$hass_python_new_dest" "$hass_python_link"
|
|
fi
|
|
|
|
#=================================================
|
|
# SET FILE OWNERSHIP / PERMISSIONS
|
|
#=================================================
|
|
|
|
myynh_set_permissions
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
|
|
ynh_script_progression "Starting $app's systemd service..."
|
|
# start systemd service with --verbose
|
|
ynh_systemctl --service=$app --action=start --wait_until="Home Assistant initialized" --log_path="$log_file" --timeout=3600
|
|
# remove --verbose from service
|
|
ynh_replace --match=" --verbose" --replace="" --file="/etc/systemd/system/$app.service"
|
|
ynh_store_file_checksum "/etc/systemd/system/$app.service"
|
|
systemctl daemon-reload
|
|
ynh_systemctl --service=$app --action=restart
|
|
|
|
#=================================================
|
|
# RELOAD NGINX AND PHP-FPM
|
|
#=================================================
|
|
|
|
ynh_script_progression "Reloading NGINX web server and PHP-FPM..."
|
|
ynh_systemctl --service=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression "Restoration completed for $app"
|