#!/bin/bash -e
#
# Simple wrapper for the SVGA Photo-CD Viewer pcdview.
# Greps cdrom-location from user .xpcdrc && let the user choose graphics mode.
# Then it shows all images of the Photo CD in "one run".
#
# Supplied for the Debian version of xpcd by Stephan Alexander Suerken <absurd@debian.org>
#
pcdview=pcdsvgaview
xpcdrc_file=${HOME}/.xpcdrc
graphic_mode_default=21


#
# Smartly find out a default cdrom loacation
#
if test -e ${xpcdrc_file} ;
   then photo_cd_location_default=`grep cdrom ${xpcdrc_file} | cut -d= -f2 | tr --delete [:space:]`;
        echo "Using Photo CD location default from ${xpcdrc_file}.";
   else echo "Could not find file '${xpcdrc_file}'.";
        echo "Thusly, I cannot determine your default Photo CD location.";
        echo "(You may change this by using xpcd once.)";
        echo "Using stubborn Photo CD location default.";
        photo_cd_location_default="/cdrom" ;
fi

#
# Read cdrom location
#
echo -n "Select the location of the Photo CD [${photo_cd_location_default}]: ";
read photo_cd_location
if test "${photo_cd_location}" == "";
   then photo_cd_location=${photo_cd_location_default};
        echo "Using default location ${photo_cd_location_default}..."
fi

#
# Read graphics mode
#
echo
echo "Available graphic modes"
echo "-----------------------"
${pcdview} -l
echo "-----------------------"
echo -n "Choose a graphic mode [${graphic_mode_default}]: "
read graphic_mode
if test "${graphic_mode}" == "";
   then graphic_mode=${graphic_mode_default};
        echo "Using default mode ${graphic_mode_default}..."
fi

#
# Run pcdview
#
${pcdview} -m${graphic_mode} $* ${photo_cd_location}/photo_cd/images/*
