#!/bin/bash # Useful functions for all scripts set -euo pipefail _err() { echo "ERR: $@"; exit 1; } # Shortcut for mktemp _mktmp() { mktemp -p "$HL_TMP_DIR" $@; } # Substitute env variables in a file using python template strings # all env vars must be prefixed with "HL_", and are case insensitive # Ex: # -- file.txt # hello $person # # -- script.sh # export HL_PERSON="world"; # cat $(_fill file.txt) # # Output: "hello world" _fill() { OUT="$(_mktmp)" python3 - $1 > "$OUT" < /dev/null; if grep -q -E "^$f$" run.checkpoints; then echo "skipping $f, already run"; popd > /dev/null; else echo "running $f"; $f popd > /dev/null; echo "$f" >> run.checkpoints; fi; done; } _assert_vars HL_TMP_DIR