#!/bin/bash

# A script to create an automatic HTML slideshow
# Possibly to be used for a screen saver
# Created by Ben Tasker


# Images need to have similar filenames with a unique numeral in them

getsettings ()
{

# Get config from user
clear 
echo "All image files should reside in the same directory and should all be named in the same format."
echo ""
echo "For example they should all be named SSXXXX.jpg where XXXX is a numeral"
echo "All files Should contain a unique numeral, which should increase by one between files"
echo ""
echo "The order of the numbers will determine the order of the slideshow"
echo ""
echo "The next few questions will determine the filenames to reference, Please do not enter the numerical element of the filename in the prefix or suffix"
echo ""
echo "Please enter the prefix of the filename (i.e. ss if the filenames follow the convention ssXXXX.jpg)"
read PREFIX
echo "Please enter the suffix of the image filename (i.e. .jpg using the above example)"
read IMAGESUFFIX
echo "Please enter the Start Image Number (may not necessarily be 1)"
read TITLE
echo "Please enter the final Image Number"
read ENDTITLE
echo ""
echo "Ok please now define a title to use for the HTML pages, please avoid special characters"
read PAGETITLE
clear
echo "OK please wait while I generate the pages"
# OK we now have the information we need
FINALLINK="$PREFIX""$TITLE""$SUFFIX"

mainfunction
}

mainfunction ()
{
# check for the last image

if [ "$TITLE" == "$ENDTITLE" ]
then
# Final Title

NEXTFILE=$FINALLINK
FILENAME="$PREFIX""$TITLE""$SUFFIX"
IMAGENAME="$PREFIX""$TITLE""$IMAGESUFFIX"

# Generate the html

echo "<html>" > $FILENAME
echo "<head>" >> $FILENAME
echo "<title>$PAGETITLE</title>" >> $FILENAME
echo "<meta content="">" >> $FILENAME
echo "<meta http-equiv=refresh content=5;$NEXTFILE >" >> $FILENAME
echo "<style></style></head>" >> $FILENAME
echo "<body style='color: rgb(0, 0, 0); background-color: rgb(255, 204, 204);'" >> $FILENAME
echo "alink='#000099' link='#000099' vlink='#990099'>" >> $FILENAME
echo "<div style='text-align: center;'><big><big><span" >> $FILENAME
echo "style='font-family: century schoolbook l; font-weight: bold; text-decoration: underline;'>" >> $FILENAME 
echo "</span></big></big><span " >> $FILENAME
echo "style='font-family: century schoolbook l;'><img alt='' " >> $FILENAME
echo "src=Images/$IMAGENAME ><br> " >> $FILENAME
echo "<br><br></span></div></body></html>" >> $FILENAME
echo "Generation Complete"

else
# All titles from START until END

# Create filenames

NEXTFILESEED=$(( $TITLE + 1 ))
NEXTFILE="$PREFIX""$NEXTFILESEED""$SUFFIX"
FILENAME="$PREFIX""$TITLE""$SUFFIX"
IMAGENAME="$PREFIX""$TITLE""$IMAGESUFFIX"

# Generate the html

echo "<html>" > $FILENAME
echo "<head>" >> $FILENAME
echo "<title>$PAGETITLE</title>" >> $FILENAME
echo "<meta content="">" >> $FILENAME
echo "<meta http-equiv=refresh content=5;$NEXTFILE >" >> $FILENAME
echo "<style></style></head>" >> $FILENAME
echo "<body style='color: rgb(0, 0, 0); background-color: rgb(255, 204, 204);'" >> $FILENAME
echo "alink='#000099' link='#000099' vlink='#990099'>" >> $FILENAME
echo "<div style='text-align: center;'><big><big><span" >> $FILENAME
echo "style='font-family: century schoolbook l; font-weight: bold; text-decoration: underline;'>" >> $FILENAME 
echo "</span></big></big><span " >> $FILENAME
echo "style='font-family: century schoolbook l;'><img alt='' " >> $FILENAME
echo "src=Images/$IMAGENAME ><br> " >> $FILENAME
echo "<br><br></span></div></body></html>" >> $FILENAME
echo "Generated file $FILENAME"
TITLE=$(( $TITLE + 1 ))
mainfunction
fi

exit




}


getsettings