#!/bin/bash # Convert a Linux-dd multi-session UDF cal ISO into a Windows-readable # single-session ISO+UDF hybrid. Mounts the dd file via UDF loop, copies # files into a temp tree, repacks via mkisofs with ISO9660+UDF. # # Use this when a Mitutoyo cal disc was ripped with `dd if=/dev/sr0` # (default Linux rip). For multi-session UDF discs `dd` captures session # 1 only and truncates trailing UDF Anchor Volume Descriptor Pointers; # the file mounts on Linux (loop-udf) but Windows Mount-DiskImage reports # IsReady=False. mkisofs rebuilds clean metadata Windows reads. Linux # still reads the result. # # Single-session discs (older 218-458A Mitutoyo pattern) are already # ISO9660 from dd - no conversion needed. Run `file CAL-*.iso`: # ISO 9660 = fine; "data" = convert. # # Usage: convert-cal-iso.sh # Replaces input in place. Saves .dd-backup on first run. # # Requires: sudo (loop-udf mount), mkisofs (genisoimage / cdrtools). set -euo pipefail ISO="$1" test -f "$ISO" || { echo "Missing: $ISO"; exit 1; } # Extract label from filename, e.g. CAL-WJF00052_... -> 12AAE675-ish. # Use the asset tag as the volume label so it stays unique + greppable. ASSET=$(basename "$ISO" | sed -n 's/^CAL-\([A-Za-z0-9]*\)_.*/\1/p') test -n "$ASSET" || { echo "Could not parse asset from $ISO"; exit 1; } LABEL="CAL-$ASSET" # Length cap: ISO9660 vol id <= 32 chars LABEL="${LABEL:0:32}" STAGE=$(mktemp -d -p /tmp calconv.XXXX) MNT="$STAGE/mnt" TREE="$STAGE/tree" mkdir -p "$MNT" "$TREE" cleanup() { if mountpoint -q "$MNT"; then sudo umount "$MNT" 2>/dev/null || true; fi rm -rf "$STAGE" } trap cleanup EXIT echo "[$ASSET] mount $ISO" sudo mount -t udf -o loop,ro "$ISO" "$MNT" echo "[$ASSET] copy" cp -a "$MNT/." "$TREE/" sudo umount "$MNT" rmdir "$MNT" 2>/dev/null || true # Verify expected files present (case-insensitive: older WJRP discs use Setup.exe) test -d "$TREE/data" -o -d "$TREE/Data" -o -d "$TREE/DATA" || { echo "[$ASSET] missing data/ dir in tree"; exit 1; } find "$TREE" -maxdepth 1 -iname 'setup.exe' -type f -print -quit | grep -q . || { echo "[$ASSET] missing setup.exe in tree"; exit 1; } NEW="$STAGE/new.iso" echo "[$ASSET] mkisofs -> $NEW" mkisofs -V "$LABEL" \ -udf \ -iso-level 3 \ -J -joliet-long \ -r \ -o "$NEW" \ "$TREE" 2>&1 | tail -3 NEW_SIZE=$(stat -c %s "$NEW") echo "[$ASSET] new size: $NEW_SIZE" # Replace original (backup the dd version once) BACKUP="${ISO}.dd-backup" if [ ! -f "$BACKUP" ]; then mv "$ISO" "$BACKUP" echo "[$ASSET] backed up dd version -> $BACKUP" else rm "$ISO" fi mv "$NEW" "$ISO" echo "[$ASSET] replaced. md5: $(md5sum $ISO | cut -d' ' -f1)"