From 65f5621cb6ec790f075c5c80abe5d57203270d83 Mon Sep 17 00:00:00 2001 From: Robin Candau <robincandau@protonmail.com> Date: Sun, 7 Jul 2024 01:00:17 +0200 Subject: [PATCH] feat: Only check for post upgrade restart service if packages got upgraded --- src/script/arch-update.sh | 112 ++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 53 deletions(-) diff --git a/src/script/arch-update.sh b/src/script/arch-update.sh index 942d8fe..95ae27c 100755 --- a/src/script/arch-update.sh +++ b/src/script/arch-update.sh @@ -423,6 +423,8 @@ update() { echo error_msg "$(eval_gettext "An error has occurred during the update process\nThe update has been aborted\n")" && quit_msg exit 5 + else + packages_updated="y" fi fi @@ -435,6 +437,8 @@ update() { echo error_msg "$(eval_gettext "An error has occurred during the update process\nThe update has been aborted\n")" && quit_msg exit 5 + else + packages_updated="y" fi fi @@ -634,68 +638,70 @@ pacnew_files() { # Definition of the restart_services function: Verify if any services require a post update restart restart_services() { - services=$(yes No | sudo checkservices -FP 2> /dev/null | grep ".service" | grep -v -e "dbus-broker.service" -e "systemd-logind.service" | cut -f2 -d "'") - services_num=$(echo "${services}" | wc -l) - - if [ -n "${services}" ]; then - if [ "${services_num}" -eq 1 ]; then - main_msg "$(eval_gettext "Services:\nThe following service requires a post upgrade restart\n")" - else - main_msg "$(eval_gettext "Services:\nThe following services require a post upgrade restart\n")" - fi - - i=1 - while IFS= read -r line; do - echo "${i} - ${line}" - ((i=i+1)) - done < <(printf '%s\n' "${services}") - - echo - ask_msg_array "$(eval_gettext "Select the service(s) to restart (e.g. 1 3 5), select 0 to restart them all or press \"enter\" to continue without restarting the service(s):")" - echo - - if [ "${answer_array[0]}" -eq 0 ] 2> /dev/null; then - # shellcheck disable=SC2086 - if "${su_cmd}" systemctl restart ${services}; then - info_msg "$(eval_gettext "Service(s) restarted successfully\n")" - + if [ -n "${packages_updated}" ]; then + services=$(yes No | sudo checkservices -FP 2> /dev/null | grep ".service" | grep -v -e "dbus-broker.service" -e "systemd-logind.service" | cut -f2 -d "'") + services_num=$(echo "${services}" | wc -l) + + if [ -n "${services}" ]; then + if [ "${services_num}" -eq 1 ]; then + main_msg "$(eval_gettext "Services:\nThe following service requires a post upgrade restart\n")" else - error_msg "$(eval_gettext "An error has occurred during service(s) restart\nPlease, verify the above service(s) status\n")" && quit_msg - exit 11 + main_msg "$(eval_gettext "Services:\nThe following services require a post upgrade restart\n")" fi - else - array_to_string=$(printf "%s\n" "${answer_array[@]}") - mapfile -t answer_array < <(echo "${array_to_string}" | awk '!seen[$0]++') - - for num in "${answer_array[@]}"; do - if [ "${num}" -le "${services_num}" ] 2> /dev/null && [ "${num}" -gt "0" ]; then - service_restarted="y" - service_selected=$(sed -n "${num}"p <<< "${services}") - - if "${su_cmd}" systemctl restart "${service_selected}"; then - info_msg "$(eval_gettext "The \${service_selected} service has been successfully restarted")" - else - error_msg "$(eval_gettext "An error occurred during the restart of the \${service_selected} service")" - service_fail="y" - fi - fi - done - - if [ -n "${service_restarted}" ]; then - if [ -z "${service_fail}" ]; then - echo + + i=1 + while IFS= read -r line; do + echo "${i} - ${line}" + ((i=i+1)) + done < <(printf '%s\n' "${services}") + + echo + ask_msg_array "$(eval_gettext "Select the service(s) to restart (e.g. 1 3 5), select 0 to restart them all or press \"enter\" to continue without restarting the service(s):")" + echo + + if [ "${answer_array[0]}" -eq 0 ] 2> /dev/null; then + # shellcheck disable=SC2086 + if "${su_cmd}" systemctl restart ${services}; then info_msg "$(eval_gettext "Service(s) restarted successfully\n")" + else - echo - error_msg "$(eval_gettext "An error occurred during the service(s) restart\nPlease, verify the status of the above service(s)\n")" && quit_msg + error_msg "$(eval_gettext "An error has occurred during service(s) restart\nPlease, verify the above service(s) status\n")" && quit_msg exit 11 fi else - warning_msg "$(eval_gettext "The service(s) restart hasn't been performed\nPlease, consider restarting services that have been updated to fully apply the upgrade\n")" + array_to_string=$(printf "%s\n" "${answer_array[@]}") + mapfile -t answer_array < <(echo "${array_to_string}" | awk '!seen[$0]++') + + for num in "${answer_array[@]}"; do + if [ "${num}" -le "${services_num}" ] 2> /dev/null && [ "${num}" -gt "0" ]; then + service_restarted="y" + service_selected=$(sed -n "${num}"p <<< "${services}") + + if "${su_cmd}" systemctl restart "${service_selected}"; then + info_msg "$(eval_gettext "The \${service_selected} service has been successfully restarted")" + else + error_msg "$(eval_gettext "An error occurred during the restart of the \${service_selected} service")" + service_fail="y" + fi + fi + done + + if [ -n "${service_restarted}" ]; then + if [ -z "${service_fail}" ]; then + echo + info_msg "$(eval_gettext "Service(s) restarted successfully\n")" + else + echo + error_msg "$(eval_gettext "An error occurred during the service(s) restart\nPlease, verify the status of the above service(s)\n")" && quit_msg + exit 11 + fi + else + warning_msg "$(eval_gettext "The service(s) restart hasn't been performed\nPlease, consider restarting services that have been updated to fully apply the upgrade\n")" + fi fi + else + info_msg "$(eval_gettext "No service requiring a post upgrade restart found\n")" fi - else - info_msg "$(eval_gettext "No service requiring a post upgrade restart found\n")" fi } # Definition of the kernel_reboot function: Verify if there's a kernel update waiting for a reboot to be applied