mirror of
https://github.com/YunoHost-Apps/roundcube_ynh.git
synced 2024-09-03 20:16:28 +02:00
831d2d842a
Should be merged quickly Can be really tested, and the upgrade process doesn't work with previous version.
219 lines
6.9 KiB
Bash
219 lines
6.9 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
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)
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
|
|
# If db_name doesn't exist, create it
|
|
if [ -z $db_name ]; then
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
ynh_app_setting_set $app db_name $db_name
|
|
fi
|
|
|
|
# If final_path doesn't exist, create it
|
|
if [ -z $final_path ]; then
|
|
final_path=/var/www/$app
|
|
ynh_app_setting_set $app final_path $final_path
|
|
fi
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
|
|
ynh_backup_before_upgrade # Backup the current version of the app
|
|
ynh_clean_setup () {
|
|
ynh_restore_upgradebackup # restore it if the upgrade fails
|
|
}
|
|
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
|
|
|
|
#=================================================
|
|
# CHECK THE PATH
|
|
#=================================================
|
|
|
|
# Normalize the URL path syntax
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
|
|
# jessie-backports is needed for php-net-ldap3
|
|
grep -q -R 'jessie-backports' /etc/apt/sources.list{,.d} || {
|
|
echo "deb http://httpredir.debian.org/debian jessie-backports main" \
|
|
| tee -a /etc/apt/sources.list.d/backports.list >/dev/null
|
|
}
|
|
|
|
ynh_install_app_dependencies "$pkg_dependencies"
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
|
|
# Create a system user
|
|
ynh_system_user_create $app
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
# Get the current version of roundcube
|
|
oldversion=$(grep RCMAIL_VERSION "$final_path/program/include/iniset.php" | cut -d\' -f4)
|
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source "$final_path"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
# Create a dedicated nginx config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# PHP-FPM CONFIGURATION
|
|
#=================================================
|
|
|
|
# Create a dedicated php-fpm config
|
|
ynh_add_fpm_config
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# INSTALL THE NEW ROUNDCUBE VERSION
|
|
#=================================================
|
|
|
|
# Verify the checksum and backup the file if it's different
|
|
ynh_store_file_checksum "${final_path}/config/config.inc.php"
|
|
|
|
# Get the new version of roundcube
|
|
newversion=$(grep RCMAIL_VERSION "$final_path/program/include/iniset.php" | cut -d\' -f4)
|
|
|
|
# Do the upgrade only if it's really needed
|
|
if [ "$newversion" != "$oldversion" ]
|
|
then
|
|
(cd "$final_path"
|
|
/usr/bin/php -q ./bin/installto.sh "${final_path}")
|
|
fi
|
|
|
|
#=================================================
|
|
# CONFIGURE ROUNDCUBE
|
|
#=================================================
|
|
|
|
rc_conf="${final_path}/config/config.inc.php"
|
|
cp ../conf/config.inc.php "$rc_conf"
|
|
ynh_replace_string "#DESKEY#" "$(ynh_string_random 24)" "$rc_conf"
|
|
ynh_replace_string "#DBUSER#" "$db_name" "$rc_conf"
|
|
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
|
ynh_replace_string "#DBPASS#" "$db_pwd" "$rc_conf"
|
|
ynh_replace_string "#DBNAME#" "$db_name" "$rc_conf"
|
|
|
|
#=================================================
|
|
# UPDATE DEPENDENCIES WITH COMPOSER
|
|
#=================================================
|
|
|
|
# Check if dependencies need to be updated with composer
|
|
if [[ -f ${final_path}/composer.json ]]; then
|
|
exec_composer "${final_path}" update --no-dev --prefer-dist
|
|
else
|
|
init_composer "${final_path}"
|
|
fi
|
|
|
|
#=================================================
|
|
# UPGRADE ADDITIONAL PLUGINS
|
|
#=================================================
|
|
|
|
# Create logs and temp directories
|
|
mkdir -p "${final_path}/logs" "${final_path}/temp"
|
|
|
|
# Update or install contextmenu and automatic_addressbook plugins
|
|
# https://plugins.roundcube.net/packages/sblaisot/automatic_addressbook
|
|
# https://plugins.roundcube.net/packages/johndoh/contextmenu
|
|
exec_composer "${final_path}" update --no-dev --prefer-dist \
|
|
"johndoh/contextmenu $contextmenu_version" \
|
|
"sblaisot/automatic_addressbook $automatic_addressbook_version"
|
|
installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
|
|
|
|
# Guess with_carddav value if empty
|
|
if [[ -z "${with_carddav:-}" ]]; then
|
|
[[ -f "${final_path}/plugins/carddav/config.inc.php" ]] \
|
|
&& with_carddav=1 \
|
|
|| with_carddav=0
|
|
ynh_app_setting_set "$app" with_carddav "$with_carddav"
|
|
fi
|
|
|
|
# Update or install CardDAV plugin
|
|
if [[ $with_carddav -eq 1 ]]; then
|
|
install_carddav "${final_path}" \
|
|
&& installed_plugins+=" 'carddav'," \
|
|
|| echo "Unable to install CardDAV plugin" >&2
|
|
fi
|
|
|
|
# Guess with_enigma value if empty
|
|
if [[ -z "${with_enigma:-}" ]]; then
|
|
[[ -f "${final_path}/plugins/enigma/config.inc.php" ]] \
|
|
&& with_enigma=1 \
|
|
|| with_enigma=0
|
|
ynh_app_setting_set "$app" with_enigma "$with_enigma"
|
|
fi
|
|
|
|
# Install Enigma plugin
|
|
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'," \
|
|
|| echo "Unable to install Enigma plugin" >&2
|
|
fi
|
|
|
|
#=================================================
|
|
# UPDATE ROUNDCUBE CONFIGURATION
|
|
#=================================================
|
|
|
|
sed -i "s#^\s*// installed plugins#&\n ${installed_plugins}#" \
|
|
"$rc_conf"
|
|
|
|
# Update javascript dependencies
|
|
( cd "${final_path}"
|
|
/usr/bin/php -q ./bin/install-jsdeps.sh)
|
|
|
|
# Store the config file checksum into the app settings
|
|
ynh_store_file_checksum "${final_path}/config/config.inc.php"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SECURE FILES AND DIRECTORIES
|
|
#=================================================
|
|
|
|
# Set permissions to app files
|
|
chown -R root: "$final_path"
|
|
chown -R $app: "${final_path}/temp/" "${final_path}/logs/"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
systemctl reload nginx
|