This is a quick&dirty script that pushes pictures onto my web server, does
some sensible resizing, and fixes up some igal stupidities on the
way. (I only use it locally nowadays, with -foo.) |
|
#!/bin/bash # settings LOCALBASEDIR=`echo "/home/user/photo"` REMOTEBASEDIR=`echo "/var/www/photos/"` HTMLBASE=`echo "http://www.user.invalid/photos"` REMOTEHOST=`echo "remote.user.invalid"` QUALITY=`echo "60"` CWD=`pwd` if [ "$1" != "-foo" ]; then echo -n "Input directory name: " read DIRNAME DIR=`echo "$LOCALBASEDIR/$DIRNAME"` echo "Directory set to $DIR" if [ -d "$DIR" ]; then echo "$DIR already exists. Exiting." exit `/bin/false` fi echo "$DIR does not exist. Attempting to create it..." mkdir "$DIR" || exit `/bin/false` cd "$DIR" || exit `/bin/false` echo "$DIR created and cwd now" gphoto2 -P && gphoto2 -D fi # make sure the extensions are what the rest of the script assumes if [ ! -f "*.JPG" ]; then for i in `ls -1 *.jpg`; do NAME=`echo "$i" | sed s/"\.jpg"/"\.JPG"/g` mv "$i" "$NAME" done fi for i in `ls -1 *.JPG`; do echo -n "downsizing $i.." BASE=`echo "$i" | sed s/"\.JPG"//g` convert -size 800x600 -quality "$QUALITY" "$i" -resize 800x600 "$BASE.jpg" mv "$i" "$i.foo" echo "done." done echo " " echo "running igal.." igal --www -as echo " " echo -n "fixing html-files.." for i in `ls -1 *.html`; do cat "$i" | sed s/"width\=\ "//g | sed s/"height\=\ "//g >"$i.new" cat "$i.new" | sed s/"\(.P\ class..center.*\(.*\/.*\)\)"/"\1 (click on picture for original size)"/g >"$i" # mv "$i.new" "$i" done echo "done." set -e DIRNAME=`pwd | sed s/".*\/"//g` #ssh -x "$REMOTEHOST" mkdir "$REMOTEBASEDIR/$DIRNAME" #scp -i *html .i* .s* .t* *.jpg *.css "$REMOTEHOST:$REMOTEBASEDIR/$DIRNAME" mkdir "$REMOTEBASEDIR/$DIRNAME" cp -v *html .i* .s* .t* *.jpg *.css "$REMOTEBASEDIR/$DIRNAME" echo -n "cleaning up.." rm *.jpg *.html .i* .s* .t* for i in `ls -1 *.foo`; do NAME=`echo "$i" | sed s/"\.foo"//g` mv "$i" "$NAME" done echo "done" echo "Copying original files..." for i in `ls -1 *.JPG`; do NAME=`echo "$i" | sed s/"\.JPG"/"\.jpg"/g` mv "$i" "$NAME" done #ssh -x "$REMOTEHOST" mkdir "$REMOTEBASEDIR/$DIRNAME/orig" #scp *.jpg "$REMOTEHOST:$REMOTEBASEDIR/$DIRNAME/orig/" mkdir "$REMOTEBASEDIR/$DIRNAME/orig" cp -v *.jpg "$REMOTEBASEDIR/$DIRNAME/orig/" #ssh -x "$REMOTEHOST" chmod 755 "$REMOTEBASEDIR/$DIRNAME/orig" #ssh -x "$REMOTEHOST" chmod 644 "$REMOTEBASEDIR/$DIRNAME/orig/*" chmod 755 "$REMOTEBASEDIR/$DIRNAME/orig" chmod 644 $REMOTEBASEDIR/$DIRNAME/orig/* cd "$CWD" echo " " echo "copy/paste URL: $HTMLBASE/$DIRNAME/index.html" echo " " exit `/bin/true`