Skip to content

Scripting & Automation

openrom-core is designed to be the only thing your scripts need to call. This page collects recipes that are known to work.

#!/usr/bin/env bash
set -euo pipefail
SRC="/roms/ps2"
DST="/roms/ps2-chd"
openrom-core \
--folder "$SRC" \
--output "$DST" \
--format CHD \
--compression Max \
--verify

--folder is non-recursive; loop over subdirectories when your collection is organised by system:

Terminal window
find /roms -mindepth 1 -maxdepth 1 -type d | while read -r system; do
name="$(basename "$system")"
openrom-core --folder "$system" --output "/out/$name" --format CHD --verify
done
Terminal window
openrom-core --json --hash "game.iso" |
jq -r '[.crc32, .sha1, .sha256, input_filename] | @tsv'

For a folder, collect one JSON object per file:

Terminal window
: > manifest.jsonl
for f in /roms/ps1/*.bin; do
openrom-core --json --hash "$f" | jq -c . >> manifest.jsonl
done

The manifest becomes your integrity baseline. Re-run it later and diff to detect bit rot.

Terminal window
find /roms -name '*.chd' -print0 |
while IFS= read -r -d '' chd; do
if ! openrom-core --input "$chd" --verify-only --json |
jq -e '.success == true' >/dev/null; then
echo "FAILED: $chd"
fi
done
Terminal window
openrom-core \
--watch /downloads/roms \
--output /roms/incoming \
--format CHD \
--settle-seconds 15 \
--delete-source

Run it under a process supervisor so it restarts after a reboot. A minimal systemd user unit:

[Unit]
Description=OpenROM watch folder
[Service]
ExecStart=/usr/local/bin/openrom-core --watch %h/downloads/roms --output %h/roms --format CHD --settle-seconds 15
Restart=on-failure
[Install]
WantedBy=default.target
Terminal window
systemctl --user enable --now openrom-watch.service

A docs or patch repository can assert that every patch still applies:

- name: Check ROM tooling
run: |
openrom-core --version
openrom-core --list-formats

Plugin repositories can validate and pack on every tag:

Terminal window
openrom-core --plugin-validate ./my-plugin
openrom-core --plugin-pack ./my-plugin --out "my-plugin-${TAG}.orplug"

The packer computes SHA-256 hashes for each platform binary, so the archive is ready to upload to the Marketplace.

--json writes one object per line, which is friendly to jq and to line-oriented tools. Avoid parsing the human-readable output: the labels and emoji are presentation, not an API.

Terminal window
openrom-core --json --audit-mame --dat mame.xml --folder /roms --only-present |
jq -r 'select(.type == "done") | .machines[] | select(.status != "complete") | "\(.status)\t\(.name)"'
Code Meaning Typical handling
0 Success Continue
1 The operation failed (tool error, I/O, bad file) Log and skip the file
2 Invalid arguments or missing input Fix the script

With set -e, a single bad file aborts a batch. If you want to keep going, || true per file and collect failures yourself.

  • Quote every path. ROM collections contain spaces, brackets and parentheses.
  • Pass --output explicitly in scripts; never rely on writing beside the source.
  • Set OPENROM_7Z when 7-Zip is installed outside PATH.
  • In containers, mount both the ROM folder and the destination and run as a user that can write to the destination only.