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

77 lines
3 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
2018-09-25 19:03:30 +02:00
# yunohost app remove homeassistant
# yunohost backup restore "homeassistant-test"
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"
2018-09-25 19:03:30 +02:00
home_path="/home/$app"
2018-10-17 16:00:04 +02:00
data_path="/home/$app/.$app"
2021-01-05 15:18:56 +01:00
path_url="/"
2018-09-25 19:03:30 +02:00
2020-11-17 18:20:52 +01:00
ynh_script_progression --message="Validating recovery parameters..."
2018-09-25 19:03:30 +02:00
# check domain/path availability
2020-11-16 15:10:12 +01:00
[ ! -d "$final_path" ] || ynh_die --message="This path already contains a folder"
ynh_webpath_available --domain="$domain" --path_url="$path_url" || ynh_die "$domain/$path_url is not available, please use an other domain."
2018-09-25 19:03:30 +02:00
2020-11-17 18:20:52 +01:00
ynh_script_progression --message="Restoring the port and opening it..."
# restore port
[ $port -eq $(ynh_find_port $port) ] || ynh_die "$port is not available, please use an other port"
ynh_exec_fully_quiet yunohost firewall allow TCP $port
ynh_script_progression --message="Restoring dedicated user, rights and folders..."
2018-09-25 19:03:30 +02:00
# restore dedicated system user
2020-08-12 22:22:59 +02:00
ynh_system_user_create --username="$app"
ynh_restore_file --origin_path="/etc/sudoers.d/$app"
2018-09-25 19:03:30 +02:00
# restore source
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
2020-11-17 18:20:52 +01:00
ynh_script_progression --message="Restoring the data..."
2018-09-25 19:03:30 +02:00
# restore data
2020-08-12 22:22:59 +02:00
ynh_restore_file --origin_path="$home_path"
chown -R $app: "$home_path"
chmod -R +x "$home_path/.homeassistant/bin"
2018-09-25 19:03:30 +02:00
2020-11-17 18:20:52 +01:00
ynh_script_progression --message="Restoring the packages dependencies..."
# add required packages
myynh_install_dependencies --python="$python"
2018-09-25 19:03:30 +02:00
2020-11-17 18:20:52 +01:00
ynh_script_progression --message="Restoring the dedicated service..."
ynh_restore_file --origin_path="/etc/systemd/system/$app@$app.service"
2018-09-25 19:03:30 +02:00
# add service in admin panel
2020-11-14 14:10:51 +01:00
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
2018-09-25 19:03:30 +02:00
2020-11-17 18:20:52 +01:00
ynh_script_progression --message="Starting the Home Assistant server..."
2020-11-16 15:10:12 +01:00
# add --verbose to service
sed --in-place "/ExecStart/s/$/ --verbose/" "/etc/systemd/system/$app@$app.service"
# start
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=3600
# remove --verbose from service and restart
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.service"
systemctl daemon-reload
ynh_systemd_action --service_name="$app@$app" --action=restart
2018-09-25 19:03:30 +02:00
2020-11-17 18:20:52 +01:00
ynh_script_progression --message="Restoring nginx web server..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2018-09-25 19:03:30 +02:00
# reload nginx
2020-08-13 20:50:44 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2020-11-17 18:20:52 +01:00
ynh_script_progression --message="Recovery of $app completed" --last