#!/bin/bash
xhost local:$USER > /dev/null 2>&1
export DISPLAY=:0
tmpfile=/tmp/lun
ionice -c2 -p$$ -n 7;nice -n 19 apt-get update >/dev/null 2>&1
UPD=$(apt-get -s dist-upgrade | awk '/[0-9]+ upgraded,/ {print $1 " package updates are available"}' && echo && echo Click here to remove this message); echo $UPD > $tmpfile
if sed -n '/\b0 package\b/p' $tmpfile | grep -q 'package'; then
	if [ -f "/usr/local/sbin/.updnotify" ]; then
		:
	else 
		notify-send -i /usr/share/icons/Faenza/places/48/distributor-logo-ubuntu.png 'Lite Updates Notify' "Your system is up to date" & touch "/usr/local/sbin/.updnotify"
	fi
else
    notify-send -i /usr/share/icons/Faenza/apps/48/system-software-installer.png 'Install Updates' "$UPD"
    rm -f "/usr/local/sbin/.updnotify" >/dev/null
fi
xhost - >/dev/null 2>&1
rm -f $tmpfile

# Report number of kernels installed, recommend to keep a minimum of 2 installed
numkern=`ls /boot/ | grep vmlinuz | wc -l`
oldkerns=`expr $numkern - 2`

if test $numkern -gt 3; then
	notify-send -t 15000 -i /usr/share/liteappsicons/lite-updatesnotify/linuxkernel.png 'Kernel Notice' "You have $numkern kernels installed.\n\nConsider removing the $oldkerns oldest Kernels\nvia Lite Tweaks to free up space on your computer."
else
	echo " "
fi

exit