2020-10-11 14:45:13 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
2020-12-30 11:21:59 +01:00
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
2020-12-29 18:07:35 +01:00
|
|
|
port_wg=$(ynh_app_setting_get --app=$app --key=port_wg)
|
2020-10-11 14:45:13 +02:00
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
### This helper will compare the version of the currently installed app and the version of the upstream package.
|
|
|
|
### $upgrade_type can have 2 different values
|
|
|
|
### - UPGRADE_APP if the upstream app version has changed
|
|
|
|
### - UPGRADE_PACKAGE if only the YunoHost package has changed
|
|
|
|
### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
|
|
|
|
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
# If final_path doesn't exist, create it
|
|
|
|
if [ -z "$final_path" ]; then
|
|
|
|
final_path=/opt/yunohost/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
fi
|
|
|
|
|
2020-12-30 12:48:17 +01:00
|
|
|
# Change port for WireGuard UI because 8095 is default port for WireGuard VPN
|
|
|
|
if [ $port -eq 8095 ]
|
|
|
|
then
|
|
|
|
ynh_app_setting_delete --app=$app --key=port
|
|
|
|
port=$(ynh_find_port --port=8096)
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=0
|
|
|
|
fi
|
|
|
|
|
2020-10-11 14:45:13 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=wireguard_ui --action="stop" --log_path="/var/log/$app/ui.log"
|
2020-12-29 20:07:37 +01:00
|
|
|
systemctl disable --now --quiet wireguard.path
|
2020-10-11 14:45:13 +02:00
|
|
|
ynh_systemd_action --service_name=wireguard --action="stop"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2020-12-30 15:23:24 +01:00
|
|
|
ynh_setup_source --dest_dir="$final_path" --source_id="$(ynh_detect_arch)"
|
2020-10-11 14:45:13 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=7
|
2020-10-11 14:45:13 +02:00
|
|
|
|
2020-10-11 16:35:19 +02:00
|
|
|
ynh_install_extra_app_dependencies --repo="http://deb.debian.org/debian buster-backports main" --package="$pkg_dependencies"
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
# Create a dedicated systemd config for the web UI
|
|
|
|
ynh_add_systemd_config --service=wireguard_ui --template=wireguard_ui.service --others_var="port"
|
|
|
|
|
|
|
|
# Create a dedicated systemd config for monitoring WireGuard's configuration
|
|
|
|
cp ../conf/wireguard.path /etc/systemd/system/wireguard.path
|
2020-12-30 12:48:17 +01:00
|
|
|
systemctl enable --quiet wireguard.path
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
# Create a dedicated systemd config for restarting WireGuard
|
2020-12-29 20:10:01 +01:00
|
|
|
ynh_add_systemd_config --service=wireguard --template=wireguard.service --others_var="port_wg"
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CONFIGURING WIREGUARD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create db directory for securing it later
|
|
|
|
mkdir -p $final_path/db/server
|
|
|
|
|
|
|
|
# Add interface configuration file
|
|
|
|
cp ../conf/interfaces.json $final_path/db/server/interfaces.json
|
|
|
|
ynh_replace_string --match_string="__PORT_WG__" --replace_string="$port_wg" --target_file="$final_path/db/server/interfaces.json"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set permissions on app files
|
|
|
|
chown -R root: $final_path
|
|
|
|
chown -R $app: $final_path/db
|
2020-12-29 18:16:39 +01:00
|
|
|
chmod -R 750 $final_path/db
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
2021-01-01 13:54:05 +01:00
|
|
|
yunohost service add wireguard --description "WireGuard" --needs_exposed_ports "$port_wg" --test_status "wg show | grep wg0"
|
2020-12-29 18:07:35 +01:00
|
|
|
yunohost service add wireguard_ui --description "WireGuard UI" --log "/var/log/$app/ui.log"
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
# Start a systemd service
|
2020-12-29 18:07:35 +01:00
|
|
|
ynh_systemd_action --service_name=wireguard_ui --action="start" --log_path="/var/log/$app/ui.log"
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
2020-10-11 14:45:13 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-12-30 20:26:03 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|