From f50d1f64de2d2970b7f43acc17296c1fbe49079f Mon Sep 17 00:00:00 2001 From: Barry Jackson Date: Thu, 29 Jun 2023 23:00:01 +0100 Subject: [PATCH 1/7] Fix 1st part of bug31969 --- remove-old-kernels | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/remove-old-kernels b/remove-old-kernels index 17c553c..b0b2ec1 100755 --- a/remove-old-kernels +++ b/remove-old-kernels @@ -474,8 +474,12 @@ if (( nbt != 0 )) ; then rm -f "${TMPKTR}" exit 0 fi - # Warn if we are not root - RootWarn + # Warn if we are not root and exit hang until spacebar + if ! RootWarn; then + { echo "$(i18n "Tap spacebar to exit")"; read -n1; echo -en "${ClearLine}"; } + exit 0 + fi + if [[ "${MODE}" != "A" ]] ; then if (( DEBUG == 1 )) ; then echo -e "\n${KeepCol}>> $(i18n "Test mode is on - kernels will not be removed") <<${Normal}" From e4c63b269650f7f39b038ecdc87dab9117be40aa Mon Sep 17 00:00:00 2001 From: Barry Jackson Date: Thu, 29 Jun 2023 23:12:20 +0100 Subject: [PATCH 2/7] Cleaner fix 1st part of bug31969 --- remove-old-kernels | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/remove-old-kernels b/remove-old-kernels index b0b2ec1..027cbb9 100755 --- a/remove-old-kernels +++ b/remove-old-kernels @@ -51,13 +51,12 @@ if (( UID > 0 )); then fi } -# Warn when not root +# Warn when not root and force only exit option RootWarn() { if (( UID > 0 )); then - echo -e "${RemvCol}$(i18n "Must be root to allow removal")${Normal}" - return 1 - else - return 0 + echo -e "${RemvCol}$(i18n "Must be root to allow removal")${Normal}\n$(i18n "Tap spacebar to exit")" + read -r -n1; echo -en "${ClearLine}" + exit 0 fi } @@ -475,11 +474,7 @@ if (( nbt != 0 )) ; then exit 0 fi # Warn if we are not root and exit hang until spacebar - if ! RootWarn; then - { echo "$(i18n "Tap spacebar to exit")"; read -n1; echo -en "${ClearLine}"; } - exit 0 - fi - + RootWarn if [[ "${MODE}" != "A" ]] ; then if (( DEBUG == 1 )) ; then echo -e "\n${KeepCol}>> $(i18n "Test mode is on - kernels will not be removed") <<${Normal}" From cec62fa755130a43aec99058830b86a7a5a9518d Mon Sep 17 00:00:00 2001 From: Barry Jackson Date: Thu, 29 Jun 2023 23:14:13 +0100 Subject: [PATCH 3/7] Only say tap spacebar --- remove-old-kernels | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remove-old-kernels b/remove-old-kernels index 027cbb9..dde1dd1 100755 --- a/remove-old-kernels +++ b/remove-old-kernels @@ -54,7 +54,7 @@ fi # Warn when not root and force only exit option RootWarn() { if (( UID > 0 )); then - echo -e "${RemvCol}$(i18n "Must be root to allow removal")${Normal}\n$(i18n "Tap spacebar to exit")" + echo -e "${RemvCol}$(i18n "Must be root to allow removal")${Normal}\n$(i18n "Tap spacebar")" read -r -n1; echo -en "${ClearLine}" exit 0 fi From eea0bf508c1ebd9f941ee2d0e4b78374306d4825 Mon Sep 17 00:00:00 2001 From: Barry Jackson Date: Thu, 29 Jun 2023 23:49:14 +0100 Subject: [PATCH 4/7] Fix 2nd part of bug 31969 --- remove-old-kernels | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/remove-old-kernels b/remove-old-kernels index dde1dd1..11604fc 100755 --- a/remove-old-kernels +++ b/remove-old-kernels @@ -451,6 +451,7 @@ if (( ${#dnfmssg} > 0 ));then echo -e "${dnfmssg}"; fi #================================= Mode of execution =================== # Check there are kernels to remove +nbktr=$(grep -v devel < "${TMPKTR}"|wc -l) nbt=$(wc -l < "${TMPKTR}") if (( nbt != 0 )) ; then # Check if we are in preview mode @@ -479,14 +480,14 @@ if (( nbt != 0 )) ; then if (( DEBUG == 1 )) ; then echo -e "\n${KeepCol}>> $(i18n "Test mode is on - kernels will not be removed") <<${Normal}" fi - plural="s"; (( nbt == 1 )) && plural="" + plural="s"; (( nbktr == 1 )) && plural="" if [[ "$plural" == "s" ]]; then kernstr="$(i18n "kernels"):" else kernstr="$(i18n "kernel"):" fi - read -p "$(i18n "Remove") ${nbt} $kernstr ? $(i18n "y/N/i (i=confirm for each)") " -n 1 response + read -p "$(i18n "Remove") ${nbktr} $kernstr ? $(i18n "y/N/i (i=confirm for each)") " -n 1 response if [[ -z ${response} ]] ; then response="n" ; fi case ${response} in [Yy]) From 0fec92bdebc34608916a6347f5b37c469fc47e54 Mon Sep 17 00:00:00 2001 From: Barry Jackson Date: Fri, 30 Jun 2023 10:44:44 +0100 Subject: [PATCH 5/7] -Remove function used once -Display kernel number to remove when devel packages also need removing --- remove-old-kernels | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/remove-old-kernels b/remove-old-kernels index 11604fc..620c98c 100755 --- a/remove-old-kernels +++ b/remove-old-kernels @@ -51,15 +51,6 @@ if (( UID > 0 )); then fi } -# Warn when not root and force only exit option -RootWarn() { - if (( UID > 0 )); then - echo -e "${RemvCol}$(i18n "Must be root to allow removal")${Normal}\n$(i18n "Tap spacebar")" - read -r -n1; echo -en "${ClearLine}" - exit 0 - fi -} - # Function to handle -f or -F options altcfg() { cfgno=$1 @@ -475,7 +466,11 @@ if (( nbt != 0 )) ; then exit 0 fi # Warn if we are not root and exit hang until spacebar - RootWarn + if (( UID > 0 )); then + echo -e "${RemvCol}$(i18n "Must be root to allow removal")${Normal}\n$(i18n "Tap spacebar to exit")" + read -r -n1; echo -en "${ClearLine}" + exit 0 + fi if [[ "${MODE}" != "A" ]] ; then if (( DEBUG == 1 )) ; then echo -e "\n${KeepCol}>> $(i18n "Test mode is on - kernels will not be removed") <<${Normal}" @@ -486,8 +481,11 @@ if (( nbt != 0 )) ; then else kernstr="$(i18n "kernel"):" fi - - read -p "$(i18n "Remove") ${nbktr} $kernstr ? $(i18n "y/N/i (i=confirm for each)") " -n 1 response + if (( nbt == nbktr )); then + read -p "$(i18n "Remove") ${nbt} $kernstr ? $(i18n "y/N/i (i=confirm for each)") " -n 1 response + else + read -p "$(i18n "Remove") ${nbt} (${nbktr} ${kernstr}) ? $(i18n "y/N/i (i=confirm for each)") " -n 1 response + fi if [[ -z ${response} ]] ; then response="n" ; fi case ${response} in [Yy]) From c0c6f2b5d7b5d29f79819005ac71e722522c830d Mon Sep 17 00:00:00 2001 From: Barry Jackson Date: Fri, 30 Jun 2023 12:27:24 +0100 Subject: [PATCH 6/7] Also ignore kernel-source packages when displaying kernels to remove --- remove-old-kernels | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remove-old-kernels b/remove-old-kernels index 620c98c..570aaee 100755 --- a/remove-old-kernels +++ b/remove-old-kernels @@ -442,7 +442,7 @@ if (( ${#dnfmssg} > 0 ));then echo -e "${dnfmssg}"; fi #================================= Mode of execution =================== # Check there are kernels to remove -nbktr=$(grep -v devel < "${TMPKTR}"|wc -l) +nbktr=$(grep -vc 'devel\|source' < "${TMPKTR}") nbt=$(wc -l < "${TMPKTR}") if (( nbt != 0 )) ; then # Check if we are in preview mode @@ -467,7 +467,7 @@ if (( nbt != 0 )) ; then fi # Warn if we are not root and exit hang until spacebar if (( UID > 0 )); then - echo -e "${RemvCol}$(i18n "Must be root to allow removal")${Normal}\n$(i18n "Tap spacebar to exit")" + echo -e "${RemvCol}$(i18n "Must be root to allow removal")${Normal}\n$(i18n "Tap spacebar")" read -r -n1; echo -en "${ClearLine}" exit 0 fi From 5e8254713bec690b4a96b8f2bf7cb9bbd42bb3f7 Mon Sep 17 00:00:00 2001 From: Barry Jackson Date: Fri, 30 Jun 2023 13:01:47 +0100 Subject: [PATCH 7/7] minor typos --- remove-old-kernels | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remove-old-kernels b/remove-old-kernels index 570aaee..5c88643 100755 --- a/remove-old-kernels +++ b/remove-old-kernels @@ -465,7 +465,7 @@ if (( nbt != 0 )) ; then rm -f "${TMPKTR}" exit 0 fi - # Warn if we are not root and exit hang until spacebar + # Warn if we are not root and hang until spacebar hit if (( UID > 0 )); then echo -e "${RemvCol}$(i18n "Must be root to allow removal")${Normal}\n$(i18n "Tap spacebar")" read -r -n1; echo -en "${ClearLine}" @@ -559,4 +559,4 @@ rm -f "${TMPKTR}" # Run again if some removable kernels are left (( UID > 0 )) && exit 0 # Not root user so exit [[ ${MODE} != "I" ]] && exit 0 # Auto so exit -(( nbt > 0 )) && ${0} # Root user and interactive so run again if removable kernels left +(( nbt > 0 )) && ${0} # Root user and interactive so run again if removable packages left