From 3ef137083a3a9e3c1ac942c1645ea8548e52af82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 24 Jan 2024 16:26:05 +0100 Subject: [PATCH] fix and simplify upgrade --- manifest.toml | 18 ++--- scripts/backup | 7 ++ scripts/install | 6 +- scripts/remove | 4 +- scripts/restore | 11 +-- scripts/upgrade | 173 +++++++++++++++--------------------------------- 6 files changed, 82 insertions(+), 137 deletions(-) diff --git a/manifest.toml b/manifest.toml index 2ef30ac..4e0bdea 100644 --- a/manifest.toml +++ b/manifest.toml @@ -53,47 +53,47 @@ ram.runtime = "50M" sha256 = "b1467797f892f72aa313f69f16d5277b481f2a7264ebe1d0ccf43311ca473684" autoupdate.strategy = "latest_github_release" - [resources.sources.upgrade_from_17] + [resources.sources.main_18_0_1] url = "https://github.com/dolibarr/dolibarr/archive/18.0.1.tar.gz" sha256 = "37bd3c8533b821c241dbb34b0e88349c1d5b43f7ffa6027f0b7970748d1f727a" prefetch = false - [resources.sources.upgrade_from_16] + [resources.sources.main_17_0_1] url = "https://github.com/dolibarr/dolibarr/archive/17.0.1.tar.gz" sha256 = "2eddd545c07eae291ad46e48ab55d3adb988d99c29a8dfaa2e2fde0a890b0ddc" prefetch = false - [resources.sources.upgrade_from_15] + [resources.sources.main_16_0_5] url = "https://github.com/dolibarr/dolibarr/archive/16.0.5.tar.gz" sha256 = "c8298342558e62b955a6f4c01fedb6a187b2e0c0b2c1681a97158ca979f9304f" prefetch = false - [resources.sources.upgrade_from_14] + [resources.sources.main_15_0_3] url = "https://github.com/dolibarr/dolibarr/archive/15.0.3.tar.gz" sha256 = "b145a38f56c44b166721d64909fb12408c6d10d08fcf74d2c00418a60201cc9d" prefetch = false - [resources.sources.upgrade_from_13] + [resources.sources.main_14_0_5] url = "https://github.com/Dolibarr/dolibarr/archive/14.0.5.tar.gz" sha256 = "31f4c934e484a9582d8867e4170f1f1acd8c41628b059370a6a449eb6e94ae75" prefetch = false - [resources.sources.upgrade_from_12] + [resources.sources.main_13_0_5] url = "https://github.com/Dolibarr/dolibarr/archive/13.0.5.tar.gz" sha256 = "08ec08dc5093d614361f273237f5aaf8d70e63d764c2fa8d7f3f68a1485156d0" prefetch = false - [resources.sources.upgrade_from_11] + [resources.sources.main_12_0_5] url = "https://github.com/Dolibarr/dolibarr/archive/12.0.5.tar.gz" sha256 = "b60b124ebcd294375f6200cc0683449e475b5dec687f8317b820fc8ec1413d21" prefetch = false - [resources.sources.upgrade_from_10] + [resources.sources.main_11_0_5] url = "https://github.com/Dolibarr/dolibarr/archive/11.0.5.tar.gz" sha256 = "6f51435a4ffe576e836bf6449d900de9a56016f09591322cb2ba47a07c97679d" prefetch = false - [resources.sources.upgrade_from_9] + [resources.sources.main_10_0_7] url = "https://github.com/Dolibarr/dolibarr/archive/10.0.7.tar.gz" sha256 = "6efc230f400a7b7152a0e4b9ba02a780f38b869b4aebd2bc28883268270ef871" prefetch = false diff --git a/scripts/backup b/scripts/backup index 97adcfe..3f87dc4 100755 --- a/scripts/backup +++ b/scripts/backup @@ -19,6 +19,13 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$install_dir" +#================================================= +# BACKUP THE DATA DIR +#================================================= + +### Only relevant if there is a "data_dir" resource for this app +ynh_backup --src_path="$data_dir" --is_big + #================================================= # BACKUP THE SYSTEM CONFIGURATION #================================================= diff --git a/scripts/install b/scripts/install index ee3c04b..e0f53bc 100644 --- a/scripts/install +++ b/scripts/install @@ -21,7 +21,6 @@ fpm_usage="medium" ynh_script_progression --message="Storing installation settings..." --weight=2 ynh_app_setting_set --app="$app" --key="member" --value="$member" -ynh_app_setting_set --app="$app" --key="version" --value="$(ynh_app_upstream_version)" ynh_app_setting_set --app="$app" --key="fpm_footprint" --value="$fpm_footprint" ynh_app_setting_set --app="$app" --key="fpm_usage" --value="$fpm_usage" @@ -41,14 +40,15 @@ ynh_script_progression --message="Setting up source files..." --weight=1 ynh_setup_source --dest_dir="$install_dir" chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" #================================================= # PREPARE AND INSTALL APP #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 +ynh_script_progression --message="Adding $app's configuration file..." --weight=1 -ynh_add_config --template="conf.php" --destination="$install_dir/htdocs/conf/conf.php" +ynh_add_config --template="../conf/conf.php" --destination="$install_dir/htdocs/conf/conf.php" chmod 644 "$install_dir/htdocs/conf/conf.php" chown "$app:$app" "$install_dir/htdocs/conf/conf.php" diff --git a/scripts/remove b/scripts/remove index 1a73be4..f617b28 100644 --- a/scripts/remove +++ b/scripts/remove @@ -8,9 +8,9 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# REMOVE NGINX CONFIGURATION +# REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the dedicated nginx config ynh_remove_nginx_config diff --git a/scripts/restore b/scripts/restore index af99308..9163735 100755 --- a/scripts/restore +++ b/scripts/restore @@ -15,8 +15,12 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$install_dir" +# Set permissions on app files chmod 750 "$install_dir" -chown -R $app:www-data "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R "$app:www-data" "$install_dir" + +chmod 644 "$install_dir/htdocs/conf/conf.php" #================================================= # RESTORE THE DATA DIRECTORY @@ -42,9 +46,6 @@ ynh_script_progression --message="Restoring system configurations related to $ap # Restore the file first, so it can have a backup if different ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" -# Recreate a dedicated php-fpm config -ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint - ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/logrotate.d/$app" @@ -54,8 +55,8 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1 -ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name="php$phpversion-fpm" --action=reload +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 3fcaa8b..78ddfa6 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,19 +7,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= - -update_version=$(ynh_app_upstream_version "../manifest.json") -current_version=$(ynh_app_setting_get --app=$app --key=version) - -#================================================= -# CHECK VERSION -#================================================= - -upgrade_type=$(ynh_check_app_version_changed) - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -30,13 +17,21 @@ ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # If fpm_footprint doesn't exist, create it if [ -z "${fpm_footprint:-}" ]; then fpm_footprint=low - ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint + ynh_app_setting_set --app="$app" --key=fpm_footprint --value=$fpm_footprint fi # If fpm_usage doesn't exist, create it if [ -z "${fpm_usage:-}" ]; then fpm_usage=low - ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage + 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 fi #================================================= @@ -48,7 +43,7 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - ynh_add_nginx_config # Recreate a dedicated PHP-FPM config -ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint +ynh_add_fpm_config --usage="$fpm_usage" --footprint="$fpm_footprint" #================================================= # SPECIFIC UPGRADE @@ -56,113 +51,55 @@ ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint # MAKE SEQUENTIAL UPGRADES FROM EACH MAJOR # VERSION TO THE NEXT ONE #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --weight=60 +ynh_script_progression --message="Upgrading source files..." --weight=60 - # Load the last available version - source upgrade.d/upgrade.last.sh - last_version=$next_version +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" - last_major_version=${last_version%%.*} + # Remove the lock if it exists + lock=$install_dir/documents/install.lock + if [ -f "$lock" ]; then + ynh_secure_remove --file="$lock" + fi - # While the current version is not the last version, do an upgrade - while [ "$last_version" != "$current_version" ] - do + pushd "$install_dir/htdocs/install/" + "php$phpversion" upgrade.php "$current_version" "$new_version" + ynh_exec_fully_quiet sleep 5 - # The major version is the first part of the version number - current_major_version=${current_version%%.*} + "php$phpversion" upgrade2.php "$current_version" "$new_version" + ynh_exec_fully_quiet sleep 5 - if [ ! -f upgrade.d/upgrade.$current_major_version.sh ]; then - source_id="main" - else - source_id="upgrade_from_$current_major_version" - fi + "php$phpversion" step5.php "$current_version" "$new_version" + ynh_exec_fully_quiet sleep 5 + popd +} - # If the current version has the same major version than the next one, - # then it's the last upgrade to do - # We also cover the case where the last version is the first of the current major version series - # (e.g. 20.0.0 is the latest version) - if [[ ("$last_major_version" -eq "$current_major_version") || ( ("$last_major_version" -eq "$((current_major_version+1))") && ("$next_version" == "$last_version") ) ]]; then - current_major_version=last - fi +# 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 - # Load the value for this version - source upgrade.d/upgrade.$current_major_version.sh +# 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 - ynh_print_info --message="Upgrading app from $current_version to $next_version" - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --source_id="$source_id" --dest_dir="$install_dir" - - chown -R $app: "$install_dir" - - # Remove the lock if it exists - lock=$install_dir/documents/install.lock - if [ -f $lock ] - then - ynh_secure_remove $lock - fi - - mkdir -p /var/log/$app/ - - # Upgrade with CURL - - 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 --database=$db_name --sql="ALTER DATABASE $db_name charset=utf8" - - ynh_local_curl "/install/repair.php" \ - "force_utf8_on_tables=confirmed" > /var/log/$app/repair.html - fi - - ynh_exec_fully_quiet sleep 5 - - - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" - - pushd $install_dir/htdocs/install/ - - if php$phpversion upgrade.php $current_version $next_version > /var/log/$app/upgrade.html; then - ynh_print_info --message="Step 1 upgrading ended successfully" - else - ynh_die --message="Step 1 upgrading ended with error" - fi - - ynh_exec_fully_quiet sleep 5 - - if php$phpversion upgrade2.php $current_version $next_version > /var/log/$app/upgrade2.html; then - ynh_print_info --message="Step 2 upgrading ended successfully" - else - ynh_die --message="Step 2 upgrading ended with error" - fi - - ynh_exec_fully_quiet sleep 5 - - if php$phpversion step5.php $current_version $next_version > /var/log/$app/upgrade3.html; then - ynh_print_info --message="Step 3 upgrading ended successfully" - else - ynh_die --message="Step 3 upgrading ended with error" - fi - popd - - - # Get the new current version number - current_version=$next_version - current_major_version=${current_version%%.*} - - done - - 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" - fi - - ynh_app_setting_set --app=$app --key=version --value=$update_version +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" fi #================================================= @@ -191,9 +128,9 @@ ynh_script_progression --message="Configuring permissions..." --weight=1 # Set permissions on app files if [ ! -f "$data_dir/install.lock" ]; then - 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" + 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" fi chmod 750 "$install_dir"