1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00
movim_ynh/scripts/upgrade

216 lines
8 KiB
Text
Raw Normal View History

2015-08-11 12:26:57 +02:00
#!/bin/bash
2018-08-10 15:55:41 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2018-08-10 15:55:41 +02:00
source _common.sh
source /usr/share/yunohost/helpers
2018-08-10 15:55:41 +02:00
#=================================================
# LOAD SETTINGS
#=================================================
2024-01-29 17:21:02 +01:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#REMOVEME? 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
2024-01-29 17:21:02 +01:00
#REMOVEME? fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
#REMOVEME? fpm_free_footprint=$(ynh_app_setting_get --app=$app --key=fpm_free_footprint)
#REMOVEME? fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
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
#=================================================
2024-01-29 17:21:02 +01:00
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
2022-01-31 08:47:43 +01:00
# Backup the current version of the app
2024-01-29 17:21:02 +01:00
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? 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
2024-01-29 17:21:02 +01:00
#REMOVEME? ynh_restore_upgradebackup
2022-01-31 08:47:43 +01:00
}
# Exit if an error occurs during the execution of the script
2024-01-29 17:21:02 +01:00
#REMOVEME? ynh_abort_if_errors
2022-01-31 08:47:43 +01:00
#=================================================
# 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
# If fpm_footprint doesn't exist, create it
if [ -z "$fpm_footprint" ]; then
fpm_footprint=low
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint
fi
# If fpm_free_footprint doesn't exist, create it
if [ -z "$fpm_free_footprint" ]; then
fpm_free_footprint=0
ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint
fi
# If fpm_usage doesn't exist, create it
if [ -z "$fpm_usage" ]; then
fpm_usage=low
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
fi
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
2024-01-29 17:21:02 +01:00
#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name
2020-07-24 12:46:55 +02:00
fi
2024-01-29 17:21:02 +01:00
# If install_dir doesn't exist, create it
if [ -z "$install_dir" ]; then
#REMOVEME? install_dir=/var/www/$app
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
2018-08-12 00:29:57 +02:00
fi
# Cleaning legacy permissions
2024-01-29 17:21:02 +01:00
#REMOVEME? if ynh_legacy_permissions_exists; then
#REMOVEME? 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
#=================================================
2024-01-29 17:21:02 +01:00
#REMOVEME? 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)
2024-01-29 17:21:02 +01:00
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
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
2024-01-29 17:21:02 +01:00
ynh_setup_source --dest_dir="$install_dir" --keep="config/db.inc.php"
2022-01-31 08:47:43 +01:00
# Temporary workaround to fix movim.ERROR: Error: Call to undefined function GuzzleHttp\Psr7\uri_for()
2024-01-29 17:21:02 +01:00
ynh_replace_string --match_string="0.3.5" --replace_string="0.4.1" --target_file="$install_dir/composer.json"
2020-07-24 12:46:55 +02:00
fi
2018-08-12 00:59:39 +02:00
2024-01-29 17:21:02 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
2021-08-09 23:58:08 +02:00
2020-07-24 12:46:55 +02:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2024-01-29 17:21:02 +01:00
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..."
2020-07-24 12:46:55 +02:00
2024-01-29 17:21:02 +01:00
#REMOVEME? 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
ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint
2024-01-29 17:21:02 +01:00
#REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
2018-08-12 00:03:51 +02: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
#=================================================
2022-01-31 08:47:43 +01:00
ynh_script_progression --message="Updating a configuration file..."
2024-01-29 17:21:02 +01:00
ynh_add_config --template="../conf/db.example.inc.php" --destination="$install_dir/config/db.inc.php"
2024-01-29 17:21:02 +01:00
chmod 400 "$install_dir/config/db.inc.php"
chown $app:$app "$install_dir/config/db.inc.php"
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
2024-01-29 17:21:02 +01:00
ynh_exec_warn_less ynh_install_composer --phpversion="$phpversion" --workdir="$install_dir"
ynh_exec_warn_less ynh_composer_exec --phpversion="$phpversion" --workdir="$install_dir" --commands="config --global discard-changes true --quiet"
ynh_exec_warn_less ynh_composer_exec --phpversion="$phpversion" --workdir="$install_dir" --commands="update --no-interaction --quiet"
ynh_exec_warn_less ynh_composer_exec --phpversion="$phpversion" --workdir="$install_dir" --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
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
#=================================================
2024-01-29 17:21:02 +01:00
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
2020-07-24 12:46:55 +02:00
2024-01-29 17:21:02 +01:00
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
2020-07-24 12:46:55 +02:00
#=================================================
# 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"