From 05b3a99653d38af84818a43881e3021a03f76802 Mon Sep 17 00:00:00 2001 From: Robles Rodolphe Date: Mon, 1 Nov 2021 12:19:48 +0100 Subject: [PATCH] fix issue #65 'Upgrade pass but then redirects to install.php page' on upgrade script --- conf/1.1.0.src | 5 +++ scripts/upgrade | 81 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 61 insertions(+), 25 deletions(-) create mode 100644 conf/1.1.0.src diff --git a/conf/1.1.0.src b/conf/1.1.0.src new file mode 100644 index 0000000..59679fe --- /dev/null +++ b/conf/1.1.0.src @@ -0,0 +1,5 @@ +SOURCE_URL=https://fossil.kd2.org/garradin/uv/garradin-1.1.0.tar.bz2 +SOURCE_SUM=8689c62754d3b7920cf59786379e085a591fc1763dd3ec8fd13736e916c659bd +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=tar.bz2 +SOURCE_IN_SUBDIR=true \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade index f066255..703db35 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -27,6 +27,8 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) if ynh_compare_current_package_version --comparison lt --version 0.9.8.1~ynh1; then upgrade_type="0.9.8" +elif ynh_compare_current_package_version --comparison le --version 1.0.7~ynh2; then + upgrade_type="1.1.0" else upgrade_type=$(ynh_check_app_version_changed) fi @@ -87,7 +89,7 @@ if [ "$upgrade_type" == "0.9.8" ] then ynh_script_progression --message="Upgrading upgrade to 0.9.8" --weight=5 # Download, check integrity, uncompress and patch the source from 0.9.8.src - ynh_setup_source --dest_dir="$final_path" --source_id="0.9.8" + ynh_setup_source --keep="config.local.php" --dest_dir="$final_path" --source_id="0.9.8" # Set permissions on app files ynh_system_user_create --username=$app ynh_add_nginx_config @@ -98,28 +100,66 @@ then backup_bdd=/tmp/association.sqlite backup_squelettes=/tmp/squelettes - if [ -d "$backup_squelettes" ] + if [ -d "$backup_squelettes" ] + then + cp -ar $backup_squelettes $final_path/www/squelettes + fi + + if [ -e "$backup_bdd" ] + then + cp -a $backup_bdd $final_path/association.sqlite + fi + + chown -R $app:$app $final_path + chmod 755 $final_path + + # Create the visitors permission if needed + visitors_enabled=$(ynh_permission_has_user "main" "visitors" && echo 0 || echo 1) + if [[ $visitors_enabled -eq 0 ]]; then + ynh_permission_update --permission "main" --add "visitors" + fi + + ynh_systemd_action --service_name=nginx --action=reload + # Finalize the upgrade + ynh_local_curl "/index.php" + sleep 5 + ynh_local_curl "/index.php" + upgrade_type="UPGRADE_APP" + + if [[ $visitors_enabled -eq 0 ]]; then + ynh_permission_update --permission "main" --remove "visitors" + fi +fi +#================================================= +# UPGRADE TO 1.1.0 if necessary +#================================================= + +if [ "$upgrade_type" == "1.1.0" ] +then + ynh_script_progression --message="Upgrading upgrade to 1.1.0" --weight=5 + # Download, check integrity, uncompress and patch the source from 0.9.8.src + ynh_setup_source --keep="config.local.php" --dest_dir="$final_path" --source_id="1.1.0" + # Set permissions on app files + ynh_system_user_create --username=$app + ynh_add_nginx_config + ynh_add_fpm_config --package="$extra_php_dependencies" + phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) + ynh_script_progression --message="restore data..." --weight=10 + + backup_bdd=/tmp/association.sqlite + backup_squelettes=/tmp/squelettes + + if [ -d "$backup_squelettes" ] then cp -ar $backup_squelettes $final_path/www/squelettes - ynh_secure_remove $backup_squelettes fi if [ -e "$backup_bdd" ] then - cp -a $backup_bdd $final_path/association.sqlite - ynh_secure_remove $backup_bdd + cp -a $backup_bdd $final_path/association.sqlite fi chown -R $app:$app $final_path - - key=$(ynh_string_random --length=50) - cp -a $final_path/config.dist.php $final_path/config.local.php - ynh_replace_string --match_string="const SECRET_KEY = '3xUhIgGwuovRKOjVsVPQ5yUMfXUSIOX2GKzcebsz5OINrYC50r';" --replace_string="const SECRET_KEY = '$key';" --target_file="$final_path/config.local.php" - if [ "$path_url" == "/" ]; then - ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url';" --target_file="$final_path/config.local.php" - else - ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php" - fi chmod 755 $final_path # Create the visitors permission if needed @@ -156,7 +196,7 @@ ynh_script_progression --message="Upgrading source files..." --weight=5 if [ "$upgrade_type" == "UPGRADE_APP" ] then # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" + ynh_setup_source --keep="config.local.php" --dest_dir="$final_path" fi #================================================= @@ -200,15 +240,6 @@ fi #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=5 -key=$(ynh_string_random --length=50) -cp -a $final_path/config.dist.php $final_path/config.local.php -ynh_replace_string --match_string="const SECRET_KEY = '3xUhIgGwuovRKOjVsVPQ5yUMfXUSIOX2GKzcebsz5OINrYC50r';" --replace_string="const SECRET_KEY = '$key';" --target_file="$final_path/config.local.php" -if [ "$path_url" == "/" ]; then -ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url';" --target_file="$final_path/config.local.php" -else -ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php" -fi - # Permissions on files and directories chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" @@ -237,4 +268,4 @@ chmod 440 "$final_path/config.local.php" # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of Garradin completed" --last +ynh_script_progression --message="Upgrade of Garradin completed" --last \ No newline at end of file