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

59 lines
1.9 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
ynh_abort_if_errors
# retrieve arguments
app=$YNH_APP_INSTANCE_NAME
2020-08-12 22:22:59 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
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"
2018-09-25 19:03:30 +02:00
# check domain/path availability
path_url=$(ynh_normalize_url_path "/")
2018-10-18 05:16:40 +02:00
ynh_webpath_available $domain $path_url || ynh_die "$domain/$path_url is not available, please use an other domain."
2018-09-25 19:03:30 +02:00
# add required packages
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
# restore dedicated system user
2020-08-12 22:22:59 +02:00
ynh_system_user_create --username="$app"
2018-09-25 19:03:30 +02:00
# restore conf files
2020-08-12 22:22:59 +02:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/sudoers.d/$app"
ynh_restore_file --origin_path="/etc/systemd/system/$app@$app.service"
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"
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
2018-10-18 05:16:40 +02:00
# 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
2018-09-25 19:03:30 +02:00
# add service in admin panel
2019-06-10 12:07:28 +02:00
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server"
2018-09-25 19:03:30 +02:00
# enable & restart systemd service
2018-10-18 05:16:40 +02:00
ynh_system_reload --service_name="$app@$app" --action=enable
2018-11-30 05:55:42 +01:00
ynh_check_starting --line_to_match="Home Assistant initialized" --app_log="systemd" --timeout=1000 --service_name="$app@$app"
2018-09-25 19:03:30 +02:00
# reload nginx
2018-10-18 05:16:40 +02:00
ynh_system_reload --service_name=nginx