the home site for me: also iteration 3 or 4 of my site
1#!/usr/bin/env bash
2
3# Check if exiftool is installed
4if ! command -v exiftool &> /dev/null; then
5 echo "Error: exiftool is not installed. Please install it." >&2
6 exit 1
7fi
8
9# Flag to track if we found any draft files
10found_draft=0
11
12# First pass: check for draft files
13while read -r file; do
14 case "$file" in
15 *.md)
16 # Check if file contains draft = true within +++ header section
17 awk '
18 /^\+\+\+$/ { inblock = !inblock }
19 inblock && /draft = true/ { found = 1 }
20 END { exit(found ? 0 : 1) }
21 ' "$file"
22 if [ $? -eq 0 ]; then
23 echo "Error: Draft file detected: $file" >&2
24 echo "Please remove draft status or unstage this file before committing." >&2
25 found_draft=1
26 fi
27 ;;
28 *)
29 ;;
30 esac
31done < <(git diff --cached --name-only --diff-filter=ACMR)
32
33# Exit if we found any draft files
34if [ $found_draft -eq 1 ]; then
35 exit 1
36fi
37
38# Second pass: process images in parallel
39pids=()
40tmpdir=$(mktemp -d)
41
42while read -r file; do
43 case "$file" in
44 *.jpg|*.jpeg|*.png|*.gif|*.tiff|*.bmp)
45 (
46 cleared_data=$(exiftool -all= --icc_profile:all -tagsfromfile @ -orientation -overwrite_original "$file" 2>&1)
47 if [ $? -ne 0 ]; then
48 echo "Error: exiftool failed to process $file" >&2
49 exit 1
50 fi
51 echo "Cleared EXIF data for $file:" >&2
52 echo "$cleared_data" >&2
53 echo "$file" >> "$tmpdir/processed"
54 ) &
55 pids+=($!)
56 ;;
57 *)
58 ;;
59 esac
60done < <(git diff --cached --name-only --diff-filter=ACMR)
61
62failed=0
63for pid in "${pids[@]}"; do
64 wait "$pid" || failed=1
65done
66
67if [ -f "$tmpdir/processed" ]; then
68 git add -- $(cat "$tmpdir/processed")
69fi
70rm -rf "$tmpdir"
71
72exit $failed