#!/bin/bash
#
# Phonecam v.5
#
#
# For the latest edition of this script:
# see http://freenetworks.org/~mattw/badsoftware/phonecam/
#
# For an example of this script in action, see http://16photos.com/
#
# It is a modified version of roadcam shell script: http://haavi.iki.fi/roadcam/
#
# The code has been refined for t-mobile and pulls out the masthead sent with the images
#
# the system also give the name of the image send
#
#
#
##############################

 

export PATH=/bin:/usr/bin:/usr/local/bin

filepath="/your/path/"
tmp="/tmp"

baseref="http://your.site.com/"
title="photo search feed"
notify="name@your.address.com"

perpage="15"

# thumbnail sizes
tlandscape="240x160"
tportrait="160x240"

# latest.jpg sizes
llandscape="150x90"
lportrait="90x150"

imgdir="images"
html="html"
arcdate=`date +%D`
arcdate=${arcdate//\//.} # replace all / with

umask 022

 

if [ ! -f $filepath/count ]; then
echo "0" > $filepath/count
fi

if [ ! -f $filepath/arc.txt ]; then
touch $filepath/arc.txt
fi

if [ ! -d $filepath/archive ]; then
mkdir $filepath/archive
fi

if [ ! -d $filepath/$html ]; then
mkdir $filepath/$html
fi

if [ ! -d $filepath/$imgdir ]; then
mkdir $filepath/$imgdir
fi

#grep ^From: > $filepath/sender.txt

 

count=`head -1 $filepath/count`

mkdir $tmp/.$$
cd $tmp/.$$
munpack > /dev/null 2>&1

 

#grep From: tmp
#sender= ` sed 's/From:/ /g'`

#echo "$sender" > $filepath/email.txt

 

 

for i in *.jpg; do
sleep 1
f=`identify $i`
a=`basename $i .jpg`
time=`date +%s`
name="$a"
m="masthead"

if [ "$name" != masthead ] #if to pull out the masthead .jpg
then

echo "$time" > $filepath/stamp.txt
echo "$name" > $filepath/vari.txt #adds the title sent with the image



mv $i $filepath/$imgdir/$name.jpg

f=${f/+0*/}
f=${f/* /}
x=${f/x*/}
y=${f/*x/}

#you may need to do a "whereis convert"

/usr/bin/X11/convert -resize 200x200 $filepath/$imgdir/$name.jpg $filepath/$imgdir/$name.thumb.jpg #> $filepath/error.txt 2>&1
/usr/bin/X11/convert -resize 150x150 $filepath/$imgdir/$name.jpg $filepath/cell.jpg #> $filepath/error.txt 2>&1
/usr/bin/X11/convert -resize 100x100 $filepath/$imgdir/$name.jpg $filepath/latest.jpg #> $filepath/error.txt 2>&1
/usr/bin/X11/convert -resize 200x200 $filepath/$imgdir/$name.jpg $filepath/thumb.jpg

 

# make the new page

[ -f $filepath/new.txt ] && cat $filepath/new.txt > $filepath/new.tmp
echo "<tr><th scope="col"><p align="left"><a href=\"$baseref/$html/$time.shtml\"><img src=\"$baseref/$imgdir/$name.thumb.jpg\" border=0></a></p></th><th scope="col"><p align="right"><a href=\"$baseref/text/$time.shtml\"><span class="style3">"$name"</span></a></p></th></tr>"> $filepath/new.txt
cat $filepath/new.tmp >> $filepath/new.txt 2> /dev/null
rm -f $filepath/new.tmp

 

# make small page for wap or xhtml

# [ -f $filepath/newsmall.txt ] && cat $filepath/newsmall.txt > $filepath/newsmall.tmp
echo "<img src=\"$baseref/latest.jpg\"><br><br>" > $filepath/newsmall.txt
#cat $filepath/newsmall.tmp >> $filepath/newsmall.txt 2> /dev/null
# rm -f $filepath/newsmall.tmp

 

 

# make the individual photo page

echo "<html>
<head>
<title>title</title>
<link rel=stylesheet href=$baseref/style.css type='text/css'>
</head>
<body>
<center><img src=\"$baseref/$imgdir/$name.jpg\" border=1></center><!--#include virtual="$filepath/text/$time.txt"--> <br>



<p><center>" > $filepath/$html/$time.shtml

[ -f $a.desc ] && cat $a.desc >> $filepath/$html/$time.shtml

#<br><!--#include virtual="$filepath/text/$time.txt"-->
echo "<!--#include virtual="$filepath/text/$time.txt"-->" >>$filepath/$html/$time.shtml
echo "</center></body></html>" >> $filepath/$html/$time.shtml

count=$((count+1))

 

/usr/bin/perl $filepath/gsearch.cgi > $filepath/error.txt 2>&1

#file_six=`/usr/bin/perl -e $filepath/gsearch.cgi`; # ' -e 'print $file_list[5];'`
#echo $file_six


fi
done

 

 

 

 

echo $count > $filepath/count

if [ "$count" -eq 1 ]; then
echo "There is 1 image in the queue" > $filepath/notify
else
echo "There are $count images in the queue" > $filepath/notify
fi

if [ "$count" -ge "$perpage" ]; then
echo "<html><head><title>$title</title><link rel=stylesheet href=$baseref/style.css type='text/css'></head><body><center>" > $filepath/archive/$time.shtml
[ -f $filepath/index.txt ] && cat $filepath/index.txt >> $filepath/archive/$time.shtml
cp $filepath/new.txt $filepath/index.txt
rm -f $filepath/count
rm -f $filepath/new.txt
cat $filepath/arc.txt > $filepath/arc.tmp
echo "<li><a href=\"$baseref/archive/$time.shtml\">$arcdate</a></li>" >> $filepath/arcn.txt
cat $filepath/arc.tmp >> $filepath/arcn.txt
rm -f $filepath/arc.tmp
mv $filepath/arcn.txt $filepath/arc.txt

echo "There are no new images in the queue" > $filepath/notify
fi

 

 

cat << EOF > $filepath/rss.xml
<?xml version="1.0"?>

<!-- name="generator" content="$title" -->
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">
<channel>
<title>$title</title>
<link>$baseref</link>
<description>$title</description>
<language>en</language>

<item>
<title>$title</title>
<link>$baseref/$html/$time.shtml</link>
<description>
&lt;img src=&quot;$baseref/$imgdir/$name.thumb.jpg&quot;&gt;&lt;br&gt;
</description>
</item>

</channel>
</rss>

EOF

 

 

 

if [ "$notify" ]; then
echo "Photo $name has been added to new feed ($count / $perpage)view it at http://your.site.com/cell.html" | mail $notify
fi

 

 

 

rm -rf $tmp/.$$

echo "<!--#include virtual="title.txt"--><br><!--#include virtual="summary.txt"--><br><!--#include virtual="snippet.txt"--><br><!--#include virtual="url.txt"-->" > $filepath/result.txt

#
# End
#