2019-02-28 00:12:48 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2020-04-17 14:38:01 +02:00
ynh_script_progression --message="Loading installation settings..."
2019-02-28 00:12:48 +01:00
app=$YNH_APP_INSTANCE_NAME
2020-04-17 14:38:01 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
password=$(ynh_app_setting_get --app=$app --key=password)
master_key=$(ynh_app_setting_get --app=$app --key=master_key)
2019-02-28 00:12:48 +01:00
2020-04-17 14:38:01 +02:00
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
2019-11-10 12:53:41 +01:00
2019-02-28 00:12:48 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-04-17 14:38:01 +02:00
ynh_script_progression --message="Ensuring downward compatibility..."
2019-02-28 00:12:48 +01:00
# If db_name doesn't exist, create it
2020-04-17 14:38:01 +02:00
if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
2019-02-28 00:12:48 +01:00
fi
# If final_path doesn't exist, create it
2020-04-17 14:38:01 +02:00
if [ -z "$final_path" ]; then
2019-02-28 00:12:48 +01:00
final_path=/var/www/$app
2020-04-17 14:38:01 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2019-02-28 00:12:48 +01:00
fi
2020-04-17 14:38:01 +02:00
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
2019-11-10 12:53:41 +01:00
2020-04-17 14:38:01 +02:00
if [ -n "$is_public" ]; then
ynh_app_setting_delete --app=$app --key=protected_uris
2019-11-10 12:53:41 +01:00
2020-04-17 14:38:01 +02:00
# Removing skipped/unprotected_uris under certain conditions, remove the visitors group added during the migration process of 3.7
2020-04-17 16:21:07 +02:00
# Remove unprotected_uris. If the app was public, add visitors again to the main permission
2020-04-17 14:38:01 +02:00
if ynh_permission_has_user --permission=main --user=visitors
then
2020-04-17 16:21:07 +02:00
ynh_app_setting_delete --app=$app --key=unprotected_uris
2020-03-27 11:50:56 +01:00
ynh_permission_update --permission "main" --add "visitors"
2020-04-17 14:38:01 +02:00
else
2020-04-17 16:21:07 +02:00
ynh_app_setting_delete --app=$app --key=unprotected_uris
2020-03-27 11:50:56 +01:00
fi
ynh_app_setting_delete --app=$app --key=is_public
fi
2019-02-28 00:12:48 +01:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2020-04-17 14:38:01 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=4
2019-02-28 00:12:48 +01:00
# 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
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
2020-04-17 14:38:01 +02:00
path_url=$(ynh_normalize_url_path --path_url=$path_url)
2019-02-28 00:12:48 +01:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2020-04-17 14:38:01 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=4
2019-02-28 00:12:48 +01:00
2020-04-17 14:38:01 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
# Download, check integrity, uncompress and patch the source from app.src
# In case of a new version, the url change from http://download.dotclear.org/latest/dotclear-X.X.X.tar.gz to http://download.dotclear.org/attic/dotclear-X.X.X.tar.gz
src_url=$(grep 'SOURCE_URL=' "../conf/app.src" | cut -d= -f2-)
if ! curl --output /dev/null --silent --head --fail "$src_url"; then
ynh_replace_string "latest" "attic" ../conf/app.src
fi
2019-02-28 00:12:48 +01:00
2020-04-17 14:38:01 +02:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
2019-09-08 01:33:05 +02:00
fi
2019-02-28 00:12:48 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-04-17 14:38:01 +02:00
ynh_script_progression --message="Upgrading nginx web server configuration..."
2019-02-28 00:12:48 +01:00
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
2020-04-17 14:38:01 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..."
2019-02-28 00:12:48 +01:00
# Create a dedicated user (if not existing)
2020-04-17 14:38:01 +02:00
ynh_system_user_create --username=$app
2019-02-28 00:12:48 +01:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2020-04-17 14:38:01 +02:00
ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=2
2019-02-28 00:12:48 +01:00
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
2020-04-17 14:38:01 +02:00
# MODIFY A CONFIG FILE
2019-02-28 00:12:48 +01:00
#=================================================
2020-04-17 14:38:01 +02:00
php_config=$final_path/inc/config.php
ynh_backup_if_checksum_is_different --file=$php_config
2019-02-28 00:12:48 +01:00
cp $php_config.in $php_config
2020-04-17 14:38:01 +02:00
admin_url="${path_url%/}/admin/index.php"
email=$(ynh_user_get_info --username=$admin --key=mail)
2019-02-28 00:12:48 +01:00
# Config as if we called in admin/install/wizard.php
2020-04-17 14:38:01 +02:00
ynh_replace_string --match_string="'DC_DBDRIVER', ''" --replace_string="'DC_DBDRIVER', 'mysqli'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBHOST', ''" --replace_string="'DC_DBHOST', 'localhost'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBUSER', ''" --replace_string="'DC_DBUSER', '$db_user'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBPASSWORD', ''" --replace_string="'DC_DBPASSWORD', '$db_pwd'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBNAME', ''" --replace_string="'DC_DBNAME', '$db_name'" --target_file=$php_config
ynh_replace_string --match_string="'DC_MASTER_KEY', ''" --replace_string="'DC_MASTER_KEY', '$master_key'" --target_file=$php_config
ynh_replace_string --match_string="'DC_ADMIN_URL', ''" --replace_string="'DC_ADMIN_URL', 'https://$domain$admin_url'" --target_file=$php_config
ynh_replace_string --match_string="'DC_ADMIN_MAILFROM', ''" --replace_string="'DC_ADMIN_MAILFROM', '$email'" --target_file=$php_config
2019-02-28 00:12:48 +01:00
2019-03-01 02:05:03 +01:00
# Adding LDAP login
2020-04-17 14:38:01 +02:00
cp ../conf/class.auth.ldap.php $final_path/inc/class.auth.ldap.php
ynh_replace_string "__APP__" "$app" $final_path/inc/class.auth.ldap.php
2019-03-01 02:05:03 +01:00
cat << EOF >> $php_config
2020-04-17 23:49:35 +02:00
\$__autoload['ldapDcAuth'] = dirname(__FILE__).'/class.auth.ldap.php';
define('DC_AUTH_CLASS','ldapDcAuth');
2019-03-01 02:05:03 +01:00
EOF
2019-02-28 00:12:48 +01:00
# Recalculate and store the checksum of the file for the next upgrade.
2020-04-17 14:38:01 +02:00
ynh_store_file_checksum --file=$php_config
2019-02-28 00:12:48 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
2020-04-18 00:37:11 +02:00
chown -R root: $final_path
chown -R $app $final_path/{public,cache,themes,plugins}
2019-02-28 00:12:48 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2020-04-17 14:38:01 +02:00
ynh_script_progression --message="Upgrading permissions configuration..." --weight=2
2019-02-28 00:12:48 +01:00
2020-04-17 14:38:01 +02:00
# Create the admin permission if needed
2019-11-19 09:38:33 +01:00
if ! ynh_permission_exists --permission "admin"; then
ynh_permission_create --permission "admin" --url "/admin" --allowed $admin
2019-02-28 00:12:48 +01:00
fi
#=================================================
# RELOAD NGINX
#=================================================
2020-04-17 14:38:01 +02:00
ynh_script_progression --message="Reloading nginx web server..."
2019-02-28 00:12:48 +01:00
2020-04-17 14:38:01 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2019-02-28 00:12:48 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2020-04-17 14:38:01 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last