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

87 lines
3.1 KiB
Text
Raw Normal View History

2018-09-25 19:03:30 +02:00
#!/bin/bash
# to test the functionnality :
2018-10-18 05:16:40 +02:00
# yunohost backup create -n "homeassistant-test" --apps homeassistant
2021-11-20 19:05:14 +01:00
# yunohost app remove homeassistant --purge
2018-09-25 19:03:30 +02:00
# yunohost backup restore "homeassistant-test"
2021-11-20 19:05:14 +01:00
# yunohost backup delete "homeassistant-test"
2018-09-25 19:03:30 +02:00
2018-10-18 05:16:40 +02:00
source ../settings/scripts/_common.sh
2018-09-25 19:03:30 +02:00
source /usr/share/yunohost/helpers
# manage script failure
2020-08-13 20:50:44 +02:00
ynh_clean_setup () {
ynh_clean_check_starting
}
2018-09-25 19:03:30 +02:00
ynh_abort_if_errors
# retrieve arguments
app=$YNH_APP_INSTANCE_NAME
2020-11-16 15:10:12 +01:00
domain=$(ynh_app_setting_get --app="$app" --key=domain)
port=$(ynh_app_setting_get --app="$app" --key=port)
2020-11-17 18:20:52 +01:00
python=$(ynh_app_setting_get --app="$app" --key=python)
2018-09-25 19:03:30 +02:00
# definie useful vars
2018-10-18 05:16:40 +02:00
final_path="/opt/yunohost/$app"
2021-11-20 19:05:14 +01:00
data_path="/home/yunohost.app/$app"
2021-11-24 06:53:48 +01:00
log_file="/var/log/$app/$app.log"
2021-01-05 15:18:56 +01:00
path_url="/"
2018-09-25 19:03:30 +02:00
# check domain/path availability
2021-11-20 19:05:14 +01:00
ynh_script_progression --message="Validating recovery parameters..."
2020-11-16 15:10:12 +01:00
[ ! -d "$final_path" ] || ynh_die --message="This path already contains a folder"
2018-09-25 19:03:30 +02:00
2020-11-17 18:20:52 +01:00
# restore port
2021-11-20 19:05:14 +01:00
ynh_script_progression --message="Restoring the port and opening it..."
2021-06-21 08:55:20 +02:00
ynh_exec_warn_less yunohost firewall allow TCP $port
2020-11-17 18:20:52 +01:00
2018-09-25 19:03:30 +02:00
# restore dedicated system user
2021-11-20 19:05:14 +01:00
ynh_script_progression --message="Restoring dedicated user and rights folders..."
2020-08-12 22:22:59 +02:00
ynh_system_user_create --username="$app"
ynh_restore_file --origin_path="/etc/sudoers.d/$app"
2021-11-20 19:05:14 +01:00
2018-09-25 19:03:30 +02:00
# restore source
2021-11-20 19:05:14 +01:00
ynh_script_progression --message="Restoring the app..."
2020-08-12 22:22:59 +02:00
ynh_restore_file --origin_path="$final_path"
2020-11-17 18:20:52 +01:00
chown -R $app: "$final_path"
2018-09-25 19:03:30 +02:00
# restore data
2021-11-20 19:05:14 +01:00
ynh_script_progression --message="Restoring the data..."
ynh_restore_file --origin_path="$data_path"
chown -R $app: "$data_path"
chmod -R +x "$data_path/.$app/bin"
2018-09-25 19:03:30 +02:00
2020-11-17 18:20:52 +01:00
# add required packages
2021-11-20 19:05:14 +01:00
ynh_script_progression --message="Restoring the packages dependencies..."
2021-01-18 21:12:47 +01:00
myynh_install_dependencies --python="$python"
2018-09-25 19:03:30 +02:00
2021-11-20 19:05:14 +01:00
# restore the systemd service
2020-11-17 18:20:52 +01:00
ynh_script_progression --message="Restoring the dedicated service..."
2021-11-21 21:25:39 +01:00
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
2021-11-20 19:05:14 +01:00
2018-09-25 19:03:30 +02:00
# add service in admin panel
2021-11-23 22:27:54 +01:00
yunohost service add "$app" --log "$log_file" --description "Home Assistant server" --needs_exposed_ports $port
2018-09-25 19:03:30 +02:00
2021-11-20 19:05:14 +01:00
# restart the app
2020-11-17 18:20:52 +01:00
ynh_script_progression --message="Starting the Home Assistant server..."
2021-11-21 21:25:39 +01:00
sed --in-place "/ExecStart/s/$/ --verbose/" "/etc/systemd/system/$app.service"
2021-11-24 06:53:48 +01:00
ynh_systemd_action --service_name="$app" --action=start --line_match="Home Assistant initialized" --log_path="$log_file" --timeout=900
2021-11-20 19:05:14 +01:00
2020-11-16 15:10:12 +01:00
# remove --verbose from service and restart
2021-11-23 20:40:19 +01:00
#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
2018-09-25 19:03:30 +02:00
2021-02-20 09:53:53 +01:00
# restore logrotate
2021-11-20 19:05:14 +01:00
ynh_script_progression --message="Restoring logrotate..."
2021-02-20 09:53:53 +01:00
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
2021-11-20 19:05:14 +01:00
# restore nginx
ynh_script_progression --message="Restoring nginx web server..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2020-08-13 20:50:44 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2020-11-17 18:20:52 +01:00
2021-11-24 20:34:38 +01:00
ynh_local_curl
2020-11-17 18:20:52 +01:00
ynh_script_progression --message="Recovery of $app completed" --last