2015-08-22 20:24:46 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2015-08-22 20:24:46 +02:00
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2015-08-22 20:24:46 +02:00
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
2015-08-22 20:24:46 +02:00
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2015-08-22 22:22:45 +02:00
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
port=$(ynh_app_setting_get $app port)
|
2015-08-22 20:24:46 +02:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
#=================================================
|
|
|
|
# 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)
|
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
|
2015-08-22 20:24:46 +02:00
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
# Fix is_public as a boolean value
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=1
|
2018-05-01 12:25:53 +02:00
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=0
|
2018-05-01 12:25:53 +02:00
|
|
|
is_public=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If final_path doesn't exist, create it
|
2019-10-25 11:04:41 +02:00
|
|
|
if [ -z "$final_path" ]; then
|
2018-05-01 12:25:53 +02:00
|
|
|
final_path=/var/www/$app
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2018-05-01 12:25:53 +02:00
|
|
|
fi
|
2015-08-22 20:24:46 +02:00
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
# If config_path doesn't exist, create it
|
2019-10-25 11:04:41 +02:00
|
|
|
if [ -z "$config_path" ]; then
|
|
|
|
final_path=/home/yunohost.app/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$config_path
|
2015-08-22 20:24:46 +02:00
|
|
|
fi
|
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
|
2018-05-01 12:25:53 +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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Normalize the URL path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
# STOP SYSTEMD SERVICE
|
2018-05-01 12:25:53 +02:00
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
|
2018-05-01 12:25:53 +02:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
2015-08-22 20:24:46 +02:00
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2018-05-01 12:25:53 +02:00
|
|
|
#=================================================
|
2015-08-22 20:24:46 +02:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Upgrading source files..." --time --weight=1
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
fi
|
2018-05-01 12:25:53 +02:00
|
|
|
|
2018-05-03 19:57:18 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE NODEJS
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
|
2018-05-03 19:57:18 +02:00
|
|
|
|
|
|
|
ynh_cron_upgrade_node
|
|
|
|
|
2018-05-01 22:09:53 +02:00
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
# UPGRADE THE LOUNGE
|
2018-05-01 22:09:53 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
|
|
|
pushd $final_path
|
|
|
|
npm install --unsafe-perm
|
|
|
|
|
|
|
|
# Install webpack
|
|
|
|
npm upgrade webpack
|
|
|
|
npm upgrade webpack-cli
|
|
|
|
npm upgrade copy-webpack-plugin
|
|
|
|
|
|
|
|
# Build The Lounge
|
|
|
|
NODE_ENV=production npm run build
|
|
|
|
|
|
|
|
popd
|
|
|
|
fi
|
2018-05-01 22:09:53 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
# NGINX CONFIGURATION
|
2018-05-01 22:09:53 +02:00
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1
|
2018-05-01 22:09:53 +02:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
2018-05-01 22:09:53 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
# CREATE DEDICATED USER
|
2018-05-01 22:09:53 +02:00
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
|
2018-05-01 22:09:53 +02:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app
|
2018-05-01 22:09:53 +02:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2018-05-01 22:09:53 +02:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_use_nodejs
|
|
|
|
ynh_replace_string "__NODEJS__" "$nodejs_version" "../conf/systemd.service"
|
|
|
|
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
|
|
|
|
ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service"
|
|
|
|
ynh_add_systemd_config
|
2018-05-01 22:09:53 +02:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app
|
2018-05-01 22:09:53 +02:00
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# ...
|
|
|
|
#=================================================
|
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
|
|
|
|
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
|
|
|
|
ynh_backup_if_checksum_is_different --file="$config_path/config.js"
|
|
|
|
# Recalculate and store the checksum of the file for the next upgrade.
|
|
|
|
ynh_store_file_checksum --file="$config_path/config.js"
|
|
|
|
|
|
|
|
cp -a ../conf/config.js $config_path
|
2018-05-01 12:25:53 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
|
2018-05-01 12:25:53 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set right permissions for curl installation
|
|
|
|
chown -R $app: $final_path
|
|
|
|
chown -R $app: $config_path
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Upgrading SSOwat configuration..." --time --weight=1
|
2018-05-01 12:25:53 +02:00
|
|
|
|
2015-08-22 20:24:46 +02:00
|
|
|
# Make app public if necessary
|
2018-05-01 12:25:53 +02:00
|
|
|
if [ $is_public -eq 1 ]
|
2015-08-22 20:24:46 +02:00
|
|
|
then
|
2018-05-01 12:25:53 +02:00
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
2015-08-22 20:24:46 +02:00
|
|
|
fi
|
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
2018-05-01 12:25:53 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2018-05-01 12:25:53 +02:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --time --last
|