#!/bin/bash
-destdir=/some/path # Optional: Fill this in here.
+destdir=
+if [[ -e .default-pic-mv-destdir ]];then
+ destdir=$( < .default-pic-mv-destdir )
+fi
exposure=
rotate=
done
shift `expr $OPTIND - 1`
+if [[ -z "$destdir" ]];then
+ echo "Please specify a destdir with -d or .default-pic-mv-destdir" >&2
+ exit 1
+fi
+
file="$1"
name="$2"
+re_escaped_name=$(sed 's/[?+*.]/\\&/g' <<< "$name")
+
# Find next number
-max=$(ls "$destdir" | sed -rn "s/^$name ([0-9]+).jpeg$/\1/p" | sort -n | tail -n1)
+max=$(ls "$destdir" | sed -rn "s/^$re_escaped_name ([0-9]+).jpeg$/\1/p" | sort -n | tail -n1)
if [[ "$max" ]];then
number=$((max + 1))
else
if [[ "$file" == *.NEF ]];then
base="${file%.NEF}"
+ NEFout="$destdir/$name $number.NEF"
if [[ "$rotate" ]];then
numeric_exposure=$(dc <<< "2k $exposure 4 / 3.5-p")
pics-run-ufraw "$numeric_exposure" "$file" "$out" "$rotate"
mv -vi "$exposure/$base.jpeg" "$out"
fi
touch -r "$file" "$out"
- mv -vi "$file" "$destdir/$name $number.NEF"
+ mv -vi "$file" "$NEFout"
+ chmod 644 "$NEFout"
else
if [[ "$rotate" ]];then
- sed -i "s/^# ROBOTS_INSERT_THINGS_HERE\$/&\n\"$name $number.jpeg\" => $rotate," "$destdir/rotations.php"
+ sed -i "s/^# ROBOTS_INSERT_THINGS_HERE\$/\"$name $number.jpeg\" => $rotate,\n&/" "$destdir/rotations.php"
fi
mv -vi "$file" "$out"
fi
+chmod 644 "$out"