]>
Commit | Line | Data |
---|---|---|
7a7a7a75 SW |
1 | #!/bin/bash |
2 | ||
d6874f6c SW |
3 | destdir= |
4 | if [[ -e .default-pic-mv-destdir ]];then | |
5 | destdir=$( < .default-pic-mv-destdir ) | |
6 | fi | |
7a7a7a75 SW |
7 | |
8 | exposure= | |
9 | rotate= | |
10 | while getopts d:e:r: opt;do | |
11 | case $opt in | |
12 | d) destdir=$OPTARG;; | |
13 | e) exposure=$OPTARG;; | |
14 | r) rotate=$OPTARG;; | |
15 | esac | |
16 | done | |
17 | shift `expr $OPTIND - 1` | |
18 | ||
d6874f6c SW |
19 | if [[ -z "$destdir" ]];then |
20 | echo "Please specify a destdir with -d or .default-pic-mv-destdir" >&2 | |
21 | exit 1 | |
22 | fi | |
23 | ||
7a7a7a75 SW |
24 | file="$1" |
25 | name="$2" | |
26 | ||
ade6dae4 SW |
27 | re_escaped_name=$(sed 's/[?+*.]/\\&/g' <<< "$name") |
28 | ||
7a7a7a75 | 29 | # Find next number |
ade6dae4 | 30 | max=$(ls "$destdir" | sed -rn "s/^$re_escaped_name ([0-9]+).jpeg$/\1/p" | sort -n | tail -n1) |
7a7a7a75 SW |
31 | if [[ "$max" ]];then |
32 | number=$((max + 1)) | |
33 | else | |
34 | number=1 | |
35 | fi | |
36 | ||
7e0b085a SW |
37 | out="$destdir/$name $number.jpeg" |
38 | ||
7a7a7a75 SW |
39 | if [[ "$file" == *.NEF ]];then |
40 | base="${file%.NEF}" | |
9ac8dac0 | 41 | NEFout="$destdir/$name $number.NEF" |
7a7a7a75 | 42 | if [[ "$rotate" ]];then |
7e0b085a SW |
43 | numeric_exposure=$(dc <<< "2k $exposure 4 / 3.5-p") |
44 | pics-run-ufraw "$numeric_exposure" "$file" "$out" "$rotate" | |
7a7a7a75 | 45 | else |
7e0b085a | 46 | mv -vi "$exposure/$base.jpeg" "$out" |
7a7a7a75 | 47 | fi |
5167ae01 | 48 | touch -r "$file" "$out" |
9ac8dac0 SW |
49 | mv -vi "$file" "$NEFout" |
50 | chmod 644 "$NEFout" | |
7a7a7a75 SW |
51 | else |
52 | if [[ "$rotate" ]];then | |
4ef7056e | 53 | sed -i "s/^# ROBOTS_INSERT_THINGS_HERE\$/\"$name $number.jpeg\" => $rotate,\n&/" "$destdir/rotations.php" |
7a7a7a75 | 54 | fi |
7e0b085a | 55 | mv -vi "$file" "$out" |
7a7a7a75 | 56 | fi |
9ac8dac0 | 57 | chmod 644 "$out" |