2019-02-17 19:06:33 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2022-07-29 00:43:33 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2019-02-17 19:06:33 +01:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2022-07-29 00:43:33 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
db_user=$db_name
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
|
|
password=$(ynh_app_setting_get --app=$app --key=password)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Checking version..."
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=30
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop"
|
2019-02-17 19:06:33 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2022-07-29 00:43:33 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2019-02-17 19:06:33 +01:00
|
|
|
|
|
|
|
# If db_name doesn't exist, create it
|
|
|
|
if [ -z $db_name ]; then
|
|
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
|
|
ynh_app_setting_set $app db_name $db_name
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If final_path doesn't exist, create it
|
|
|
|
if [ -z $final_path ]; then
|
|
|
|
final_path=/opt/yunohost/$app
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
fi
|
|
|
|
|
2022-07-29 00:43:33 +02:00
|
|
|
# If data directory doesn't exists
|
|
|
|
if [ -z $final_path/data ]; then
|
|
|
|
mkdir $final_path/data
|
|
|
|
fi
|
2019-02-17 19:06:33 +01:00
|
|
|
|
2022-07-29 00:43:33 +02:00
|
|
|
# check data directory permission
|
|
|
|
chown -R $app: $final_path/data
|
2019-02-17 19:06:33 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-07-29 00:43:33 +02:00
|
|
|
# CREATE DEDICATED USER
|
2019-02-17 19:06:33 +01:00
|
|
|
#=================================================
|
2022-07-29 00:43:33 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=2
|
2019-02-17 19:06:33 +01:00
|
|
|
|
2022-07-29 00:43:33 +02:00
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create $app
|
2019-02-17 19:06:33 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2020-04-14 21:23:42 +02:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=6
|
2019-02-17 19:06:33 +01:00
|
|
|
|
2022-07-29 00:43:33 +02:00
|
|
|
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_setup_source --dest_dir="$final_path" --source_id="$YNH_ARCH"
|
|
|
|
fi
|
|
|
|
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
2019-02-17 19:06:33 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-11-22 15:27:37 +01:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
|
2019-02-17 19:06:33 +01:00
|
|
|
|
2020-11-30 15:07:53 +01:00
|
|
|
# Create a dedicated NGINX config
|
2019-02-17 19:06:33 +01:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2022-07-29 00:43:33 +02:00
|
|
|
# UPDATE A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Updating a configuration file..."
|
2019-02-17 19:06:33 +01:00
|
|
|
|
2022-07-29 00:43:33 +02:00
|
|
|
ynh_add_config --template="../conf/config.yml" --destination="$final_path/config.yml"
|
2019-02-17 19:06:33 +01:00
|
|
|
|
2022-07-29 00:43:33 +02:00
|
|
|
chmod 400 "$final_path/config.yml"
|
|
|
|
chown $app:$app "$final_path/config.yml"
|
2019-02-17 19:06:33 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2022-07-29 00:43:33 +02:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
2019-02-17 19:06:33 +01:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2022-07-29 00:43:33 +02:00
|
|
|
architecture=$YNH_ARCH
|
2019-02-17 19:06:33 +01:00
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2022-07-29 00:43:33 +02:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2020-11-22 15:27:37 +01:00
|
|
|
#=================================================
|
2022-07-29 00:43:33 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2020-11-22 15:27:37 +01:00
|
|
|
|
|
|
|
yunohost service add $app
|
|
|
|
|
2019-02-17 19:06:33 +01:00
|
|
|
#=================================================
|
2022-07-29 00:43:33 +02:00
|
|
|
# START SYSTEMD SERVICE
|
2019-03-10 13:43:27 +01:00
|
|
|
#=================================================
|
2022-07-29 00:43:33 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2019-03-10 13:43:27 +01:00
|
|
|
|
2022-07-29 00:43:33 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start"
|
2019-03-10 13:43:27 +01:00
|
|
|
|
2019-02-17 19:06:33 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-11-22 15:27:37 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2019-02-17 19:06:33 +01:00
|
|
|
|
2020-11-30 15:07:53 +01:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2019-03-10 17:11:52 +01:00
|
|
|
|
2020-11-22 15:27:37 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|