1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/framaforms_ynh.git synced 2024-09-03 18:36:12 +02:00
framaforms_ynh/scripts/upgrade
Éric Gaspar 6dacdc990a cleaning
2023-12-19 19:00:15 +01:00

144 lines
5 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# If db_name doesn't exist, create it
if [ -z "${db_name:-}" ]; then
db_name=$(ynh_sanitize_dbid --db_name=$app)
fi
# If data_dir doesn't exist, create it
if [ -z "${data_dir:-}" ]; then
data_dir=/home/yunohost.app/$app
fi
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
ynh_add_fpm_config
ynh_add_nginx_config
#=================================================
# Framaforms 2 Yakforms Backup
#=================================================
if [ "$upgrade_to_yakforms" = false ]
then
update-alternatives --set php /usr/bin/php$phpversion
upgrade_to_yakforms=true
pushd "$install_dir"
ynh_exec_as $app env PATH=$PATH php framaforms2yakforms.php backup
ynh_exec_as $app env PATH=$PATH drush @$app dis framaforms
ynh_exec_as $app env PATH=$PATH drush @$app pm-uninstall framaforms
ynh_exec_as $app env PATH=$PATH drush @$app dis framaforms_share_results
ynh_exec_as $app env PATH=$PATH drush @$app pm-uninstall framaforms_share_results
ynh_exec_as $app env PATH=$PATH drush @$app dis framaforms_public_results
ynh_exec_as $app env PATH=$PATH drush @$app pm-uninstall framaforms_public_results
ynh_exec_as $app env PATH=$PATH drush @$app dis framaforms_spam
ynh_exec_as $app env PATH=$PATH drush @$app pm-uninstall framaforms_spam
popd
update-alternatives --set php /usr/bin/php${YNH_PHP_VERSION}
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=9
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/app"
fi
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# UPGRADE COMPOSER
#=================================================
ynh_script_progression --message="Upgrading Composer..." --weight=3
ynh_install_composer --phpversion="$phpversion" --workdir="$install_dir/.composer"
export PATH="$install_dir/.composer/vendor/bin:$PATH"
#=================================================
# Framaforms 2 Yakforms Restore
#=================================================
if [ "$upgrade_to_yakforms" = true ]
then
update-alternatives --set php /usr/bin/php$phpversion
pushd "$install_dir"
ynh_exec_as $app env PATH=$PATH drush @$app en yakforms
ynh_exec_as $app env PATH=$PATH drush @$app dis yakforms_share_results
ynh_exec_as $app env PATH=$PATH drush @$app dis yakforms_public_results
ynh_exec_as $app env PATH=$PATH drush @$app dis yakforms_spam
ynh_exec_as $app env PATH=$PATH php framaforms2yakforms.php restore
ynh_exec_as $app env PATH=$PATH php framaforms2yakforms.php clean
popd
update-alternatives --set php /usr/bin/php${YNH_PHP_VERSION}
fi
#=================================================
# UPGRADE DRUPAL
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading Drupal..." --weight=30
ynh_backup_if_checksum_is_different --file="$install_dir/app/sites/default/settings.php"
update-alternatives --set php /usr/bin/php$phpversion
pushd "$install_dir"
ynh_exec_as $app env PATH=$PATH drush @$app variable-set --exact maintenance_mode 1
ynh_exec_as $app env PATH=$PATH drush @$app cache-clear all
# ynh_exec_as $app env PATH=$PATH drush @$app pm-update -y drupal
# ynh_exec_as $app env PATH=$PATH drush @$app updatedb -y
ynh_exec_as $app env PATH=$PATH drush @$app cache-clear all
ynh_exec_as $app env PATH=$PATH drush @$app variable-set --exact maintenance_mode 0
popd
update-alternatives --set php /usr/bin/php${YNH_PHP_VERSION}
fi
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
chmod 600 "$install_dir/app/sites/default/settings.php"
chown $app:$app "$install_dir/app/sites/default/settings.php"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last