2020-11-09 13:27:06 +01:00
|
|
|
#!/bin/bash
|
2017-03-03 21:26:30 +01:00
|
|
|
|
2020-11-09 13:27:06 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2017-03-03 21:26:30 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2020-11-09 13:27:06 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2017-11-15 19:19:00 +01:00
|
|
|
|
2020-11-09 13:27:06 +01:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
|
|
fs_port=$(ynh_app_setting_get --app=$app --key=fs_port)
|
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
2020-11-12 18:20:42 +01:00
|
|
|
password=$(ynh_app_setting_get --app=$app --key=password)
|
2017-03-03 21:26:30 +01:00
|
|
|
|
2020-11-09 13:27:06 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
2017-03-03 21:26:30 +01:00
|
|
|
|
2020-11-09 13:27:06 +01:00
|
|
|
### 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)
|
2017-03-03 21:26:30 +01:00
|
|
|
|
2020-11-09 13:27:06 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
2017-03-03 21:26:30 +01:00
|
|
|
|
2020-11-09 13:27:06 +01:00
|
|
|
# If final_path doesn't exist, create it
|
|
|
|
if [ -z "$final_path" ]; then
|
|
|
|
final_path=/var/www/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
fi
|
2017-03-03 21:26:30 +01:00
|
|
|
|
2020-11-09 13:27:06 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
2017-03-03 21:26:30 +01:00
|
|
|
}
|
2020-11-09 13:27:06 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Normalize the URL path syntax
|
|
|
|
# N.B. : this is for app installations before YunoHost 2.7
|
|
|
|
# where this value might be something like /foo/ or foo/
|
|
|
|
# instead of /foo ....
|
|
|
|
# If nobody installed your app before 2.7, then you may
|
|
|
|
# safely remove this line
|
|
|
|
path_url=$(ynh_normalize_url_path --path_url=$path_url)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="$datadir/log/debug-last.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_secure_remove --file="$final_path"
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..."
|
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
|
|
|
2020-11-12 18:20:42 +01:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
pip3 install msgpack-python gevent base58 merkletools
|
2020-11-09 13:27:06 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
2020-11-12 18:20:42 +01:00
|
|
|
ynh_system_user_create --username=$app --home_dir=$datadir -s
|
2020-11-09 13:27:06 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
2020-11-12 18:20:42 +01:00
|
|
|
# Enable password authentication for Zeronet
|
|
|
|
mv $final_path/plugins/disabled-UiPassword $final_path/plugins/UiPassword
|
|
|
|
|
2020-11-09 13:27:06 +01:00
|
|
|
# Set permissions on app files
|
|
|
|
chown -R $app: $final_path
|
|
|
|
chown -R $app: $datadir
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2020-11-12 18:20:42 +01:00
|
|
|
ynh_add_systemd_config --service="$app" --template="systemd.service" --others_var="fs_port port domain datadir password"
|
2020-11-09 13:53:45 +01:00
|
|
|
yunohost service add $app --description "$app service" --log "$datadir/log/debug-last.log" --needs_exposed_ports "$fs_port"
|
2020-11-09 13:27:06 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="$datadir/log/debug-last.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading SSOwat configuration..."
|
|
|
|
|
2020-11-12 18:20:42 +01:00
|
|
|
# Allow the app to be public
|
|
|
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
2020-11-09 13:27:06 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading nginx web server..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2017-03-03 21:26:30 +01:00
|
|
|
|
2020-11-09 13:27:06 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|