2016-03-28 22:14:19 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-05-15 17:26:39 +02:00
|
|
|
|
2017-06-02 17:15:57 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2019-03-03 18:12:41 +01:00
|
|
|
# Overload the helper ynh_handle_getopts_args to have fixes from unstable.
|
|
|
|
# Needed for composer helpers
|
|
|
|
source _getopts_fix.sh
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Loading installation settings..."
|
2017-08-26 03:24:41 +02:00
|
|
|
|
2017-06-02 17:15:57 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
db_name=$(ynh_app_setting_get $app db_name)
|
|
|
|
with_carddav=$(ynh_app_setting_get $app with_carddav)
|
|
|
|
with_enigma=$(ynh_app_setting_get $app with_enigma)
|
|
|
|
|
2017-10-13 01:45:29 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Ensuring downward compatibility..."
|
2017-10-13 01:45:29 +02:00
|
|
|
|
|
|
|
# If db_name doesn't exist, create it
|
2017-10-15 01:14:08 +02:00
|
|
|
if [ -z "$db_name" ]; then
|
2017-10-13 01:45:29 +02:00
|
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
|
|
ynh_app_setting_set $app db_name $db_name
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If final_path doesn't exist, create it
|
2017-10-15 01:14:08 +02:00
|
|
|
if [ -z "$final_path" ]; then
|
2017-10-13 01:45:29 +02:00
|
|
|
final_path=/var/www/$app
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
fi
|
|
|
|
|
2019-03-03 18:12:41 +01:00
|
|
|
# If with_carddav doesn't exist, create it
|
|
|
|
if [ -z "$with_carddav" ]; then
|
|
|
|
if [ -f "$final_path/plugins/carddav/config.inc.php" ]
|
|
|
|
then
|
|
|
|
with_carddav=1
|
|
|
|
else
|
|
|
|
with_carddav=0
|
|
|
|
fi
|
|
|
|
ynh_app_setting_set $app with_carddav $with_carddav
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If with_enigma doesn't exist, create it
|
|
|
|
if [ -z "$with_enigma" ]; then
|
|
|
|
if [ -f "${final_path}/plugins/enigma/config.inc.php" ]
|
|
|
|
then
|
|
|
|
with_enigma=1
|
|
|
|
else
|
|
|
|
with_enigma=0
|
|
|
|
fi
|
|
|
|
ynh_app_setting_set $app with_enigma $with_enigma
|
|
|
|
fi
|
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Backing up the app before upgrading (may take a while)..."
|
2017-08-26 03:24:41 +02:00
|
|
|
|
2019-03-03 18:12:41 +01:00
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
2017-06-02 17:15:57 +02:00
|
|
|
ynh_clean_setup () {
|
2019-03-03 18:12:41 +01:00
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
2017-06-02 17:15:57 +02:00
|
|
|
}
|
2019-03-03 18:12:41 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2017-08-26 03:24:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Normalize the URL path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
2017-06-02 17:15:57 +02:00
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Upgrading source files..."
|
2017-08-26 03:24:41 +02:00
|
|
|
|
|
|
|
# Get the current version of roundcube
|
|
|
|
oldversion=$(grep RCMAIL_VERSION "$final_path/program/include/iniset.php" | cut -d\' -f4)
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source "$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Upgrading nginx web server configuration..."
|
2017-08-26 03:24:41 +02:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2019-03-03 18:12:41 +01:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Upgrading dependencies..."
|
2019-03-03 18:12:41 +01:00
|
|
|
|
|
|
|
ynh_install_app_dependencies "$pkg_dependencies"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Making sure dedicated system user exists..."
|
2019-03-03 18:12:41 +01:00
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create $app
|
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Upgrading php-fpm configuration..."
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
# Create a dedicated php-fpm config
|
|
|
|
ynh_add_fpm_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2017-10-15 01:14:08 +02:00
|
|
|
# CONFIGURE ROUNDCUBE
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Reconfiguring roundcube..."
|
2017-08-26 03:24:41 +02:00
|
|
|
|
2019-03-03 18:12:41 +01:00
|
|
|
rc_conf="$final_path/config/config.inc.php"
|
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
# Verify the checksum and backup the file if it's different
|
2019-03-03 18:12:41 +01:00
|
|
|
ynh_backup_if_checksum_is_different "$rc_conf"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-06-02 17:15:57 +02:00
|
|
|
cp ../conf/config.inc.php "$rc_conf"
|
2019-03-03 18:12:41 +01:00
|
|
|
|
|
|
|
ynh_replace_string "__DESKEY__" "$(ynh_string_random 24)" "$rc_conf"
|
|
|
|
ynh_replace_string "__DBUSER__" $db_name "$rc_conf"
|
2017-08-26 03:24:41 +02:00
|
|
|
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
2019-03-03 18:12:41 +01:00
|
|
|
ynh_replace_string "__DBPASS__" "$db_pwd" "$rc_conf"
|
|
|
|
ynh_replace_string "__DBNAME__" $db_name "$rc_conf"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# UPDATE DEPENDENCIES WITH COMPOSER
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Updating dependencies with composer..."
|
2016-03-28 22:14:19 +02:00
|
|
|
|
|
|
|
# Check if dependencies need to be updated with composer
|
2019-03-03 18:12:41 +01:00
|
|
|
if [ -f "$final_path/composer.json" ]
|
|
|
|
then
|
|
|
|
ynh_exec_warn_less ynh_composer_exec --commands=\"update --no-dev --prefer-dist\"
|
2016-03-28 22:14:19 +02:00
|
|
|
else
|
2019-03-03 18:12:41 +01:00
|
|
|
# Install composer.json
|
|
|
|
cp "$final_path/composer.json-dist" "$final_path/composer.json"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2019-03-03 18:12:41 +01:00
|
|
|
# Install composer
|
|
|
|
ynh_install_composer
|
|
|
|
fi
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE ADDITIONAL PLUGINS
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Upgrading additional plugins..."
|
2017-08-26 03:24:41 +02:00
|
|
|
|
|
|
|
# Create logs and temp directories
|
2019-03-03 18:12:41 +01:00
|
|
|
mkdir -p "$final_path/"{logs,temp}
|
2017-08-26 03:24:41 +02:00
|
|
|
|
|
|
|
# Update or install contextmenu and automatic_addressbook plugins
|
|
|
|
# https://plugins.roundcube.net/packages/sblaisot/automatic_addressbook
|
|
|
|
# https://plugins.roundcube.net/packages/johndoh/contextmenu
|
2019-03-03 18:12:41 +01:00
|
|
|
ynh_composer_exec --commands="update --no-dev --prefer-dist \
|
|
|
|
johndoh/contextmenu $contextmenu_version \
|
|
|
|
sblaisot/automatic_addressbook $automatic_addressbook_version"
|
2016-03-30 14:38:37 +02:00
|
|
|
|
2019-03-03 18:12:41 +01:00
|
|
|
installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
|
2016-05-15 23:51:33 +02:00
|
|
|
|
2017-06-19 00:16:34 +02:00
|
|
|
# Update or install CardDAV plugin
|
2019-03-03 18:12:41 +01:00
|
|
|
if [ $with_carddav -eq 1 ]
|
|
|
|
then
|
|
|
|
ynh_composer_exec --commands="require roundcube/carddav $carddav_version"
|
|
|
|
|
|
|
|
carddav_tmp_config="../conf/carddav.config.inc.php"
|
|
|
|
|
|
|
|
# Look for installed and supported CardDAV servers
|
2019-03-04 15:23:53 +01:00
|
|
|
for carddav_app in "owncloud" "nextcloud" "baikal"
|
2019-03-03 18:12:41 +01:00
|
|
|
do
|
|
|
|
carddav_app_id=$(yunohost app list --installed -f $carddav_app \
|
|
|
|
--output-as json | grep -Po '"id":[ ]?"\K.*?(?=")' | head -1)
|
|
|
|
if [ -n "$carddav_app_id" ]
|
|
|
|
then
|
|
|
|
# Retrieve app settings and enable relevant preset
|
|
|
|
carddav_domain=$(ynh_app_setting_get $carddav_app_id domain)
|
|
|
|
carddav_path=$(ynh_app_setting_get $carddav_app_id path)
|
|
|
|
carddav_url="https://${carddav_domain}${carddav_path%/}"
|
|
|
|
ynh_replace_string "{${carddav_app}_url}" "$carddav_url" "$carddav_tmp_config"
|
2019-03-05 00:47:16 +01:00
|
|
|
ynh_replace_string "\/\* PRESET FOR: $carddav_app" "" "$carddav_tmp_config"
|
|
|
|
ynh_replace_string "END: $carddav_app \*\/" "" "$carddav_tmp_config"
|
2019-03-03 18:12:41 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Copy the plugin configuration file
|
|
|
|
cp "$carddav_tmp_config" ""$final_path/plugins/carddav/config.inc.php""
|
|
|
|
|
|
|
|
installed_plugins+=" 'carddav',"
|
2017-07-03 15:05:22 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Install Enigma plugin
|
2019-03-03 18:12:41 +01:00
|
|
|
if [ $with_enigma -eq 1 ]
|
|
|
|
then
|
|
|
|
cp -a "$final_path/plugins/enigma/config.inc.php.dist" "$final_path/plugins/enigma/config.inc.php" \
|
|
|
|
&& installed_plugins+=" 'enigma'," \
|
|
|
|
|| ynh_print_warn "Unable to install Enigma plugin"
|
2017-07-03 15:05:22 +02:00
|
|
|
fi
|
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# UPDATE ROUNDCUBE CONFIGURATION
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Updating roundcube configuration..."
|
2017-08-26 03:24:41 +02:00
|
|
|
|
2019-03-03 18:12:41 +01:00
|
|
|
ynh_replace_string "^\s*// installed plugins" "&\n $installed_plugins" "$rc_conf"
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-07-03 13:12:59 +02:00
|
|
|
# Update javascript dependencies
|
2019-03-03 18:12:41 +01:00
|
|
|
(cd "$final_path"
|
2017-08-26 03:24:41 +02:00
|
|
|
/usr/bin/php -q ./bin/install-jsdeps.sh)
|
|
|
|
|
|
|
|
# Store the config file checksum into the app settings
|
2019-03-03 18:12:41 +01:00
|
|
|
ynh_store_file_checksum "$rc_conf"
|
2017-07-03 13:12:59 +02:00
|
|
|
|
2017-10-15 01:14:08 +02:00
|
|
|
#=================================================
|
|
|
|
# UPDATE ROUNDCUBE CORE
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Updating roundcube core..."
|
2017-10-15 01:14:08 +02:00
|
|
|
|
2019-03-03 18:12:41 +01:00
|
|
|
( cd "$final_path"
|
|
|
|
ynh_exec_warn ./bin/update.sh --version=$oldversion -y)
|
2017-10-15 01:14:08 +02:00
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2017-06-18 17:09:53 +02:00
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
# Set permissions to app files
|
|
|
|
chown -R root: "$final_path"
|
2019-03-03 18:12:41 +01:00
|
|
|
chown -R $app: "$final_path/"{temp,logs,plugins/enigma/home}
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-03-03 18:13:57 +01:00
|
|
|
ynh_print_info "Reloading nginx web server..."
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
systemctl reload nginx
|
2019-03-03 18:13:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_print_info "Upgrade of $app completed"
|