Files
dotfiles/scripts/fix-scans.sh
Cato 5d5e857c79 Adopt fix-scans.sh from lifeops, and write down three rules earned today (#66)
* feat(scripts): adopt fix-scans.sh, and say that scripts/ exists

Batch-repairs date and GPS metadata on scanned film frames: scanners stamp
the scan time, not the shot time, so a 1994 roll sorts into last Tuesday in
any photo app. Dry-run by default, --apply writes through exiftool.

It came from bitbaum/lifeops, a repo created by an agent on 2026-08-13 that
never went anywhere. The idea (personal non-code tasks made repo-shaped so
FleetCrown can dispatch them) is worth keeping as an idea; a repo is not the
place to keep an idea. This is the one file in it that does real work, and
it is environment-shaped, so it belongs beside fleet-status.sh.

The architecture block never mentioned scripts/ even though fleet-status.sh
has lived there for months. A directory the file does not list is one the
next person puts the wrong thing in.

* docs(claude): three rules earned the hard way today

Written after a session that created litter, then nearly deleted live code
while cleaning it up. Each is a fact an agent cannot derive:

- Clean up the experiment when the experiment is over. Six dogfood sites
  from 10-11 September were still live days later, two reading as real
  Zurich businesses that do not exist, on George's own domain. Includes the
  deletion ORDER: the FleetCrown project first, or box-prepare re-clones the
  site within two minutes.

- Never create a GitHub repository on your own initiative. Agents commit
  under George's own identity, so an agent-made repo is indistinguishable
  from his. 27 of 48 repos had an agent-authored first commit, and he did
  not recognise several of them.

- Answer "what do we have?" from a register, never a grep. ~/dev is a
  partial copy of the org. A grep for @bitbaum/<name> missed every consumer
  of packages that install under a bare name, and "nothing depends on these"
  nearly deleted bip-kit (8 adopters), limitkit (3) and threadkit (3).
  fleet/registers/*.json had the right answer the whole time.

* docs(claude): three rules earned today, and the budget to hold them

Each records an incident from 2026-09-12 and is a fact an agent cannot
derive on its own:

- Clean up the experiment when the experiment is over. Six dogfood sites
  from 10-11 September were still live days later, two reading as real
  Zurich businesses that do not exist, on George's own domain. Carries the
  deletion ORDER, because the FleetCrown project row is invisible from the
  box and box-prepare re-cloned three of the six within two minutes.

- Never create a GitHub repository on your own initiative. Agents commit
  under George's own identity, so an agent-made repo is indistinguishable
  from his. 27 of 48 repos had an agent-authored first commit and he
  recognised few of them.

- Answer "what do we have?" from a register, never a grep. A grep for
  @bitbaum/<name> missed every consumer of packages that install under a
  bare name; "nothing depends on these" nearly deleted bip-kit (8
  adopters), limitkit (3) and threadkit (3). fleet/registers/*.json had
  the answer the whole time.

The first draft of these ran 75 lines and the budget gate caught it, which
is the gate working: they are 49 now. BUDGET rises 242 -> 291, set to the
exact count so the ratchet keeps no slack, with the reason in the diff.
2026-09-12 12:30:11 -07:00

85 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# fix-scans.sh — batch-repair date + GPS metadata on scanned film frames.
#
# Film scans carry the scanner's timestamp, not the shot date, and no location.
# This stamps a whole roll with its real capture date (one frame per --step
# seconds so ordering survives in photo apps) and optionally a GPS position.
#
# Usage:
# fix-scans.sh --dir <scans/> --date "1994:07:21 12:00:00" \
# [--gps "47.3769,8.5417"] [--step 60] [--tz +02:00] [--apply] [--no-backup]
#
# Dry-run by default: prints the plan, writes nothing. --apply writes via
# exiftool, which keeps originals as *_original next to each file;
# --no-backup overwrites in place.
set -euo pipefail
DIR="" DATE="" GPS="" STEP=60 TZ_OFF="+00:00" APPLY=0 BACKUP=1
usage() { sed -n '2,14p' "$0" | sed 's/^# \{0,1\}//'; exit "${1:-0}"; }
while [ $# -gt 0 ]; do
case "$1" in
--dir) DIR=$2; shift 2 ;;
--date) DATE=$2; shift 2 ;;
--gps) GPS=$2; shift 2 ;;
--step) STEP=$2; shift 2 ;;
--tz) TZ_OFF=$2; shift 2 ;;
--apply) APPLY=1; shift ;;
--no-backup) BACKUP=0; shift ;;
-h|--help) usage ;;
*) echo "unknown arg: $1" >&2; usage 1 ;;
esac
done
[ -n "$DIR" ] && [ -n "$DATE" ] || { echo "error: --dir and --date are required" >&2; usage 1; }
[ -d "$DIR" ] || { echo "error: no such directory: $DIR" >&2; exit 1; }
command -v exiftool >/dev/null || { echo "error: exiftool not found in PATH" >&2; exit 1; }
echo "$DATE" | grep -Eq '^[0-9]{4}:[0-9]{2}:[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' \
|| { echo "error: --date must be 'YYYY:MM:DD HH:MM:SS' (EXIF format)" >&2; exit 1; }
LAT="" LON=""
if [ -n "$GPS" ]; then
LAT=${GPS%%,*}; LON=${GPS##*,}
[ "$LAT" != "$GPS" ] && [ -n "$LON" ] || { echo "error: --gps must be 'lat,lon'" >&2; exit 1; }
fi
# Frames sorted by filename = frame order (holds for every scanner naming scheme).
mapfile -t FRAMES < <(find "$DIR" -maxdepth 1 -type f \
\( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.tif' -o -iname '*.tiff' -o -iname '*.png' -o -iname '*.dng' \) \
! -name '*_original' | sort)
[ ${#FRAMES[@]} -gt 0 ] || { echo "error: no image files in $DIR" >&2; exit 1; }
epoch=$(date -d "$(echo "$DATE" | sed 's/:/-/;s/:/-/')" +%s)
MODE="DRY-RUN (pass --apply to write)"; [ $APPLY -eq 1 ] && MODE="APPLY"
echo "== fix-scans: ${#FRAMES[@]} frames in $DIR — $MODE"
echo " roll date $DATE ($TZ_OFF), +${STEP}s/frame${GPS:+, GPS $LAT,$LON}"
i=0
for f in "${FRAMES[@]}"; do
ts=$(date -d "@$((epoch + i * STEP))" '+%Y:%m:%d %H:%M:%S')
printf '%3d %-40s -> %s\n' "$i" "$(basename "$f")" "$ts"
if [ $APPLY -eq 1 ]; then
args=( -q "-AllDates=$ts" "-OffsetTime*=$TZ_OFF" )
[ $BACKUP -eq 0 ] && args+=( -overwrite_original )
if [ -n "$GPS" ]; then
args+=( "-GPSLatitude=$LAT" "-GPSLongitude=$LON"
"-GPSLatitudeRef=$([ "${LAT#-}" = "$LAT" ] && echo N || echo S)"
"-GPSLongitudeRef=$([ "${LON#-}" = "$LON" ] && echo E || echo W)" )
fi
exiftool "${args[@]}" "$f"
fi
i=$((i + 1))
done
if [ $APPLY -eq 1 ]; then
echo "== verifying..."
bad=0
for f in "${FRAMES[@]}"; do
got=$(exiftool -s3 -DateTimeOriginal "$f")
[ -n "$got" ] || { echo " MISSING DateTimeOriginal: $f" >&2; bad=1; }
done
[ $bad -eq 0 ] && echo "== OK: all ${#FRAMES[@]} frames stamped" || { echo "== FAILED verification" >&2; exit 1; }
fi