thefoggiest.dev

Scripting Scry

Yesterday, I wrote about Scry, a PHP photo publishing script that I basically like for the same reasons I like my favorite Linux distribution: simplicity and elegance make it easy to use and to maintain.

To make things even easier, tonight I wrote a small bash script that allows me to publish a collection of pictures on my hard drive to the Scry installation on my server. Here is is:

#!/bin/bash

targethost=target host or ip
target="/local/path/to/collection"
imgwidth=publication full size with
tmp=/tmp/scryify

EXPECTED_ARGS=2
E_BADARGS=65

if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` </local/path/to/collection/ </remote/path/to/supercollection>"
exit $E_BADARGS
fi

source=$1
name=`basename "$source"`
target=$target/$2
targetdir=$(echo "$target/$name/" | sed 's/ /\\ /g')
tmpdir=$(echo "$tmp/$name" | sed 's/ /\\ /g')

echo "Copying originals"
mkdir -p $tmp
cp -R "$source" $tmp/

echo "Processing copies"
find "$tmp/$name" -name *JPG -print0 | while read -d $'\0' file
do
jhead -q -autorot "$file" > /dev/null
mogrify -scale $imgwidth "$file"
jhead -q -n%Y%m%d%H%M%S_%f "$file" > /dev/null
done

echo "Publishing copies"
ssh $targethost mkdir -p "$targetdir"
eval cd "$tmpdir"
scp *jpg $targethost:"$targetdir/" > /dev/null

echo "Cleaning up"
rm -rf $tmp
[/sourcecode]

If you want to use this, you will need to adapt some of the lines 3 through 6 to your set up. Path names are without closing slashes and should be enclosed in parentheses when they contain spaces. imgwidth Is the width of the picture when your visitor clicks the full screen link.

The script needs an ssh server running on the server. Setting up key authorization is useful if you want to be able to start the script and do other things while it runs. Obviously, mogrify and jhead must be present as well, as does sed. The former will most likely be part of the ImageMagick package.

Put the script in a file with a name you will remember (I call it scryify), make the file executable and put it in a directory in your path. The script takes two arguments, the full path to the collection on your hard drive and the path below the directory on the server where Scry keeps its collections under which you want the collection to be published.

For instance, if you order your collections per year, like me, and you have pictures of last years Christmas dinner in a local folder /home/me/pictures/Christmas dinner/, you would issue:

# scryify /home/me/pictures/christmas\ dinner/ 2010

The script will run (and tell you what it is doing) and when you get your prompt back, you can go to your photo site and voilĂ , there they are. Well, at least at my site it works, but obviously there are no guarantees. Also, use at your risk.


Categorised as: cool stuff


Comments are closed.