2017-04-24 04:16:02 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-02-02 17:02:25 +01:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2022-09-27 12:09:16 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
2019-06-16 00:06:51 +02:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2019-07-05 22:34:21 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2019-06-16 00:06:51 +02:00
|
|
|
|
2020-09-28 02:00:16 +02:00
|
|
|
# If fpm_footprint doesn't exist, create it
|
2023-05-22 08:35:38 +02:00
|
|
|
if [ -z "${fpm_footprint:-}" ]; then
|
|
|
|
fpm_footprint=low
|
2024-01-24 16:26:05 +01:00
|
|
|
ynh_app_setting_set --app="$app" --key=fpm_footprint --value=$fpm_footprint
|
2020-09-28 02:00:16 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If fpm_usage doesn't exist, create it
|
2023-05-22 08:35:38 +02:00
|
|
|
if [ -z "${fpm_usage:-}" ]; then
|
|
|
|
fpm_usage=low
|
2024-01-24 16:26:05 +01:00
|
|
|
ynh_app_setting_set --app="$app" --key=fpm_usage --value=$fpm_usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
charset=$(mysql -ss -N -e "SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = '$db_name'")
|
|
|
|
if [ "$charset" != "utf8" ]; then
|
|
|
|
ynh_print_info --message="Changing Database charset to utf8"
|
|
|
|
ynh_mysql_execute_as_root --sql="ALTER DATABASE $db_name charset=utf8"
|
|
|
|
ynh_local_curl "/install/repair.php" "force_utf8_on_tables=confirmed" > "/var/log/$app/repair.html"
|
|
|
|
ynh_exec_fully_quiet sleep 5
|
2020-09-28 02:00:16 +02:00
|
|
|
fi
|
|
|
|
|
2019-06-16 00:06:51 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-01-07 14:24:42 +01:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
2019-06-16 00:06:51 +02:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
2021-01-07 14:09:35 +01:00
|
|
|
ynh_add_nginx_config
|
2019-06-16 00:06:51 +02:00
|
|
|
|
2021-03-24 15:39:00 +01:00
|
|
|
# Recreate a dedicated PHP-FPM config
|
2024-01-24 16:26:05 +01:00
|
|
|
ynh_add_fpm_config --usage="$fpm_usage" --footprint="$fpm_footprint"
|
2020-09-28 01:07:01 +02:00
|
|
|
|
2019-06-16 00:06:51 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2022-09-27 12:09:16 +02:00
|
|
|
# MAKE SEQUENTIAL UPGRADES FROM EACH MAJOR
|
|
|
|
# VERSION TO THE NEXT ONE
|
2019-06-16 00:06:51 +02:00
|
|
|
#=================================================
|
2024-01-24 16:26:05 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=60
|
|
|
|
|
|
|
|
upgrade_dolibarr() {
|
|
|
|
ynh_setup_source --source_id="$source_id" --dest_dir="$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R "$app:www-data" "$install_dir"
|
|
|
|
|
|
|
|
# Remove the lock if it exists
|
|
|
|
lock=$install_dir/documents/install.lock
|
|
|
|
if [ -f "$lock" ]; then
|
|
|
|
ynh_secure_remove --file="$lock"
|
|
|
|
fi
|
|
|
|
|
|
|
|
pushd "$install_dir/htdocs/install/"
|
|
|
|
"php$phpversion" upgrade.php "$current_version" "$new_version"
|
|
|
|
ynh_exec_fully_quiet sleep 5
|
|
|
|
|
|
|
|
"php$phpversion" upgrade2.php "$current_version" "$new_version"
|
|
|
|
ynh_exec_fully_quiet sleep 5
|
|
|
|
|
|
|
|
"php$phpversion" step5.php "$current_version" "$new_version"
|
|
|
|
ynh_exec_fully_quiet sleep 5
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
# Sort --version-sort cdécembrean handle underscore in versions numbers
|
|
|
|
mapfile -t main_versions < <(
|
|
|
|
ynh_read_manifest --key="resources.sources | keys[]" | grep "main_" | sort --version-sort
|
|
|
|
)
|
|
|
|
current_version="$YNH_APP_CURRENT_VERSION"
|
|
|
|
for version in "${main_versions[@]}"; do
|
|
|
|
new_version=$(echo "$version" | sed 's|main_||' | sed 's|_|.|g')
|
|
|
|
if dpkg --compare-versions "$current_version" ge "$new_version"; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
ynh_print_info --message="Upgrading app from $current_version to $new_version"
|
|
|
|
upgrade_dolibarr
|
|
|
|
current_version="$new_version"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Final upgrade to the final version
|
|
|
|
new_version=$(ynh_app_upstream_version)
|
|
|
|
ynh_print_info --message="Upgrading app from $current_version to $new_version"
|
|
|
|
upgrade_dolibarr
|
|
|
|
|
|
|
|
if "php$phpversion" "$install_dir/scripts/user/sync_users_ldap2dolibarr.php" commitiferror --server=localhost -y; then
|
|
|
|
ynh_print_info --message="LDAP user update ok"
|
|
|
|
else
|
|
|
|
ynh_print_info --message="LDAP user update ended with error"
|
2019-06-16 00:06:51 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
|
|
#=================================================
|
|
|
|
|
2023-05-22 08:21:08 +02:00
|
|
|
ynh_backup_if_checksum_is_different --file="$install_dir/htdocs/conf/conf.php"
|
2019-06-16 00:06:51 +02:00
|
|
|
# Recalculate and store the checksum of the file for the next upgrade.
|
2023-05-22 08:21:08 +02:00
|
|
|
ynh_store_file_checksum --file="$install_dir/htdocs/conf/conf.php"
|
|
|
|
chmod 644 "$install_dir/htdocs/conf/conf.php"
|
2019-06-16 00:06:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2019-07-05 22:34:21 +02:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
2019-06-16 00:06:51 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2023-05-22 08:30:20 +02:00
|
|
|
ynh_script_progression --message="Configuring permissions..." --weight=1
|
2017-04-24 04:16:02 +02:00
|
|
|
|
2019-06-16 00:06:51 +02:00
|
|
|
# Set permissions on app files
|
2023-05-22 08:21:08 +02:00
|
|
|
if [ ! -f "$data_dir/install.lock" ]; then
|
2024-01-24 16:26:05 +01:00
|
|
|
echo 'This is a lock file to prevent use of install pages (set with permission 440)' > "$data_dir/install.lock"
|
|
|
|
chown $app:$app "$data_dir/install.lock"
|
|
|
|
chmod 440 "$data_dir/install.lock"
|
2022-11-30 08:31:35 +01:00
|
|
|
fi
|
|
|
|
|
2023-05-22 08:21:08 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2021-09-25 13:16:23 +02:00
|
|
|
|
2019-06-16 00:06:51 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2019-07-05 22:34:21 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|