1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dolibarr_ynh.git synced 2024-09-03 18:35:53 +02:00

fix and simplify upgrade

This commit is contained in:
Salamandar 2024-01-24 16:26:05 +01:00 committed by Salamandar
parent 2db230dd71
commit 3ef137083a
6 changed files with 82 additions and 137 deletions

View file

@ -53,47 +53,47 @@ ram.runtime = "50M"
sha256 = "b1467797f892f72aa313f69f16d5277b481f2a7264ebe1d0ccf43311ca473684" sha256 = "b1467797f892f72aa313f69f16d5277b481f2a7264ebe1d0ccf43311ca473684"
autoupdate.strategy = "latest_github_release" 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" url = "https://github.com/dolibarr/dolibarr/archive/18.0.1.tar.gz"
sha256 = "37bd3c8533b821c241dbb34b0e88349c1d5b43f7ffa6027f0b7970748d1f727a" sha256 = "37bd3c8533b821c241dbb34b0e88349c1d5b43f7ffa6027f0b7970748d1f727a"
prefetch = false 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" url = "https://github.com/dolibarr/dolibarr/archive/17.0.1.tar.gz"
sha256 = "2eddd545c07eae291ad46e48ab55d3adb988d99c29a8dfaa2e2fde0a890b0ddc" sha256 = "2eddd545c07eae291ad46e48ab55d3adb988d99c29a8dfaa2e2fde0a890b0ddc"
prefetch = false 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" url = "https://github.com/dolibarr/dolibarr/archive/16.0.5.tar.gz"
sha256 = "c8298342558e62b955a6f4c01fedb6a187b2e0c0b2c1681a97158ca979f9304f" sha256 = "c8298342558e62b955a6f4c01fedb6a187b2e0c0b2c1681a97158ca979f9304f"
prefetch = false 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" url = "https://github.com/dolibarr/dolibarr/archive/15.0.3.tar.gz"
sha256 = "b145a38f56c44b166721d64909fb12408c6d10d08fcf74d2c00418a60201cc9d" sha256 = "b145a38f56c44b166721d64909fb12408c6d10d08fcf74d2c00418a60201cc9d"
prefetch = false 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" url = "https://github.com/Dolibarr/dolibarr/archive/14.0.5.tar.gz"
sha256 = "31f4c934e484a9582d8867e4170f1f1acd8c41628b059370a6a449eb6e94ae75" sha256 = "31f4c934e484a9582d8867e4170f1f1acd8c41628b059370a6a449eb6e94ae75"
prefetch = false 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" url = "https://github.com/Dolibarr/dolibarr/archive/13.0.5.tar.gz"
sha256 = "08ec08dc5093d614361f273237f5aaf8d70e63d764c2fa8d7f3f68a1485156d0" sha256 = "08ec08dc5093d614361f273237f5aaf8d70e63d764c2fa8d7f3f68a1485156d0"
prefetch = false 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" url = "https://github.com/Dolibarr/dolibarr/archive/12.0.5.tar.gz"
sha256 = "b60b124ebcd294375f6200cc0683449e475b5dec687f8317b820fc8ec1413d21" sha256 = "b60b124ebcd294375f6200cc0683449e475b5dec687f8317b820fc8ec1413d21"
prefetch = false 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" url = "https://github.com/Dolibarr/dolibarr/archive/11.0.5.tar.gz"
sha256 = "6f51435a4ffe576e836bf6449d900de9a56016f09591322cb2ba47a07c97679d" sha256 = "6f51435a4ffe576e836bf6449d900de9a56016f09591322cb2ba47a07c97679d"
prefetch = false 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" url = "https://github.com/Dolibarr/dolibarr/archive/10.0.7.tar.gz"
sha256 = "6efc230f400a7b7152a0e4b9ba02a780f38b869b4aebd2bc28883268270ef871" sha256 = "6efc230f400a7b7152a0e4b9ba02a780f38b869b4aebd2bc28883268270ef871"
prefetch = false prefetch = false

View file

@ -19,6 +19,13 @@ ynh_print_info --message="Declaring files to be backed up..."
ynh_backup --src_path="$install_dir" 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 # BACKUP THE SYSTEM CONFIGURATION
#================================================= #=================================================

View file

