#Qole's rndback script for choosing a random wallpaper
#to display with the setback script.
#Thanks Grog for the awk random number script!

#Pull in the config, if possible...
[ -f /home/user/.wallpaper ] && . /home/user/.wallpaper

#These come from the config file... If not, fall back on defaults
[ "x$IMGTYPE" != x ] || IMGTYPE="jpg\|png\|gif"
[ "x$IMGDIRS" != x ] || IMGDIRS="/home/user/MyDocs/.images /usr/share/backgrounds"
find $IMGDIRS | grep -i "\.\($IMGTYPE\)" > /tmp/wplist.txt
TOTIMGS=`wc -l < /tmp/wplist.txt`

# Pick out a random line from the list
# (Thanks, Grog!)
RNDIMG=`awk -v tot=$TOTIMGS 'BEGIN {srand();printline=(rand()*10000%tot)+1;printline=substr(printline,1,index(printline,".")-1)} NR==printline' /tmp/wplist.txt`

echo changing to $RNDIMG
setback "$RNDIMG"
