2015-08-11 12:26:57 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-07-10 16:24:09 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2016-07-10 16:24:09 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2016-07-10 16:24:09 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2016-07-11 18:41:22 +02:00
|
|
|
|
2020-07-24 12:46:55 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
2022-01-31 08:47:43 +01:00
|
|
|
db_user=$db_name
|
2021-02-21 22:20:08 +01:00
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
2020-07-24 18:32:57 +02:00
|
|
|
phpversion=$(ynh_app_setting_get --app="$app" --key=phpversion)
|
2020-09-22 13:00:54 +02:00
|
|
|
timezone=$(cat /etc/timezone)
|
2020-07-24 12:46:55 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Checking version..."
|
2020-07-24 12:46:55 +02:00
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2018-08-10 16:36:04 +02:00
|
|
|
|
2022-01-31 08:47:43 +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 () {
|
2022-06-20 01:52:27 +02:00
|
|
|
ynh_clean_check_starting
|
2022-01-31 08:47:43 +01:00
|
|
|
# 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" --log_path="systemd" --line_match="Stopped"
|
|
|
|
|
2018-08-10 16:36:04 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
2018-08-10 16:36:04 +02:00
|
|
|
|
2018-08-12 00:29:57 +02:00
|
|
|
# If db_name doesn't exist, create it
|
|
|
|
if [ -z "$db_name" ]; then
|
2020-07-24 12:46:55 +02:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
2022-01-31 08:47:43 +01:00
|
|
|
db_user=$db_name
|
2020-07-24 12:46:55 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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
|
2018-08-12 00:29:57 +02:00
|
|
|
fi
|
|
|
|
|
2021-02-21 22:20:08 +01:00
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
|
|
|
|
2021-08-09 23:58:08 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
2021-08-09 23:58:08 +02:00
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
2022-06-20 01:52:27 +02:00
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
2021-08-09 23:58:08 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
2020-07-24 12:46:55 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
2020-07-24 12:46:55 +02:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2022-06-20 02:01:32 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path" --keep="config/db.inc.php"
|
2022-01-31 08:47:43 +01:00
|
|
|
|
2022-02-01 20:14:10 +01:00
|
|
|
# Temporary workaround to fix movim.ERROR: Error: Call to undefined function GuzzleHttp\Psr7\uri_for()
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_replace_string --match_string="0.3.5" --replace_string="0.4.1" --target_file="$final_path/composer.json"
|
2020-07-24 12:46:55 +02:00
|
|
|
fi
|
2018-08-12 00:59:39 +02:00
|
|
|
|
2021-08-09 23:58:08 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
2020-07-24 12:46:55 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
2020-07-24 12:46:55 +02:00
|
|
|
|
2021-01-15 13:32:05 +01:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
2020-07-24 12:46:55 +02:00
|
|
|
|
2018-08-12 00:03:51 +02:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Upgrading PHP-FPM configuration..."
|
2018-08-12 00:03:51 +02:00
|
|
|
|
2020-09-17 22:08:44 +02:00
|
|
|
# Create a dedicated PHP-FPM config
|
2022-03-03 09:53:43 +01:00
|
|
|
ynh_add_fpm_config
|
2018-08-12 00:03:51 +02:00
|
|
|
|
2020-11-23 23:39:34 +01:00
|
|
|
#=================================================
|
2022-06-20 01:52:27 +02:00
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
2022-01-31 08:47:43 +01:00
|
|
|
#=================================================
|
|
|
|
# UPDATE A CONFIG FILE
|
2020-11-23 23:39:34 +01:00
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Updating a configuration file..."
|
|
|
|
|
|
|
|
ynh_add_config --template="../conf/db.example.inc.php" --destination="$final_path/config/db.inc.php"
|
2020-11-23 23:39:34 +01:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
chmod 400 "$final_path/config/db.inc.php"
|
|
|
|
chown $app:$app "$final_path/config/db.inc.php"
|
2020-11-23 23:39:34 +01:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
# BUILD MOVIM
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Building Movim..."
|
2018-08-10 15:55:41 +02:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$final_path"
|
|
|
|
ynh_exec_warn_less ynh_composer_exec --phpversion="$phpversion" --workdir="$final_path" --commands="config --global discard-changes true --quiet"
|
|
|
|
ynh_exec_warn_less ynh_composer_exec --phpversion="$phpversion" --workdir="$final_path" --commands="update --no-interaction --quiet"
|
|
|
|
ynh_exec_warn_less ynh_composer_exec --phpversion="$phpversion" --workdir="$final_path" --commands="movim:migrate --quiet"
|
2015-08-11 12:26:57 +02:00
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
2018-08-10 15:55:41 +02:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
# Create a dedicated systemd config
|
2018-08-12 00:22:31 +02:00
|
|
|
ynh_add_systemd_config
|
2015-08-19 11:25:29 +02:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
|
|
|
|
yunohost service add $app --description="Responsive web-based XMPP client"
|
|
|
|
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
2020-07-24 12:46:55 +02:00
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2020-07-24 12:46:55 +02:00
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Movim daemon launched"
|
2020-07-24 12:46:55 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2020-07-24 12:46:55 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
2018-08-10 15:55:41 +02:00
|
|
|
#=================================================
|
|
|
|
|
2022-01-31 08:47:43 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|