@ -21,7 +21,6 @@ fpm_usage="medium"
ynh_script_progression --message="Storing installation settings..." --weight=2 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="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_footprint" --value="$fpm_footprint"
ynh_app_setting_set --app="$app" --key="fpm_usage" --value="$fpm_usage" 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" ynh_setup_source --dest_dir="$install_dir"
chmod 750 "$install_dir" chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir" chown -R "$app:www-data" "$install_dir"
#================================================= #=================================================
# PREPARE AND INSTALL APP # 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" chmod 644 "$install_dir/htdocs/conf/conf.php"
chown "$app:$app" "$install_dir/htdocs/conf/conf.php" chown "$app:$app" "$install_dir/htdocs/conf/conf.php"

View file

@ -8,9 +8,9 @@ source _common.sh
source /usr/share/yunohost/helpers 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 # Remove the dedicated nginx config
ynh_remove_nginx_config ynh_remove_nginx_config

View file

@ -15,8 +15,12 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
ynh_restore_file --origin_path="$install_dir" ynh_restore_file --origin_path="$install_dir"
# Set permissions on app files
chmod 750 "$install_dir" 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 # 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 # 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" 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/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/logrotate.d/$app" 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_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="php$phpversion-fpm" --action=reload
ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -7,19 +7,6 @@
source _common.sh source _common.sh
source /usr/share/yunohost/helpers 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 # 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 fpm_footprint doesn't exist, create it
if [ -z "${fpm_footprint:-}" ]; then if [ -z "${fpm_footprint:-}" ]; then
fpm_footprint=low 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 fi
# If fpm_usage doesn't exist, create it # If fpm_usage doesn't exist, create it
if [ -z "${fpm_usage:-}" ]; then if [ -z "${fpm_usage:-}" ]; then
fpm_usage=low 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 fi
#================================================= #=================================================
@ -48,7 +43,7 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." -
ynh_add_nginx_config ynh_add_nginx_config
# Recreate a dedicated PHP-FPM 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 # SPECIFIC UPGRADE
@ -56,113 +51,55 @@ ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
# MAKE SEQUENTIAL UPGRADES FROM EACH MAJOR # MAKE SEQUENTIAL UPGRADES FROM EACH MAJOR
# VERSION TO THE NEXT ONE # VERSION TO THE NEXT ONE
#================================================= #=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ] ynh_script_progression --message="Upgrading source files..." --weight=60
then
ynh_script_progression --message="Upgrading source files..." --weight=60
# Load the last available version upgrade_dolibarr() {
source upgrade.d/upgrade.last.sh ynh_setup_source --source_id="$source_id" --dest_dir="$install_dir"
last_version=$next_version 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 pushd "$install_dir/htdocs/install/"
while [ "$last_version" != "$current_version" ] "php$phpversion" upgrade.php "$current_version" "$new_version"
do ynh_exec_fully_quiet sleep 5
# The major version is the first part of the version number "php$phpversion" upgrade2.php "$current_version" "$new_version"
current_major_version=${current_version%%.*} ynh_exec_fully_quiet sleep 5
if [ ! -f upgrade.d/upgrade.$current_major_version.sh ]; then "php$phpversion" step5.php "$current_version" "$new_version"
source_id="main" ynh_exec_fully_quiet sleep 5
else popd
source_id="upgrade_from_$current_major_version" }
fi
# If the current version has the same major version than the next one, # Sort --version-sort cdécembrean handle underscore in versions numbers
# then it's the last upgrade to do mapfile -t main_versions < <(
# We also cover the case where the last version is the first of the current major version series ynh_read_manifest --key="resources.sources | keys[]" | grep "main_" | sort --version-sort
# (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_version="$YNH_APP_CURRENT_VERSION"
current_major_version=last for version in "${main_versions[@]}"; do
fi 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 # Final upgrade to the final version
source upgrade.d/upgrade.$current_major_version.sh 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" if "php$phpversion" "$install_dir/scripts/user/sync_users_ldap2dolibarr.php" commitiferror --server=localhost -y; then
# Download, check integrity, uncompress and patch the source from app.src ynh_print_info --message="LDAP user update ok"
ynh_setup_source --source_id="$source_id" --dest_dir="$install_dir" else
ynh_print_info --message="LDAP user update ended with error"
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
fi fi
#================================================= #=================================================
@ -191,9 +128,9 @@ ynh_script_progression --message="Configuring permissions..." --weight=1
# Set permissions on app files # Set permissions on app files
if [ ! -f "$data_dir/install.lock" ]; then 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" 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" chown $app:$app "$data_dir/install.lock"
chmod 440 "$data_dir/install.lock" chmod 440 "$data_dir/install.lock"
fi fi
chmod 750 "$install_dir" chmod 750 "$install_dir"