1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/roundcube_ynh.git synced 2024-09-03 20:16:28 +02:00
roundcube_ynh/scripts/upgrade
Éric Gaspar f77b672795 v2
2024-01-27 00:10:48 +01:00

293 lines
11 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=2
#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? #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? with_carddav=$(ynh_app_setting_get --app=$app --key=with_carddav)
#REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#REMOVEME? language=$(ynh_app_setting_get --app=$app --key=language)
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#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)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=5
# Backup the current version of the app
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
# restore it if the upgrade fails
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#=================================================
# 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)
#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi
# 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
fi
# If with_carddav doesn't exist, create it
if [ -z "$with_carddav" ]; then
if [ -f "$install_dir/plugins/carddav/config.inc.php" ]
then
with_carddav=1
else
with_carddav=0
fi
ynh_app_setting_set --app=$app --key=with_carddav --value=$with_carddav
fi
# If language doesn't exist, create it
if [ -z "$language" ]; then
language="en_GB"
ynh_app_setting_set --app=$app --key=language --value=$language
fi
# 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
# Cleaning legacy permissions
#REMOVEME? if ynh_legacy_permissions_exists; then
#REMOVEME? ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing)
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Get the current version of roundcube
oldversion=$(grep RCMAIL_VERSION "$install_dir/program/include/iniset.php" | cut -d\' -f4)
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=3
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
fi
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=5
# Create a dedicated PHP-FPM config
ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# CONFIGURE ROUNDCUBE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Reconfiguring Roundcube..." --weight=1
deskey=$(ynh_string_random --length=24)
ynh_add_config --template="../conf/config.inc.php" --destination="$install_dir/config/config.inc.php"
#=================================================
# UPDATE DEPENDENCIES WITH COMPOSER
#=================================================
#REMOVEME? ynh_script_progression --message="Updating dependencies with Composer..." --weight=30
# Upgrade composer itself
ynh_install_composer
# Check if dependencies need to be updated with Composer
if [ -f "$install_dir/composer.json" ]
then
ynh_exec_warn_less ynh_composer_exec --commands="update"
# Update plugin-installer for Composer version 2.0
ynh_exec_warn_less ynh_composer_exec --commands="require roundcube/plugin-installer:>=0.2.0"
else
# Install composer.json
cp "$install_dir/composer.json-dist" "$install_dir/composer.json"
fi
#=================================================
# UPGRADE ADDITIONAL PLUGINS
#=================================================
ynh_script_progression --message="Upgrading additional plugins..." --weight=30
# Create logs and temp directories
mkdir -p "$install_dir/"{logs,temp}
# Install net_LDAP
ynh_composer_exec --commands="require kolab/net_ldap3"
# Update or install contextmenu and automatic_addressbook plugins
# https://plugins.roundcube.net/packages/sblaisot/automatic_addressbook
# https://plugins.roundcube.net/packages/johndoh/contextmenu
ynh_composer_exec --commands="update --no-dev --prefer-dist \
johndoh/contextmenu $contextmenu_version \
sblaisot/automatic_addressbook $automatic_addressbook_version"
installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
ynh_add_config --template="../conf/enigma.config.inc.php" --destination="$install_dir/plugins/enigma/config.inc.php"
mkdir -p "$install_dir/plugins/enigma/home"
chown -R $app:$app "$install_dir/plugins/enigma/home"
# Update or install CardDAV plugin
if [ $with_carddav -eq 1 ]
then
ynh_composer_exec --commands="require roundcube/carddav $carddav_version --with-all-dependencies"
carddav_tmp_config="../conf/carddav.config.inc.php"
carddav_server=0
# Copy the plugin configuration file
cp $install_dir/plugins/carddav/config.inc.php{.dist,}
# Look for installed and supported CardDAV servers
for carddav_app in "nextcloud" "baikal"
do
carddav_app_ids=$(yunohost app list | grep "id: $carddav_app" | grep -Po 'id: \K(.*)' || echo "")
for carddav_app_id in $carddav_app_ids
do
carddav_server=1
# Append preset configuration to the config file
cat "../conf/${carddav_app}.inc.php" >> $install_dir/plugins/carddav/config.inc.php
# Retrieve app settings and enable relevant preset
#REMOVEME? carddav_domain=$(ynh_app_setting_get --app=$carddav_app_id --key=domain)
#REMOVEME? carddav_path=$(ynh_app_setting_get --app=$carddav_app_id --key=path)
carddav_url="https://${carddav_domain}${carddav_path%/}"
ynh_replace_string --match_string="{${carddav_app}_id}" --replace_string="$carddav_app_id" --target_file="$install_dir/plugins/carddav/config.inc.php"
ynh_replace_string --match_string="{${carddav_app}_url}" --replace_string="$carddav_url" --target_file="$install_dir/plugins/carddav/config.inc.php"
done
done
# Do not actually add the carddav plugin if there's no carddav server available...
if [ $carddav_server -eq 1 ]
then
installed_plugins+=" 'carddav',"
fi
fi
#=================================================
# UPDATE ROUNDCUBE CONFIGURATION
#=================================================
ynh_script_progression --message="Updating $app configuration..." --weight=4
ynh_replace_string --match_string="^\s*// installed plugins" --replace_string="&\n $installed_plugins" --target_file="$install_dir/config/config.inc.php"
# Update JavaScript dependencies
pushd "$final_path"
COMPOSER_ALLOW_SUPERUSER=1 ./bin/update.sh --version="?" -y <<< ""
# Store the config file checksum into the app settings
ynh_store_file_checksum --file="$install_dir/config/config.inc.php"
chmod 400 "$install_dir/config/config.inc.php"
chown $app:$app "$install_dir/config/config.inc.php"
#=================================================
# UPDATE ROUNDCUBE CORE
#=================================================
ynh_script_progression --message="Updating $app core..." --weight=4
COMPOSER_ALLOW_SUPERUSER=1 ynh_exec_warn ./bin/update.sh --version=$oldversion -y
popd
fi
#=================================================
# RELOAD NGINX
#=================================================
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last