Skip to content

Commit

Permalink
Merge pull request #18 from barjac/bug31969
Browse files Browse the repository at this point in the history
Fix for Mga#31969
  • Loading branch information
barjac committed Jun 30, 2023
2 parents c46514a + 5e82547 commit daaff0c
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions remove-old-kernels
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ if (( UID > 0 )); then
fi
}

# Warn when not root
RootWarn() {
if (( UID > 0 )); then
echo -e "${RemvCol}$(i18n "Must be root to allow removal")${Normal}"
return 1
else
return 0
fi
}

# Function to handle -f or -F options
altcfg() {
cfgno=$1
Expand Down Expand Up @@ -452,6 +442,7 @@ if (( ${#dnfmssg} > 0 ));then echo -e "${dnfmssg}"; fi
#================================= Mode of execution ===================

# Check there are kernels to remove
nbktr=$(grep -vc 'devel\|source' < "${TMPKTR}")
nbt=$(wc -l < "${TMPKTR}")
if (( nbt != 0 )) ; then
# Check if we are in preview mode
Expand All @@ -474,20 +465,27 @@ if (( nbt != 0 )) ; then
rm -f "${TMPKTR}"
exit 0
fi
# Warn if we are not root
RootWarn
# 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}"
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}"
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
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])
Expand Down Expand Up @@ -561,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

0 comments on commit daaff0c

Please sign in to comment.