#!/bin/bash

# pd_sunappu_shashin la 27.3.2010 21.42.28 +0200
#
# la 27.3.2010 21.42.28 +0200: First release.



source "${XDG_CONFIG_HOME:-$HOME/.config}/mariginari/pd_sunappu_shashin" >/dev/null 2>&1 || exit 1
test "x$FILMLIST" = "x" && exit 1
test -r "$FILMLIST" || exit 1

PATH="$HOME/bin:$PATH"
test -x `which sunappu_shashin >/dev/null 2>&1` || exit 1

number=0
while read line
do
	if [ -r "$line" ]
	then
		number=`expr $number + 1`
		film[$number]=$line
	fi
done < "$FILMLIST"
test $number -lt 1 && exit 1

# No need to pick if there's only one.
pick=1
if [ $number -gt 1 ]
then
	pick=0
	while [ "$pick" -lt 1 ]
	do
		pick=$RANDOM
		let "pick %= `expr $number + 1`"
	done
fi
FILM=${film[$pick]}

sunappu_shashin "$FILM"