Index of /~mattw/badsoftware/phonecam
Name Last modified Size Description
Parent Directory 29-Mar-2008 23:47 -
TODO 29-Mar-2008 23:47 1k
index.shtml.txt 29-Mar-2008 23:47 1k
phonecam.sh 29-Mar-2008 23:47 2k
phonecamv2.sh 29-Mar-2008 23:47 4k
phonecamv3.sh 29-Mar-2008 23:47 4k
phonecamv4.sh 29-Mar-2008 23:47 4k
phonecamv5.sh 29-Mar-2008 23:47 6k
#!/bin/bash
#
# Phonecam v.5
#
# This script allows you to publish attached images sent to an email account.
# I use it to post pictures to a webpage from my Nokia 3650.
#
#
# 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/
#
# Dependencies include convert, munpack, and procmail
#
# What's changed from the original roadcam script?
#
# - It now displays images in reverse chronological order,
# so you get the newest stuff at the top of the page.
#
# - It creates a mini-thumbnail called latest.jpg so you can
# stick it somewhere else(like your sidebar or whatever)
#
# - rss.xml is now created with your latest image. uses thumbnail url
# rather than latest.jpg for out of sync reads
#
# - Rather than creating html pages, it creates .txt files
# for inclusion in your formatted index page
#
# - Auto archival
#
# - less hardcoding, easy configuration
#
# New stuff added by rob since v4:
#
# - landscape vs. portrait detection for thumbnails: No more strangely
# stretched thumbnails. Just set the landscape and portrait sizes you
# want for the thumbnails and latest.jpg.
#
# - notify variable: set to an email address (SMS, perhaps?) if you want
# notification when a photo is added. Leave it undefined to disable.
#
# - (more or less) correctly handles multiple images per email
#
# - style sheet support
#
# - general cleanup and elimination of awk, sed, and expr. Shell variable
# replacement is your *friend*.
#
# Installation is pretty straightforward.
# Change the defaults and this rule to your .procmailrc
#
#
# :0
# * ^TOyoursecretaddress@yourdomain.com
# | /home/username/bin/phonecam.sh
#
# add this to your index.shtml or whatever you're going to
# include your pictures in.
#
# to display pictures
#
# <!--#include virtual="index.txt"-->
#
# for the archive list
#
# <!--#include virtual="arc.txt"-->
#
# for the queue
#
# <!--#include virtual="notify"-->
#
# These defaults must be changed for things to work
#
export PATH=/bin:/usr/bin:/usr/local/bin
filepath="/home/user/phonecam/htdocs"
tmp="/tmp"
baseref="http://your.server.com/phonecam"
title="My Phonecam"
#notify="1115551212@mobile.att.net"
perpage="16"
# thumbnail sizes
tlandscape="240x160"
tportrait="160x240"
# latest.jpg sizes
llandscape="150x90"
lportrait="90x150"
imgdir="img"
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
count=`head -1 $filepath/count`
mkdir $tmp/.$$
cd $tmp/.$$
munpack > /dev/null 2>&1
for i in *.jpg; do
sleep 1
time=`date +%s`
f=`identify $i`
a=`basename $i .jpg`
mv $i $filepath/$imgdir/$time.jpg
#
# Identify portrait or landscape.
# Here there be dragons.
#
f=${f/+0*/}
f=${f/* /}
x=${f/x*/}
y=${f/*x/}
if [ "$x" -gt "$y" ]; then
thumbsize=$tlandscape
latestsize=$llandscape
else
thumbsize=$tportrait
latestsize=$lportrait
fi
convert -resize $thumbsize $filepath/$imgdir/$time.jpg $filepath/$imgdir/$time.thumb.jpg
convert -resize $latestsize $filepath/$imgdir/$time.jpg $filepath/latest.jpg
# make the new page
[ -f $filepath/new.txt ] && cat $filepath/new.txt > $filepath/new.tmp
echo "<a href=\"$baseref/$html/$time.html\"><img src=\"$baseref/$imgdir/$time.thumb.jpg\" border=0></a>" > $filepath/new.txt
cat $filepath/new.tmp >> $filepath/new.txt 2> /dev/null
rm -f $filepath/new.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/$time.jpg\" border=1></center>
<p><center>" > $filepath/$html/$time.html
[ -f $a.desc ] && cat $a.desc >> $filepath/$html/$time.html
echo "</center></body></html>" >> $filepath/$html/$time.html
count=$((count+1))
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.html
[ -f $filepath/index.txt ] && cat $filepath/index.txt >> $filepath/archive/$time.html
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.html\">$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.html</link>
<description>
<img src="$baseref/$imgdir/$time.thumb.jpg"><br>
</description>
</item>
</channel>
</rss>
EOF
if [ "$notify" ]; then
echo "Photo added to phonecam ($count / $perpage)" | mail $notify
fi
rm -rf $tmp/.$$
#
# End
#