dotfiles

<-- duh.
git clone https://hhvn.uk/dotfiles
git clone git://hhvn.uk/dotfiles
Log | Files | Refs | Submodules | LICENSE

imgclean (1282B)


      1 #!/bin/sh
      2 
      3 dir="$1"
      4 odir="${2:-clean}"
      5 filexts="jpg|jpeg|png"
      6 
      7 [ -z "$dir" ] || [ ! -d "$dir" ] || [ ! -z "$3" ] && {
      8 	printf "usage: %s <dir> [output-dir]\n" "$(basename $0)"
      9 	exit 2
     10 }
     11 
     12 mkdir -p "$odir" || exit $?
     13 touch "$odir/test" && rm "$odir/test" || exit 1
     14 
     15 export IFS=$(printf '\n\t')
     16 for f in $(find "$dir" -maxdepth 1 -type f | grep -Ei "\.($filexts)$")
     17 do
     18 	[ "$(uname)" = "OpenBSD" ] && summer=sha256
     19 	[ -z "$summer" ] && summer=sha256sum
     20 
     21 	# sum name of file, for speed,
     22 	# as opposed to the file itself
     23 	sum=$(basename "$f" | $summer | awk '{print $1}')
     24 	nhash=$(basename "$f" | sed 's/\..*//')
     25 
     26 	# ignore already created
     27 	[ ! -f "$odir/$sum".jpg ] && {
     28 		printf '%s --> %s... ' "$f" "$odir/$sum.jpg"
     29 		exiftool "$f" -all= -o "$odir/$sum".jpg >/dev/null
     30 		printf 'done\n'
     31 	} || printf "%s already exists, ignoring %s...\n" "$odir/$sum.jpg" "$f"
     32 	[ ! -f "$odir/$nhash".jpg ] && {
     33 		printf 'symlinking %s <-> %s...' "$odir/$sum.jpg" "$odir/$nhash.jpg"
     34 		# symlinks are relative to the directory the symlink is in,
     35 		# therefore - do not use $odir/$sum.jpg. ln is kinda dumb in
     36 		# this regard, it just uses the raw argv contents, no checking or
     37 		# resolving of files. Perhaps a smart ln could be a project?
     38 		ln -s "$sum.jpg" "$odir/$nhash.jpg"
     39 		printf 'done\n'
     40 	}
     41 done