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
ericgaspar 7ea2497c96
fix
2020-07-24 12:46:55 +02:00

230 lines
No EOL
7.6 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME
# Retrieve app settings
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)
timezone=$(cat /etc/timezone)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
# 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
fi
# If db_name doesn't exist, create it
if [ -z "$db_name" ]; then
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
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# 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)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --time --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
## TODO: consider installation in a subpath
ynh_replace_string "'/ws/'" "'${path_url%/}/ws/'" \
"${final_path}/app/assets/js/movim_websocket.js"
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SET PERMISSIONS
#=================================================
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"
#=================================================
# Install PHP dependencies using composer
#=================================================
(
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
)
#=================================================
# Set-up database
#=================================================
(
cd "$final_path"
php mud.php db --set
)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Reset SSO parameters
ynh_app_setting_delete "$app" protected_uris
ynh_app_setting_delete "$app" skipped_uris
yunohost app clearaccess "$app"
# 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
#=================================================
# SETUP SSOWAT
#=================================================
# 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
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_replace_string --match_string="__URL__" --replace_string="${domain}${path_url}" --target_file=../conf/systemd.service
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file=../conf/systemd.service
ynh_add_systemd_config
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --time --last