2018-04-03 19:00:18 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
# GENERIC START
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2021-08-30 23:30:41 +02: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)
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
|
|
|
ynh_legacy_permissions_delete_all
|
2018-04-03 19:00:18 +02:00
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
2021-08-30 23:30:41 +02:00
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action=stop --log_path=systemd
|
|
|
|
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
|
|
|
|
ynh_secure_remove --file=$final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
fi
|
|
|
|
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
2018-04-03 19:00:18 +02:00
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
# Create a dedicated NGINX config
|
2018-04-03 19:00:18 +02:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
# UPGRADE DEPENDENCIES
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
2018-04-03 19:00:18 +02:00
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
# Install Nodejs
|
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE NPM MODULES
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Upgrading the lounge..."
|
|
|
|
pushd $final_path
|
|
|
|
ynh_use_nodejs
|
|
|
|
ynh_exec_warn_less NODE_ENV=production npm cache clean
|
|
|
|
ynh_exec_warn_less NODE_ENV=production npm update
|
|
|
|
popd
|
|
|
|
fi
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
# CONFIGURE
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_script_progression --message="Modifying a config file..."
|
2018-04-03 19:00:18 +02:00
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_add_config --template="../conf/app.json" --destination="$final_path/config/app.json"
|
|
|
|
ynh_add_config --template="../conf/db.json" --destination="$final_path/config/db.json"
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
# SETUP LOGROTATE
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_use_logrotate --non-append
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
# SETUP SYSTEMD
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
2018-04-03 19:00:18 +02:00
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
|
2018-04-03 19:00:18 +02:00
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
# SECURE FILES AND DIRECTORIES
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2018-04-03 19:00:18 +02:00
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
yunohost service add $app --description="Client Web IRC" --log="/var/log/$app/$app.log"
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
# START SYSTEMD SERVICE
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2018-04-03 19:00:18 +02:00
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action=start --log_path=systemd
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
# RELOAD NGINX
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2018-04-03 19:00:18 +02:00
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2018-04-04 11:38:47 +02:00
|
|
|
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
2021-08-30 23:30:41 +02:00
|
|
|
# END OF SCRIPT
|
2018-04-03 19:00:18 +02:00
|
|
|
#=================================================
|
|
|
|
|
2021-08-30 23:30:41 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|