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

61 lines
1.8 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-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
2020-11-14 14:10:51 +01:00
myynh_install_dependencies
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"
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
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-08-14 22:09:32 +02:00
# start systemd service
ynh_systemd_action --service_name="$app@$app" --action=start
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