1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/homeassistant_ynh.git synced 2024-09-03 19:26:16 +02:00
homeassistant_ynh/scripts/restore

115 lines
4.4 KiB
Text
Raw Permalink Normal View History

2022-01-08 10:04:57 +01:00
#!/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"
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
2023-02-12 22:01:31 +01:00
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir"
2022-01-08 10:04:57 +01:00
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
2023-02-12 22:01:31 +01:00
ynh_script_progression --message="Restoring the data directory..."
ynh_restore_file --origin_path="$data_dir" --not_mandatory
mkdir -p $data_dir
2022-01-08 10:04:57 +01:00
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
2023-02-12 22:01:31 +01:00
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
2022-01-08 10:04:57 +01:00
ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name < ./db.sql
#=================================================
2023-02-15 12:31:34 +01:00
# RESTORE SYSTEM CONFIGURATIONS
2022-01-08 10:04:57 +01:00
#=================================================
2023-02-15 12:31:34 +01:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2022-01-08 10:04:57 +01:00
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
2022-02-07 21:17:10 +01:00
# add --verbose to track restart
sed -i 's/ExecStart=.*/& --verbose/g' "/etc/systemd/system/$app.service"
2022-01-08 10:04:57 +01:00
systemctl enable $app.service --quiet
2023-02-15 12:31:34 +01:00
yunohost service add $app --description="Home Assistant server" --log="$log_file"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
ynh_restore_file --origin_path="/etc/sudoers.d/$app"
ynh_restore_file --origin_path="$(dirname "$log_file")"
2022-01-08 10:04:57 +01:00
#=================================================
2023-02-15 12:31:34 +01:00
# SPECIFIC RESTORATION
#=================================================
# CHECK PYTHON VERSION AND COMPILE IF NEEDED
2022-01-08 10:04:57 +01:00
#=================================================
2023-02-15 12:31:34 +01:00
ynh_script_progression --message="Restoring Python..." --weight=1
myynh_install_python --python="$python"
2022-01-08 10:04:57 +01:00
#=================================================
# IF NEEDED UPDATE THE PYHTON LINK IN THE VIRUTAL ENV.
#=================================================
2023-02-12 22:01:31 +01:00
ynh_script_progression --message="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
2023-02-15 18:15:32 +01:00
#=================================================
# SET FILE OWNERSHIP / PERMISSIONS
#=================================================
myynh_set_permissions
2022-01-08 10:04:57 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2023-02-12 22:01:31 +01:00
ynh_script_progression --message="Starting a systemd service..."
2022-02-07 21:17:10 +01:00
# start systemd service with --verbose
ynh_systemd_action --service_name=$app --action=start --line_match="Home Assistant initialized" --log_path="$log_file" --timeout=3600
# remove --verbose from service
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app.service"
ynh_store_file_checksum --file="/etc/systemd/system/$app.service"
systemctl daemon-reload
ynh_systemd_action --service_name=$app --action=restart
2022-01-08 10:04:57 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
2023-02-12 22:01:31 +01:00
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..."
2022-01-08 10:04:57 +01:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last