42 lines
965 B
Bash
Executable File
42 lines
965 B
Bash
Executable File
#!/bin/bash
|
|
|
|
##
|
|
# Main Program
|
|
|
|
dir=$(dirname "$(readlink -f "$0")")
|
|
origdir="$dir/orig"
|
|
indir="$dir/in"
|
|
|
|
if ! cd "$dir" ; then
|
|
echo "ERROR: Could not change to directory \"$dir\"; aborted." >&2
|
|
exit 1
|
|
elif ! test -d "$origdir" ; then
|
|
echo "ERROR: Directory \"$origdir\" not found; aborted." >&2
|
|
exit 1
|
|
elif ! mkdir -p "$indir" ; then
|
|
echo "ERROR: Could not create directory \"$indir\"; aborted." >&2
|
|
exit 1
|
|
elif ! rm -f -- "$indir/"*.jpg ; then
|
|
echo "ERROR: Could not remove files in \"$indir\"; aborted." >&2
|
|
exit 1
|
|
else
|
|
i=1
|
|
rv=0
|
|
|
|
while read -r jpg ; do
|
|
renamed=$(printf "%02d" "$i").jpg
|
|
|
|
if cp "$jpg" "$indir/$renamed" ; then
|
|
echo "INFO: Copied \"$jpg\" to \"$renamed\"." >&2
|
|
else
|
|
echo "WARNING: Could not copy \"$jpg\" to \"$renamed\"." >&2
|
|
rv=1
|
|
fi
|
|
|
|
i=$((i+1))
|
|
done < <(ls --reverse --sort time -- "$origdir/"*.jpg)
|
|
|
|
exit "$rv"
|
|
fi
|
|
|