diff --git a/scripts/.fonctions b/scripts/.fonctions index 5268a86..d04f9e3 100644 --- a/scripts/.fonctions +++ b/scripts/.fonctions @@ -203,6 +203,38 @@ BACKUP_BEFORE_UPGRADE () { # Backup the current version of the app, restore it i fi } +# Manage a fail of the script +# +# Print a warning to inform that the script was failed +# Execute the ynh_clean_setup function if used in the app script +# +# usage of ynh_clean_setup function +# This function provide a way to clean some residual of installation that not managed by remove script. +# To use it, simply add in your script: +# ynh_clean_setup () { +# instructions... +# } +# This function is optionnal. +# +# Usage: ynh_exit_properly is used only by the helper ynh_check_error. +# You must not use it directly. +ynh_exit_properly () { + exit_code=$? + if [ "$exit_code" -eq 0 ]; then + exit 0 # Exit without error if the script ended correctly + fi + + trap '' EXIT # Ignore new exit signals + set +eu # Do not exit anymore if a command fail or if a variable is empty + + echo -e "!!\n $app's script has encountered an error. Its execution was cancelled.\n!!" >&2 + + if type -t ynh_clean_setup > /dev/null; then # Check if the function exist in the app script. + ynh_clean_setup # Call the function to do specific cleaning for the app. + fi + + ynh_die # Exit with error status +} # Exit if an error occurs during the execution of the script. # diff --git a/scripts/upgrade b/scripts/upgrade index 7c55d10..c25a5a7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -83,7 +83,7 @@ fi CHECK_MD5_CONFIG "lufi.conf" "$final_path/lufi.conf" # Créé un backup du fichier de config si il a été modifié. sudo cp ../conf/lufi.conf.template "$final_path/lufi.conf" sudo sed -i "s@__DOMAIN__@$domain@g" "$final_path/lufi.conf" -sudo sed -i "s@__PATH__@$path_url@g" "$final_path/lufi.conf" +sudo sed -i "s@__PATH__@$path@g" "$final_path/lufi.conf" sudo sed -i "s@__PORT__@$port@g" "$final_path/lufi.conf" sudo sed -i "s@__SECRET__@$secret@g" "${final_path}/lufi.conf" STORE_MD5_CONFIG "lufi.conf" "$final_path/lufi.conf" # Réenregistre la somme de contrôle du fichier de config @@ -113,7 +113,7 @@ sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/cron.d/$app #================================================= pushd $final_path # cd avec une stack pour revenir en arrière -sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log" +echo yes | sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log" popd # Revient au dossier courant avant pushd #=================================================