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

123 lines
4.5 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
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
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
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
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated nginx config
ynh_add_nginx_config
# Recreate a dedicated PHP-FPM config
ynh_add_fpm_config --usage="$fpm_usage" --footprint="$fpm_footprint"
#=================================================
# SPECIFIC UPGRADE
#=================================================
# MAKE SEQUENTIAL UPGRADES FROM EACH MAJOR
# VERSION TO THE NEXT ONE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=60
# Sort --version-sort cdécembrean handle underscore in versions numbers
mapfile -t main_versions < <(
ynh_read_manifest --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"
source_id="$version"
upgrade_dolibarr
current_version="$new_version"
done
# Final upgrade to the final version
new_version=$(ynh_app_upstream_version)
source_id="main"
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"
fi
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
ynh_backup_if_checksum_is_different --file="$install_dir/htdocs/conf/conf.php"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$install_dir/htdocs/conf/conf.php"
chmod 644 "$install_dir/htdocs/conf/conf.php"
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
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"
fi
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last