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

240 lines
8.2 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
#=================================================
2020-09-17 22:08:44 +02:00
ynh_script_progression --message="Loading installation settings..." --weight=1
2018-08-10 15:55:41 +02:00
app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings
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)
ssoenabled=$(ynh_app_setting_get --app=$app --key=ssoenabled)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
2020-09-17 22:18:12 +02:00
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
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
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
2018-08-10 16:36:04 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-09-17 22:08:44 +02:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=4
2018-08-10 16:36:04 +02:00
2020-07-24 12:46:55 +02:00
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
2018-08-10 16:36:04 +02:00
fi
2018-08-10 15:55:41 +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)
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
2018-08-10 15:55:41 +02:00
#=================================================
2020-07-24 12:46:55 +02:00
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
2018-08-10 15:55:41 +02:00
#=================================================
2020-09-17 22:08:44 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
2018-08-10 15:55:41 +02:00
# Backup the current version of the app
2020-07-24 12:46:55 +02:00
ynh_backup_before_upgrade
ynh_clean_setup () {
2018-08-10 15:55:41 +02:00
# restore it if the upgrade fails
2020-07-24 12:46:55 +02:00
ynh_restore_upgradebackup
}
2018-08-10 15:55:41 +02:00
# 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)
2015-08-11 12:26:57 +02:00
2018-08-10 15:55:41 +02:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
2020-07-24 12:46:55 +02:00
# STOP SYSTEMD SERVICE
2018-08-10 15:55:41 +02:00
#=================================================
2020-09-17 22:08:44 +02:00
ynh_script_progression --message="Stopping a systemd service..." --weight=23
2015-08-31 16:39:08 +02:00
2020-07-24 12:46:55 +02:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
2017-12-29 14:33:28 +01: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
2020-09-17 22:08:44 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=1
2020-07-24 12:46:55 +02:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
2018-08-10 17:27:41 +02:00
2020-07-24 12:46:55 +02:00
## TODO: consider installation in a subpath
2020-09-17 18:49:20 +02:00
ynh_replace_string "'ws/'" "'${path_url%/}/ws/'" \
"$final_path/public/scripts/movim_websocket.js"
2020-07-24 12:46:55 +02:00
fi
2018-08-12 00:59:39 +02:00
2018-08-12 00:03:51 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-09-17 22:08:44 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=5
2018-08-12 00:03:51 +02:00
# Create a dedicated nginx config
ynh_add_nginx_config
2015-08-21 18:12:22 +02:00
2020-07-24 12:46:55 +02:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2020-09-17 22:08:44 +02:00
ynh_script_progression --message="Upgrading dependencies..." --weight=4
2020-07-24 12:46:55 +02:00
ynh_install_app_dependencies $pkg_dependencies
2018-08-10 15:55:41 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2020-09-17 22:08:44 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=7
2018-08-10 15:55:41 +02:00
# Create a dedicated user (if not existing)
2020-07-24 12:46:55 +02:00
ynh_system_user_create --username=$app
2018-08-10 15:55:41 +02:00
2018-08-12 00:03:51 +02:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2020-09-17 22:08:44 +02:00
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
2018-08-12 00:03:51 +02:00
2020-09-17 22:08:44 +02:00
# Create a dedicated PHP-FPM config
ynh_replace_string --match_string="__YHTZ__" --replace_string="$timezone" --target_file=../conf/php-fpm.conf
ynh_add_fpm_config --phpversion=$YNH_PHP_VERSION --package="$extra_php_dependencies"
phpversion=$(ynh_app_setting_get --app="$app" --key=phpversion)
2018-08-12 00:03:51 +02:00
2018-08-10 15:55:41 +02:00
#=================================================
# SET PERMISSIONS
#=================================================
2020-09-17 18:49:20 +02:00
# chown -R "$app":www-data "$final_path"
# find "${final_path}/" -type f -print0 | xargs -0 chmod 0644
# find "${final_path}/" -type d -print0 | xargs -0 chmod 0755
# chmod 400 "${final_path}/config/db.inc.php"
chown -R $app:www-data $final_path
#chmod u+rwx $final_path
chown -R $app $final_path/src/Movim/Bootstrap.php
2015-08-11 12:26:57 +02:00
2018-08-10 15:55:41 +02:00
#=================================================
2018-08-12 00:59:39 +02:00
# Install PHP dependencies using composer
2018-08-10 15:55:41 +02:00
#=================================================
2018-08-12 00:59:39 +02:00
(
cd "$final_path"
curl -sS https://getcomposer.org/installer | php -- --install-dir="$final_path" \
&& php composer.phar config --global discard-changes true --quiet \
&& php composer.phar install --no-interaction --quiet
)
2015-08-11 12:26:57 +02:00
2018-08-10 15:55:41 +02:00
#=================================================
2018-08-12 00:59:39 +02:00
# Set-up database
2018-08-10 15:55:41 +02:00
#=================================================
2020-09-17 22:08:44 +02:00
ynh_script_progression --message="Configuring database.." --weight=1
2018-08-12 00:59:39 +02:00
(
cd "$final_path"
2020-09-22 13:32:39 +02:00
ynh_exec_as $app php"${phpversion}" composer.phar movim:migrate
2018-08-12 00:59:39 +02:00
)
2018-08-10 15:55:41 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-09-17 22:08:44 +02:00
# # Reset SSO parameters
# ynh_app_setting_delete "$app" protected_uris
# ynh_app_setting_delete "$app" skipped_uris
# yunohost app clearaccess "$app"
2015-12-16 13:53:46 +01:00
2020-09-17 22:08:44 +02:00
# # Replace old public_site variable (if exists) by ssoenabled
# # TODO: add clean support for old/new setting public_site/ssoenabled
# if [ ! -z "$public_site" ]; then
# [[ $public_site = "Yes" ]] \
# && ssoenabled="No" \
# || ssoenabled="Yes"
# ynh_app_setting_delete "$app" public_site
# ynh_app_setting_set "$app" ssoenabled "$ssoenabled"
# fi
2015-12-16 17:24:02 +01:00
2018-08-10 15:55:41 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2020-09-17 22:08:44 +02:00
# # SSOwat configuration
# if [[ "$ssoenabled" = "No" ]]; then
# ynh_app_setting_set "$app" skipped_uris "/"
# (cd "$final_path" && php mud.php config --xmppwhitelist="$domain")
# yunohost app ssowatconf
# undo_sso_patch
# else
# ynh_app_setting_set "$app" unprotected_uris "/"
# fi
2015-08-21 18:12:22 +02:00
2018-08-10 15:55:41 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
2018-08-12 00:22:31 +02:00
# Create a dedicated systemd config
2020-07-24 12:46:55 +02:00
2020-09-17 22:08:44 +02:00
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file=../conf/systemd.service
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file=../conf/systemd.service
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file=../conf/systemd.service
2020-07-24 12:46:55 +02:00
2018-08-12 00:22:31 +02:00
ynh_add_systemd_config
2018-08-10 15:55:41 +02:00
#=================================================
2020-07-24 12:46:55 +02:00
# START SYSTEMD SERVICE
#=================================================
2020-09-17 22:18:12 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2020-07-24 12:46:55 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# RELOAD NGINX
#=================================================
2020-09-17 22:18:12 +02:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
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
#=================================================
2020-09-17 22:18:12 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last