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

67 lines
2 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
domain=$(ynh_app_setting_get "$app" domain)
port=$(ynh_app_setting_get "$app" port)
# 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
2018-10-18 05:16:40 +02:00
ynh_system_user_exists "$app" && ynh_die "User $app is not available"
ynh_system_user_create "$app"
2018-09-25 19:03:30 +02:00
# restore conf files
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file "/etc/sudoers.d/$app"
2018-09-25 19:03:30 +02:00
ynh_restore_file "/etc/systemd/system/$app@$app.service"
# restore source
if [ ! -d "$final_path" ]; then
2018-10-18 05:16:40 +02:00
ynh_restore_file "$final_path"
2018-09-25 19:03:30 +02:00
else
2018-10-18 05:16:40 +02:00
ynh_die "There is already a directory: $final_path"
2018-09-25 19:03:30 +02:00
fi
# restore data
if [ ! -d "$home_path" ]; then
2018-10-18 05:16:40 +02:00
ynh_restore_file "$home_path"
chown -R $app: "$home_path"
2018-09-25 19:03:30 +02:00
else
2018-10-18 05:16:40 +02:00
ynh_die "$home_path already exists and will not be overwritten"
2018-09-25 19:03:30 +02:00
fi
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
yunohost service add "$app@$app" --log "$data_path/home-assistant.log"
# 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