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
2024-08-30 22:49:44 +02:00
ynh_app_setting_set_default --key=php_memory_limit --value=256M
2019-06-16 00:06:51 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2024-08-30 22:49:44 +02:00
ynh_script_progression "Ensuring downward compatibility..."
2019-06-16 00:06:51 +02:00
2020-09-28 02:00:16 +02:00
# If fpm_footprint doesn't exist, create it
2024-03-26 20:38:36 +01:00
if [ -z "${fpm_footprint:-}" ]; then
fpm_footprint=medium
2024-08-30 22:49:44 +02:00
#REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | ynh_app_setting_set --key=fpm_footprint --value=$fpm_footprint
2020-09-28 02:00:16 +02:00
fi
# If fpm_usage doesn't exist, create it
2024-03-26 20:38:36 +01:00
if [ -z "${fpm_usage:-}" ]; then
fpm_usage=medium
2024-08-30 22:49:44 +02:00
#REMOVEME? Everything about fpm_usage is removed in helpers2.1... | ynh_app_setting_set --key=fpm_usage --value=$fpm_usage
2021-03-24 15:39:00 +01:00
fi
2022-09-27 12:09:16 +02:00
# Delete existing ini configuration file (backward compatibility)
if [ -f /etc/php/$YNH_PHP_VERSION/fpm/conf.d/20-$app.ini ]; then
2024-08-30 22:49:44 +02:00
ynh_safe_rm /etc/php/$YNH_PHP_VERSION/fpm/conf.d/20-$app.ini
2022-09-27 12:09:16 +02:00
fi
2024-03-26 20:38:36 +01:00
if [ -n "${version:-}" ]; then
2024-08-30 22:49:44 +02:00
ynh_app_setting_delete --key="version"
2024-03-26 20:38:36 +01:00
fi
2020-09-28 16:56:29 +02:00
2024-03-26 20:38:36 +01:00
charset=$(mysql -ss -N -e "SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = '$db_name'")
if [ "$charset" != "utf8" ]; then
2024-08-30 22:49:44 +02:00
ynh_print_info "Changing Database charset to utf8"
ynh_mysql_db_shell <<< "ALTER DATABASE $db_name charset=utf8"
2024-03-26 21:49:23 +01:00
ynh_local_curl "/install/repair.php" "force_utf8_on_tables=confirmed"
2024-08-30 22:49:44 +02:00
sleep 5
2024-03-26 20:38:36 +01:00
fi
2020-09-28 01:07:01 +02:00
2019-06-16 00:06:51 +02:00
#=================================================
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-08-30 22:49:44 +02:00
ynh_script_progression "Upgrading source files..."
2024-03-26 20:38:36 +01:00
# Sort --version-sort cdécembrean handle underscore in versions numbers
mapfile -t main_versions < <(
2024-08-30 22:49:44 +02:00
ynh_read_manifest | keys[]" | grep "main_" | sort --version-sort
2024-03-26 20:38:36 +01:00
)
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
2024-08-30 22:49:44 +02:00
ynh_print_info "Upgrading app from $current_version to $new_version"
2024-03-26 20:38:36 +01:00
source_id="$version"
upgrade_dolibarr
current_version="$new_version"
done
# Final upgrade to the final version
new_version=$(ynh_app_upstream_version)
2024-03-26 21:52:37 +01:00
source_id="main"
2024-08-30 22:49:44 +02:00
ynh_print_info "Upgrading app from $current_version to $new_version"
2024-03-26 20:38:36 +01:00
upgrade_dolibarr
2024-08-30 22:49:44 +02:00
if "php$php_version" "$install_dir/scripts/user/sync_users_ldap2dolibarr.php" commitiferror --server=localhost -y; then
ynh_print_info "LDAP user update ok"
2024-03-26 20:38:36 +01:00
else
2024-08-30 22:49:44 +02:00
ynh_print_info "LDAP user update ended with error"
2019-06-16 00:06:51 +02:00
fi
2024-08-30 22:49:44 +02:00
ynh_backup_if_checksum_is_different "$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.
2024-08-30 22:49:44 +02:00
ynh_store_file_checksum "$install_dir/htdocs/conf/conf.php"
2024-03-25 21:26:07 +01:00
chmod 644 "$install_dir/htdocs/conf/conf.php"
2019-06-16 00:06:51 +02:00
2024-03-26 22:01:44 +01:00
if [ ! -f "$install_dir/documents/install.lock" ]; then
echo 'This is a lock file to prevent use of install pages (set with permission 440)' > "$install_dir/documents/install.lock"
chown "$app:$app" "$install_dir/documents/install.lock"
chmod 440 "$install_dir/documents/install.lock"
2022-11-30 08:31:35 +01:00
fi
2024-08-30 22:49:44 +02:00
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
2024-03-26 20:38:36 +01:00
# mkdir -p "$data_dir"
# chown -R $app: "$data_dir"
# chmod go-w $data_dir
2019-06-16 00:06:51 +02:00
#=================================================
2024-03-26 20:38:36 +01:00
# REAPPLY SYSTEM CONFIGURATIONS
2019-06-16 00:06:51 +02:00
#=================================================
2024-08-30 22:49:44 +02:00
ynh_script_progression "Upgrading system configurations related to $app..."
2024-03-26 20:38:36 +01:00
2024-08-30 22:49:44 +02:00
ynh_config_add_phpfpm
2019-06-16 00:06:51 +02:00
2024-08-30 22:49:44 +02:00
ynh_config_add_nginx
2024-03-26 20:38:36 +01:00
2024-08-30 22:49:44 +02:00
ynh_config_add_logrotate
2019-06-16 00:06:51 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2024-08-30 22:49:44 +02:00
ynh_script_progression "Upgrade of $app completed"