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

136 lines
5.1 KiB
Bash

#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
ynh_app_setting_set_default --key=php_upload_max_filesize --value=1G
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression "Ensuring downward compatibility..."
# If fpm_footprint doesn't exist, create it
if [ -z "${fpm_footprint:-}" ]; then
fpm_footprint=low
#REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | ynh_app_setting_set --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
#REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | ynh_app_setting_set --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
#REMOVEME? Everything about fpm_usage is removed in helpers2.1... | ynh_app_setting_set --key=fpm_usage --value=$fpm_usage
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Deactivate cron jobs
ynh_safe_rm "/etc/cron.d/$app"
# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed
if ynh_app_upstream_version_changed
then
ynh_script_progression "Upgrading source files..."
# Backup user contents
mv "$install_dir" "$install_dir.old"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
# Restore user contents
cp -a "$install_dir.old/uploads/." "$install_dir/uploads/."
cp -a "$install_dir.old/protected/runtime" "$install_dir/protected/runtime"
cp -a "$install_dir.old/protected/config/." "$install_dir/protected/config/"
cp -a "$install_dir.old/protected/modules/." "$install_dir/protected/modules/"
cp -a "$install_dir.old/themes/." "$install_dir/themes/"
# Delete old source
ynh_safe_rm "$install_dir.old"
fi
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression "Upgrading PHP-FPM configuration..."
# Create a dedicated PHP-FPM config
ynh_config_add_phpfpm
# Create a dedicated NGINX config
ynh_config_add_nginx
#=================================================
# DEACTIVATE DEBUG MODE
#=================================================
ynh_replace --match="defined('YII_DEBUG') or define('YII_DEBUG', true);"\
--replace="// defined('YII_DEBUG') or define('YII_DEBUG', true);"\
--file="$install_dir/index.php"
ynh_replace --match="defined('YII_ENV') or define('YII_ENV', 'dev');"\
--replace="// defined('YII_ENV') or define('YII_ENV', 'dev');"\
--file="$install_dir/index.php"
#=================================================
# SETUP APPLICATION
#=================================================
# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed
if ynh_app_upstream_version_changed
then
ynh_script_progression "Setuping application..."
if [[ ! -d $install_dir/$HUMHUB_AUTH_BASIC_PATH ]]; then
install_sso
pushd $install_dir/protected
php$php_version yii module/enable auth-basic
popd
else
current_version=$(cat $install_dir/$HUMHUB_AUTH_BASIC_PATH/module.json | jq -j '.version')
if [ "$current_version" != "$HUMHUB_AUTH_BASIC_VERSION" ]; then
ynh_safe_rm $install_dir/$HUMHUB_AUTH_BASIC_PATH
install_sso
fi
fi
fi
#=================================================
# MIGRATE DATABASE
#=================================================
ynh_script_progression "Migrating database..."
chown -R $app $install_dir/
ynh_exec_as_app /usr/bin/php$php_version $install_dir/protected/yii migrate/up --includeModuleMigrations=1 --interactive=0
#=================================================
# UPDATE MODULES
#=================================================
ynh_script_progression "Updating modules..."
ynh_exec_as_app /usr/bin/php$php_version $install_dir/protected/yii module/update-all --interactive=0
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir"
#=================================================
# UPGRADE CRONTAB
#=================================================
ynh_script_progression "Upgrading crontab..."
ynh_config_add --template="cron" --destination="/etc/cron.d/${app}"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression "Upgrade of $app completed"