1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wireguard_ynh.git synced 2024-09-03 20:35:58 +02:00
wireguard_ynh/scripts/restore
Éric Gaspar 48e483baae
v2
2023-06-17 22:11:02 +02:00

99 lines
3.7 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$install_dir"
ynh_restore_file --origin_path="/etc/wireguard"
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app: "$install_dir"
chmod 750 /etc/wireguard
chmod -R o-rwx /etc/wireguard
chown -R $app: /etc/wireguard
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path=/etc/systemd/system/wireguard_ui.service
ynh_restore_file --origin_path=/etc/systemd/system/wireguard@.service
ynh_restore_file --origin_path=/etc/systemd/system/wireguard@.path
systemctl daemon-reload
systemctl enable --quiet wireguard_ui.service
systemctl enable --quiet wireguard@wg0.service
systemctl enable --quiet --now wireguard@wg0.path
#=================================================
# ENABLE PORT FORWARDING
#=================================================
ynh_script_progression --message="Enabling port forwarding..." --weight=1
ynh_restore_file --origin_path="/etc/sysctl.d/$app.conf"
sysctl -p /etc/sysctl.d/$app.conf
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add wg-quick@wg0 --description="WireGuard VPN" --needs_exposed_ports="$port_wg" --test_status="wg show | grep wg0"
yunohost service add wireguard_ui --description="WireGuard UI"
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_restore_file --origin_path=$(jq -r ".config_file_path" $install_dir/db/server/global_settings.json) --not_mandatory
#=================================================
# START UI SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting the systemd service for the UI..." --weight=1
ynh_systemd_action --service_name=wireguard_ui --action="start" --line_match="http server started" --log_path="systemd" --timeout=30
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app. You may need to reboot your server before being able to start the WireGuard service." --last