#!/bin/sh errorAndExit () { printf "\033[1;31m$1\033[0m" >&2 exit $2 } extractRAW () { if [ -r "$1" ]; then if [ "$1" != "${1%CR2}" ] && [ ! -f "${1%CR2}JPG" ]; then exiftool "$1" -PreviewImage -b > "${1%CR2}JPG" echo "${1%CR2}JPG" else printf "\033[1;31mPreview for $1 exists already.\n\033[0m" >&2 fi fi } if [ $# -ne 1 ] || [ ! -r "$1" ]; then errorAndExit "Please specify one readable file.\n" 1 fi if [ "$(file -b --mime-type "$1")" = "image/x-canon-cr2" ]; then extractRAW "$1" elif [ "$(head -n 1 "$1")" = "#Geeqie collection" ]; then while read line; do if echo "$line" | grep -qv "^#"; then line="${line#\"}" extractRAW "${line%\"}" fi done < "$1" # <"$(sed -r '/#/d;s/(^"|"$)//g' "$1")" else errorAndExit "Please specify either a CR2 or a geeqie collection\n" 1 fi