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
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-05-18 18:42:54 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=2
|
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
|
|
|
|
2019-05-18 18:42:54 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
2021-03-26 08:30:02 +01:00
|
|
|
db_user=$db_name
|
2019-05-18 18:42:54 +02:00
|
|
|
with_carddav=$(ynh_app_setting_get --app=$app --key=with_carddav)
|
2021-06-12 19:41:36 +02:00
|
|
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
2020-11-20 22:06:07 +01:00
|
|
|
language=$(ynh_app_setting_get --app=$app --key=language)
|
2021-02-25 23:43:48 +01:00
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
2019-05-18 18:42:54 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2017-08-26 03:24:41 +02:00
|
|
|
|
2021-08-18 21:46:27 +02:00
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-10-13 01:45:29 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2021-08-18 21:46:27 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
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
|
2019-05-18 18:42:54 +02:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
2017-10-13 01:45:29 +02:00
|
|
|
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
|
2019-05-18 18:42:54 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2017-10-13 01:45:29 +02:00
|
|
|
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
|
2019-05-18 18:42:54 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=with_carddav --value=$with_carddav
|
2019-03-03 18:12:41 +01:00
|
|
|
fi
|
|
|
|
|
2020-11-20 22:06:07 +01:00
|
|
|
# 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
|
|
|
|
|
2021-05-07 23:41:14 +02:00
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
|
|
|
|
2021-03-22 19:33:07 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2021-08-18 21:46:27 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
2021-03-22 19:33:07 +01:00
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Get the current version of roundcube
|
|
|
|
oldversion=$(grep RCMAIL_VERSION "$final_path/program/include/iniset.php" | cut -d\' -f4)
|
|
|
|
|
2019-05-18 18:42:54 +02:00
|
|
|
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="$final_path"
|
|
|
|
fi
|
2017-08-26 03:24:41 +02:00
|
|
|
|
2021-10-19 12:45:44 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-08-18 21:46:27 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
2017-08-26 03:24:41 +02:00
|
|
|
|
2020-09-27 22:39:12 +02:00
|
|
|
# Create a dedicated NGINX config
|
2017-08-26 03:24:41 +02:00
|
|
|
ynh_add_nginx_config
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2021-11-14 19:51:40 +01:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
|
|
|
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2020-09-27 22:39:12 +02:00
|
|
|
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=5
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2020-09-27 22:39:12 +02:00
|
|
|
# Create a dedicated PHP-FPM config
|
2021-11-14 19:51:40 +01:00
|
|
|
ynh_add_fpm_config
|
2017-08-26 03:24:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2017-10-15 01:14:08 +02:00
|
|
|
# CONFIGURE ROUNDCUBE
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
2016-05-15 23:51:33 +02:00
|
|
|
|
2019-05-18 18:42:54 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
2019-03-03 18:12:41 +01:00
|
|
|
then
|
2021-08-18 21:46:27 +02:00
|
|
|
ynh_script_progression --message="Reconfiguring Roundcube..." --weight=1
|
2019-05-18 18:42:54 +02:00
|
|
|
|
2021-10-19 00:09:31 +02:00
|
|
|
deskey=$(ynh_string_random --length=24)
|
|
|
|
ynh_add_config --template="../conf/config.inc.php" --destination="$final_path/config/config.inc.php"
|
2020-11-09 16:50:06 +01:00
|
|
|
|
2019-05-18 18:42:54 +02:00
|
|
|
#=================================================
|
|
|
|
# UPDATE DEPENDENCIES WITH COMPOSER
|
|
|
|
#=================================================
|
2020-09-27 22:39:12 +02:00
|
|
|
ynh_script_progression --message="Updating dependencies with Composer..." --weight=30
|
2019-05-18 18:42:54 +02:00
|
|
|
|
2019-05-26 12:02:42 +02:00
|
|
|
# Upgrade composer itself
|
|
|
|
ynh_install_composer
|
|
|
|
|
2020-09-27 22:39:12 +02:00
|
|
|
# Check if dependencies need to be updated with Composer
|
2019-05-18 18:42:54 +02:00
|
|
|
if [ -f "$final_path/composer.json" ]
|
|
|
|
then
|
2021-10-19 12:45:44 +02:00
|
|
|
ynh_exec_warn_less ynh_composer_exec --commands="update"
|
2019-05-18 18:42:54 +02:00
|
|
|
else
|
|
|
|
# Install composer.json
|
|
|
|
cp "$final_path/composer.json-dist" "$final_path/composer.json"
|
|
|
|
fi
|
2021-02-26 00:00:04 +01:00
|
|
|
|
2019-05-18 18:42:54 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE ADDITIONAL PLUGINS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading additional plugins..." --weight=30
|
|
|
|
|
|
|
|
# Create logs and temp directories
|
|
|
|
mkdir -p "$final_path/"{logs,temp}
|
|
|
|
|
2020-04-24 13:59:22 +02:00
|
|
|
# Install net_LDAP
|
2021-10-19 11:50:11 +02:00
|
|
|
ynh_composer_exec --commands="require kolab/net_ldap3"
|
2020-04-24 13:59:22 +02:00
|
|
|
|
2019-05-18 18:42:54 +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
|
|
|
|
ynh_composer_exec --commands="update --no-dev --prefer-dist \
|
|
|
|
johndoh/contextmenu $contextmenu_version \
|
|
|
|
sblaisot/automatic_addressbook $automatic_addressbook_version"
|
|
|
|
|
2021-08-27 12:18:01 +02:00
|
|
|
installed_plugins+=" 'contextmenu', 'automatic_addressbook',"
|
2021-08-27 12:09:03 +02:00
|
|
|
|
|
|
|
ynh_add_config --template="../conf/enigma.config.inc.php" --destination="$final_path/plugins/enigma/config.inc.php"
|
|
|
|
mkdir -p "$final_path/plugins/enigma/home"
|
|
|
|
chown -R $app:$app "$final_path/plugins/enigma/home"
|
2019-05-18 18:42:54 +02:00
|
|
|
|
|
|
|
# Update or install CardDAV plugin
|
|
|
|
if [ $with_carddav -eq 1 ]
|
|
|
|
then
|
|
|
|
ynh_composer_exec --commands="require roundcube/carddav $carddav_version"
|
|
|
|
|
|
|
|
carddav_tmp_config="../conf/carddav.config.inc.php"
|
2020-04-24 13:34:42 +02:00
|
|
|
carddav_server=0
|
2019-05-18 18:42:54 +02:00
|
|
|
|
2020-11-22 14:05:49 +01:00
|
|
|
# Copy the plugin configuration file
|
|
|
|
cp $final_path/plugins/carddav/config.inc.php{.dist,}
|
|
|
|
|
2019-05-18 18:42:54 +02:00
|
|
|
# Look for installed and supported CardDAV servers
|
2020-09-27 22:39:12 +02:00
|
|
|
for carddav_app in "nextcloud" "baikal"
|
2019-05-18 18:42:54 +02:00
|
|
|
do
|
2020-11-22 14:05:49 +01:00
|
|
|
carddav_app_ids=$(yunohost app list | grep "id: $carddav_app" | grep -Po 'id: \K(.*)' || echo "")
|
|
|
|
for carddav_app_id in $carddav_app_ids
|
|
|
|
do
|
2020-04-24 13:34:42 +02:00
|
|
|
carddav_server=1
|
2020-11-22 14:05:49 +01:00
|
|
|
# Append preset configuration to the config file
|
|
|
|
cat "../conf/${carddav_app}.inc.php" >> $final_path/plugins/carddav/config.inc.php
|
2019-05-18 18:42:54 +02:00
|
|
|
# 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%/}"
|
2020-11-22 14:05:49 +01:00
|
|
|
ynh_replace_string --match_string="{${carddav_app}_id}" --replace_string="$carddav_app_id" --target_file="$final_path/plugins/carddav/config.inc.php"
|
|
|
|
ynh_replace_string --match_string="{${carddav_app}_url}" --replace_string="$carddav_url" --target_file="$final_path/plugins/carddav/config.inc.php"
|
|
|
|
done
|
2019-05-18 18:42:54 +02:00
|
|
|
done
|
|
|
|
|
2020-11-22 14:05:49 +01:00
|
|
|
# Do not actually add the carddav plugin if there's no carddav server available...
|
2020-04-24 13:34:42 +02:00
|
|
|
if [ $carddav_server -eq 1 ]
|
|
|
|
then
|
|
|
|
installed_plugins+=" 'carddav',"
|
|
|
|
fi
|
2019-05-18 18:42:54 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPDATE ROUNDCUBE CONFIGURATION
|
|
|
|
#=================================================
|
2020-11-02 17:47:49 +01:00
|
|
|
ynh_script_progression --message="Updating $app configuration..." --weight=4
|
2019-05-18 18:42:54 +02:00
|
|
|
|
2021-03-22 19:33:07 +01:00
|
|
|
ynh_replace_string --match_string="^\s*// installed plugins" --replace_string="&\n $installed_plugins" --target_file="$final_path/config/config.inc.php"
|
2019-05-18 18:42:54 +02:00
|
|
|
|
2020-09-27 22:39:12 +02:00
|
|
|
# Update JavaScript dependencies
|
2019-05-18 18:42:54 +02:00
|
|
|
(cd "$final_path"
|
2021-06-08 14:04:30 +02:00
|
|
|
/usr/bin/php$phpversion -q ./bin/install-jsdeps.sh)
|
2019-05-18 18:42:54 +02:00
|
|
|
|
2021-08-18 19:20:42 +02:00
|
|
|
# Store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum --file="$final_path/config/config.inc.php"
|
|
|
|
|
2021-05-28 21:14:54 +02:00
|
|
|
chmod 400 "$final_path/config/config.inc.php"
|
|
|
|
chown $app:$app "$final_path/config/config.inc.php"
|
|
|
|
|
2019-05-18 18:42:54 +02:00
|
|
|
#=================================================
|
|
|
|
# UPDATE ROUNDCUBE CORE
|
|
|
|
#=================================================
|
2020-11-02 17:47:49 +01:00
|
|
|
ynh_script_progression --message="Updating $app core..." --weight=4
|
2019-05-18 18:42:54 +02:00
|
|
|
|
|
|
|
( cd "$final_path"
|
2021-02-26 00:12:36 +01:00
|
|
|
ynh_exec_warn ./bin/update.sh --version=$oldversion -y)
|
2017-07-03 15:05:22 +02:00
|
|
|
fi
|
|
|
|
|
2017-08-26 03:24:41 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2021-08-18 21:46:27 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2016-03-28 22:14:19 +02:00
|
|
|
|
2019-05-18 18:42:54 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-03-03 18:13:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-11-02 17:47:49 +01:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|