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
Alexandre Aubin 198dce221f Helpers 2.1
2024-07-18 16:56:29 +02:00

164 lines
5.9 KiB
Bash

#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
ynh_app_setting_set_default --key=php_upload_max_filesize --value=256M
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression "Ensuring downward compatibility..."
# If with_carddav doesn't exist, create it
if [ -z "${with_carddav:-}" ]; then
if [ -f "$install_dir/plugins/carddav/config.inc.php" ]
then
ynh_app_setting_set_default --key=with_carddav --value="1"
else
ynh_app_setting_set_default --key=with_carddav --value="0"
fi
fi
# If language doesn't exist, create it
ynh_app_setting_set_default --key=language --value="en_GB"
# Get the current version of roundcube
oldversion=$(grep RCMAIL_VERSION "$install_dir/program/include/iniset.php" | cut -d\' -f4)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
#=================================================
# 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
#=================================================
# CONFIGURE ROUNDCUBE
#=================================================
ynh_script_progression "Reconfiguring Roundcube..."
deskey=$(ynh_string_random --length=24)
ynh_config_add --template="config.inc.php" --destination="$install_dir/config/config.inc.php"
#=================================================
# UPDATE DEPENDENCIES WITH COMPOSER
#=================================================
ynh_script_progression "Updating dependencies with Composer..."
# Upgrade composer itself
ynh_composer_install
ynh_composer_exec install --no-dev
# Check if dependencies need to be updated with Composer
if [ -f "$install_dir/composer.json" ]
then
ynh_composer_exec update
# Update plugin-installer for Composer version 2.0
ynh_composer_exec 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 "Upgrading additional plugins..."
# Create logs and temp directories
mkdir -p "$install_dir/"{logs,temp}
# Install net_LDAP
ynh_composer_exec 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 update --no-dev --prefer-dist \
johndoh/contextmenu $contextmenu_version \
sblaisot/automatic_addressbook $automatic_addressbook_version
installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
ynh_config_add --template="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 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
carddav_domain=$(ynh_app_setting_get --app=$carddav_app_id --key=domain)
carddav_path=$(ynh_app_setting_get --app=$carddav_app_id --key=path)
carddav_url="https://${carddav_domain}${carddav_path%/}"
ynh_replace --match="{${carddav_app}_id}" --replace="$carddav_app_id" --file="$install_dir/plugins/carddav/config.inc.php"
ynh_replace --match="{${carddav_app}_url}" --replace="$carddav_url" --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 "Updating $app configuration..."
ynh_replace --match="^\s*// installed plugins" --replace="&\n $installed_plugins" --file="$install_dir/config/config.inc.php"
# Update JavaScript dependencies
pushd "$install_dir"
COMPOSER_ALLOW_SUPERUSER=1 "php$php_version" ./bin/update.sh --version="?" -y <<< ""
# Store the config file checksum into the app settings
ynh_store_file_checksum "$install_dir/config/config.inc.php"
#=================================================
# UPDATE ROUNDCUBE CORE
#=================================================
ynh_script_progression "Updating $app core..."
COMPOSER_ALLOW_SUPERUSER=1 ynh_exec_warn "php$php_version" ./bin/update.sh --version=$oldversion -y
popd
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression "Installation of $app completed"