/** Bash helpers shared by every generated job script: step outputs/env files, hashFiles() and the R2-backed cache. */
const SOURCE = String.raw`__stig_re_heredoc='^([A-Za-z_][A-Za-z0-9_-]*)<<(.+)$'
__stig_re_kv='^([A-Za-z_][A-Za-z0-9_-]*)=(.*)$'
__stig_read_kv() {
[ -s "$1" ] || return 0
local __line __key __value __delim __more
while IFS= read -r __line || [ -n "$__line" ]; do
if [[ $__line =~ $__stig_re_heredoc ]]; then
__key="#{BASH_REMATCH[1]}"; __delim="#{BASH_REMATCH[2]}"; __value=""; __more=0
while IFS= read -r __line || [ -n "$__line" ]; do
[ "$__line" = "$__delim" ] && break
if [ $__more = 1 ]; then __value="$__value"$'\n'"$__line"; else __value="$__line"; __more=1; fi
done
elif [[ $__line =~ $__stig_re_kv ]]; then
__key="#{BASH_REMATCH[1]}"; __value="#{BASH_REMATCH[2]}"
else
continue
fi
"$2" "$__key" "$__value" "#{3:-}"
done < "$1"
}
__stig_set_output() { [ -n "$3" ] || return 0; export "STIG_STEPOUT_#{3}__#{1//-/_}=$2"; }
__stig_set_env() { case "$1" in *-*) return 0 ;; esac; export "$1=$2"; }
__stig_reset_files() { : > "$__stig_tmp/output"; : > "$__stig_tmp/env"; : > "$__stig_tmp/path"; }
__stig_after_step() {
local __l __o=success __c=success
__stig_read_kv "$__stig_tmp/env" __stig_set_env
if [ -s "$__stig_tmp/path" ]; then
while IFS= read -r __l || [ -n "$__l" ]; do if [ -n "$__l" ]; then PATH="$__l:$PATH"; fi; done < "$__stig_tmp/path"
export PATH
fi
if [ -n "$1" ]; then
__stig_read_kv "$__stig_tmp/output" __stig_set_output "$1"
if [ "$2" -ne 0 ]; then __o=failure; [ "$3" = 1 ] || __c=failure; fi
export "STIG_STEPOUTCOME_$1=$__o" "STIG_STEPCONCLUSION_$1=$__c"
fi
__stig_reset_files
}
__stig_sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$@"; else shasum -a 256 "$@"; fi; }
__stig_hash_files() (