Add Delta-E column and make auto-scan.sh macOS-compatible

- averaged.csv now gets a dE00 (CIEDE2000) column measured against the
  sample marked with a leading '*' in samples.txt (falls back to the first)
- auto-scan.sh: drop bash-4-only mapfile/${var,,}, OS-aware Argyll package
  and python3 install, portable grep/sort, Linux-only udev check

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-14 14:50:25 +03:30
parent 3887505e40
commit 9f63e7c078
4 changed files with 152 additions and 13 deletions

View File

@@ -19,7 +19,12 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
ARGYLL_VERSION="3.4.1"
ARGYLL_URL="https://www.argyllcms.com/Argyll_V${ARGYLL_VERSION}_linux_x86_64.tgz"
OS="$(uname -s)"
case "$OS" in
Darwin) ARGYLL_PKG="osx10.6_x86_64" ;; # runs under Rosetta 2 on Apple Silicon
*) ARGYLL_PKG="linux_x86_64" ;;
esac
ARGYLL_URL="https://www.argyllcms.com/Argyll_V${ARGYLL_VERSION}_${ARGYLL_PKG}.tgz"
SAMPLES_FILE="samples.txt"
AVERAGED_CSV="averaged.csv"
FORMULA_CSV="formula.csv"
@@ -44,22 +49,32 @@ done
info() { printf '\n\033[1;34m==> %s\033[0m\n' "$*"; }
warn() { printf '\033[1;33mWARNING: %s\033[0m\n' "$*" >&2; }
fail() { printf '\033[1;31mERROR: %s\033[0m\n' "$*" >&2; exit 1; }
# Lowercase helper: macOS ships bash 3.2, which lacks ${var,,}.
lower() { printf '%s' "$1" | tr '[:upper:]' '[:lower:]'; }
# ---------------------------------------------------------------- step 1
check_dependencies() {
info "Step 1/5: Checking required software"
if ! command -v python3 >/dev/null 2>&1; then
warn "python3 not found - attempting to install (needs sudo)"
sudo apt-get update && sudo apt-get install -y python3 \
|| fail "Could not install python3"
warn "python3 not found - attempting to install"
if [[ "$OS" == "Darwin" ]]; then
command -v brew >/dev/null 2>&1 \
|| fail "python3 not found. Install Homebrew (https://brew.sh), then: brew install python3"
brew install python3 || fail "Could not install python3 via brew"
elif command -v apt-get >/dev/null 2>&1; then
sudo apt-get update && sudo apt-get install -y python3 \
|| fail "Could not install python3"
else
fail "python3 not found and no supported package manager (apt-get/brew) available"
fi
fi
echo " python3: $(command -v python3)"
if ! command -v spotread >/dev/null 2>&1; then
# Look for an existing local ArgyllCMS install first
local argyll_bin
argyll_bin="$(ls -d "$HOME"/.local/bin/Argyll_V*/bin 2>/dev/null | sort -V | tail -1 || true)"
argyll_bin="$(ls -d "$HOME"/.local/bin/Argyll_V*/bin 2>/dev/null | sort | tail -1 || true)"
if [[ -n "$argyll_bin" ]]; then
export PATH="$argyll_bin:$PATH"
fi
@@ -79,7 +94,7 @@ check_dependencies() {
export PATH="$HOME/.local/bin/Argyll_V${ARGYLL_VERSION}/bin:$PATH"
command -v spotread >/dev/null 2>&1 || fail "ArgyllCMS install failed"
echo " Installed ArgyllCMS to ~/.local/bin/Argyll_V${ARGYLL_VERSION}"
echo " Add this to your ~/.bashrc to make it permanent:"
echo " Add this to your shell profile (~/.bashrc or ~/.zshrc) to make it permanent:"
echo " export PATH=\"\$HOME/.local/bin/Argyll_V${ARGYLL_VERSION}/bin:\$PATH\""
fi
echo " spotread: $(command -v spotread)"
@@ -88,7 +103,7 @@ check_dependencies() {
[[ -f "$helper" ]] || fail "Missing helper script: $helper"
done
if [[ ! -f /etc/udev/rules.d/55-Argyll.rules ]]; then
if [[ "$OS" == "Linux" && ! -f /etc/udev/rules.d/55-Argyll.rules ]]; then
warn "Argyll udev rules not installed. If the instrument is not detected, run: sudo ./setup-udev.sh"
fi
}
@@ -106,14 +121,20 @@ wait_for_instrument() {
echo " No instrument detected. Connect the i1Pro 2 via USB."
read -r -p " Press Enter to check again (or Ctrl+C to abort)... "
done
grep -E "^\s+[0-9]+ = " <<<"$ports" | sed 's/^/ Found:/' || true
grep -E "^[[:space:]]+[0-9]+ = " <<<"$ports" | sed 's/^/ Found:/' || true
}
# ---------------------------------------------------------------- step 3+4
scan_samples() {
[[ -f "$SAMPLES_FILE" ]] || fail "$SAMPLES_FILE not found"
mapfile -t SAMPLES < <(grep -v '^#' "$SAMPLES_FILE" | grep -v '^[[:space:]]*$')
# Strip a leading "*" (the Delta-E reference marker) from displayed names.
# A while-read loop is used instead of mapfile for bash 3.2 (macOS) support.
SAMPLES=()
while IFS= read -r line; do
SAMPLES+=("$line")
done < <(grep -v '^#' "$SAMPLES_FILE" | grep -v '^[[:space:]]*$' \
| sed -E 's/^[[:space:]]*\*[[:space:]]*//')
local count="${#SAMPLES[@]}"
[[ "$count" -gt 0 ]] || fail "No sample names found in $SAMPLES_FILE"
@@ -150,7 +171,7 @@ scan_samples() {
if [[ "$readings" -ne "$count" ]]; then
warn "Expected $count readings but got $readings."
read -r -p " Keep this scan anyway? [y/N] " ans
if [[ "${ans,,}" != "y" ]]; then
if [[ "$(lower "$ans")" != "y" ]]; then
mkdir -p archive
mv "$TSV" "archive/${TSV%.tsv}_incomplete.tsv"
fail "Scan discarded (moved to archive/). Re-run ./auto-scan.sh"
@@ -191,7 +212,7 @@ update_average() {
if [[ -f build-formula-table.py ]]; then
read -r -p " Rebuild $FORMULA_CSV as well? [Y/n] " ans
if [[ "${ans,,}" != "n" ]]; then
if [[ "$(lower "$ans")" != "n" ]]; then
python3 build-formula-table.py -i "$AVERAGED_CSV" -o "$FORMULA_CSV"
else
echo " Skipped $FORMULA_CSV (rebuild later with: python3 build-formula-table.py)"