#!/bin/bash
# Created by Ben Okopnik on Wed Sep 19 16:55:05 EDT 2007

################### User config ###########################
lf_dir="/var/www/lf"
################### User config ###########################

cd $lf_dir/galleries
galleries=$(echo $(/bin/ls -d *| grep -v '\.conf'))
cd - > /dev/null

g=`echo $galleries|/bin/sed 's/ /$\|^/g'`
echo "Which gallery would you like to get the image FROM?"
while [ -z `echo "$choice1"|/bin/egrep "^$g$"` ]
do
	echo "(Choices: $galleries)"
	read choice1
done

echo "=================================================================="
grep -n $ "$lf_dir/galleries/$choice1/config"|sed 's/:/:  /'
echo "=================================================================="

echo "Please select the number for the image you want to move."
read num
line=`sed -n "${num}p" "$lf_dir/galleries/$choice1/config"`
img=`echo $line|sed 's/}.*//'`
echo "OK, we're moving image $img. Which gallery would you like to move the image TO?"
while [ -z `echo "$choice2"|/bin/egrep "^$g$"` ]
do
	echo "(Choices: $galleries)"
	read choice2
done

[ "$choice1" == "$choice2" ] && { echo "$choice1 is the same as $choice2."; exit; }

for n in small preview large xlarge
do
	mv "$lf_dir/galleries/$choice1/$n/$img" "$lf_dir/galleries/$choice2/$n/$img"
done	

conf1="$lf_dir/galleries/$choice1/config"
conf2="$lf_dir/galleries/$choice2/config"

echo $line >> $conf2
sed -i "/^$img/d" $conf1

