#!/bin/sh
# Author: Brendan Hide (http://swiftspirit.co.za/)
# Copyright: (c) Brendan Hide 2013, released under the GPLv3 license
#            See http://www.gnu.org/licenses/gpl-3.0.html for the License details
# Name: pacman-update-check
# Release Version: 0.1 (2013-01-04)
# TODO: lock file
# Description: check which packages are available for updates - ideally use with crontab set to email any results to the system administrator
#set -x                                                                                                                                                  
set -e                                                                                                                                                   
set -u                                                                                                                                                   
                                                                                                                                                         
SELF=${0##*/}                                                                                                                                            

#Check we're root
if [ $EUID -ne 0 ] ; then
 echo "$SELF must be run as root" 1>&2
 exit 1
fi

RAND=$RANDOM
TMP=/tmp/$SELF.$RAND.$$

PACLIB="/var/lib/pacman/"
grep ^DBPath /etc/pacman.conf | tail -n 1 | grep . 2>&1 /dev/null && PACLIB=$(grep ^DBPath /etc/pacman.conf | tail -n 1)

rsync -a $PACLIB/* $TMP/

pacman -Syb $TMP 2>&1 > /dev/null

package-query -QAub $TMP

rm -rf $TMP
