09-09-2014, 03:14 AM
OK so I made a lot of changes.
First the script checks if there are any old kernels/headers...
If there are no old kernels it will just display a message.
This version will purge any output it gets from $checklist.
If no item was selected it will display a message 'Nothing was selected.'.
Cancel button in the progress bar is hidden.
The only thing I can't fix is that message when I click on Quit: 'Nothing was selected.'.
I guess I can always change the message to 'Nothing was selected or you pressed Quit.'
First the script checks if there are any old kernels/headers...
If there are no old kernels it will just display a message.
This version will purge any output it gets from $checklist.
If no item was selected it will display a message 'Nothing was selected.'.
Cancel button in the progress bar is hidden.
The only thing I can't fix is that message when I click on Quit: 'Nothing was selected.'.
I guess I can always change the message to 'Nothing was selected or you pressed Quit.'
Code:
#! /bin/bash
ic="/usr/share/icons/zenity-llcc.png"
CURKERNEL=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g')
LINUXPKG="linux-(image|headers|ubuntu-modules|restricted-modules)"
METALINUXPKG="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)"
OLDKERNELS=$(dpkg -l|awk '{print $2}'|grep -E $LINUXPKG |grep -vE $METALINUXPKG|grep -v $CURKERNEL)
# check if there are old kernels
echo "$OLDKERNELS" | grep linux*
if [ $? = 1 ]; then
zenity --error \
--title="Error" --text="No old Kernels found."
exit 0
fi
# sed command adds all FALSE entries in the column 'Select'
# separator sets the separator in the output of the checklist, could be a new line \n or anything else
selection=$(echo "$OLDKERNELS" | sed -e 's/^/FALSE\n/' | zenity --window-icon="$ic" --list --checklist --separator=" " --width=890 --height=400 --column='Select' --column='Kernel' \
--text=' ' --title="Lite Cleaner" --ok-label="Clean" --cancel-label="Quit" )
#check if any item was selected
echo "$selection" | grep linux*
if [ $? = 1 ]; then
zenity --error \
--title="Error" --text="Nothing was selected."
exit 0
fi
zenity --question --title="Question" --text="Do you want to proceed?"
if [ "$?" -eq "0" ]; then
gksudo -g --message 'To run this cleaner your password is required. Enter your password, or press Cancel.' "sudo apt-get purge -y $selection" | zenity --progress --title='removing kernel/header' --text='Uninstalling...' --no-cancel --pulsate --width=400 --auto-close --auto-kill
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
zenity --error \
--title="Error" --text="Uninstall has failed."
exit 0
fi
else
exit 0
fi
PROCEED=$(zenity --info --title="Cleaner" --text="The cleaner has finished."; echo $?)
if [ ${PROCEED} -eq 1 ]; then
zenity --info --title='Cleaner' --text='Clean Complete.'
exit 0
fi
exit 0