mirror of
https://github.com/YunoHost-Apps/wireguard_ynh.git
synced 2024-09-03 20:35:58 +02:00
142 lines
5.3 KiB
Bash
142 lines
5.3 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
# Drop sudoers file if present
|
|
if [ -f "/etc/sudoers.d/${app}_ynh" ]; then
|
|
ynh_secure_remove /etc/sudoers.d/${app}_ynh
|
|
fi
|
|
|
|
# Remove deprecated services
|
|
if systemctl list-units --full -all | grep -Fq "wireguard_ui_conf.path"; then
|
|
systemctl disable --now --quiet wireguard_ui_conf.path
|
|
ynh_secure_remove --file="/etc/systemd/system/wireguard_ui_conf.path"
|
|
fi
|
|
if systemctl list-units --full -all | grep -Fq "wireguard_ui_conf.service"; then
|
|
systemctl disable --now --quiet wireguard_ui_conf.service
|
|
ynh_secure_remove --file="/etc/systemd/system/wireguard_ui_conf.service"
|
|
fi
|
|
|
|
# Remove the service integration from an older version
|
|
if ynh_exec_warn_less yunohost service status wireguard@wg0 >/dev/null
|
|
then
|
|
yunohost service remove wireguard@wg0
|
|
fi
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=wireguard_ui --action="stop" --line_match="Stopped WireGuard UI" --log_path="systemd" --timeout=30
|
|
ynh_systemd_action --service_name=wg-quick@wg0 --action="stop"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir"
|
|
fi
|
|
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
|
|
|
main_domain=$(cat /etc/yunohost/current_host)
|
|
|
|
# Update configuration for the Web UI
|
|
ynh_add_config --template="../conf/wireguard-ui.env" --destination="$install_dir/wireguard-ui.env"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
|
|
|
# Create a dedicated nginx config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
|
|
|
# Create a dedicated systemd config for the web UI
|
|
ynh_add_systemd_config --service=wireguard_ui --template=wireguard_ui.service
|
|
|
|
# Create dedicated systemd configs for starting and monitoring WireGuard's configuration
|
|
cp ../conf/wireguard@.service /etc/systemd/system/wireguard@.service
|
|
cp ../conf/wireguard@.path /etc/systemd/system/wireguard@.path
|
|
systemctl daemon-reload
|
|
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_add_config --template="../conf/sysctl.conf" --destination="/etc/sysctl.d/$app.conf"
|
|
sysctl -p /etc/sysctl.d/$app.conf
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SECURE FILES AND DIRECTORIES
|
|
#=================================================
|
|
|
|
# Set permissions to 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
|
|
|
|
#=================================================
|
|
# 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"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting the systemd service for the UI..." --weight=1
|
|
|
|
# Start a systemd service
|
|
ynh_systemd_action --service_name=wireguard_ui --action="start" --line_match="http server started" --log_path="systemd" --timeout=30
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed. You may need to reboot your server before being able to start the WireGuard service." --last
|