#!/bin/bash
#======================================#
# Simple update notifier version 0.3.7 #
#======================================#

if test -f "/usr/share/simple-notifier/scripts/update-intervals-"; then
exec /usr/share/simple-notifier/'Enable Updates'
exit 0
fi
# Kill and restart if logout/in
pkill -f 'Simple Update Notifier' > /dev/null 2>&1 
PID=`ps -eaf | grep update-intervals | grep -v grep | awk '{print $2}'`
if [[ "" !=  "$PID" ]]; then
  echo "killing $PID"
  kill -9 $PID 
fi &
pkill -f 'Updates Available' > /dev/null 2>&1
# Run simple notifier
function main () {
CONF="/var/tmp/.simple-notifier"
NUM_UPDATES=$(cat /var/tmp/.simple-notifier/num_updates | awk 'NR==1{print $0}')
NO_UPDATES=0
sleep 15;
# Check if already running
RUN=$(ps -ef | grep "update-intervals" | grep -v grep | wc -l)
if [ ${RUN} -gt 1 ]; then
echo "update-intervals is running"
else
/usr/share/simple-notifier/scripts/update-intervals
fi &
CHECK=$(cat /var/tmp/.simple-notifier/num_updates | awk 'NR==1{print $0}')
if [ "$NO_UPDATES" -eq "$CHECK" 2>/dev/null ]; then
echo "0" > /var/tmp/.simple-notifier/up2date
fi
NUM_UPDATES=$(cat /var/tmp/.simple-notifier/num_updates | awk 'NR==1{print $0}')
if [ "$NUM_UPDATES" -gt "$NO_UPDATES" 2>/dev/null ]; then
echo "1" > /var/tmp/.simple-notifier/up2date
fi
 }
   main
exit 0


