30 lines
886 B
Smarty
Executable file
30 lines
886 B
Smarty
Executable file
#!/bin/bash
|
|
set -e
|
|
|
|
%{RUNFILES_PREFIX}
|
|
|
|
EXECUTE_BINARY="$(rlocation "_main/$(basename "%{EXECUTE_PATH}")")"
|
|
JQ="$(rlocation "databuild+/runtime/$(basename "%{JQ_PATH}")")"
|
|
|
|
# First argument should be the path to a config file
|
|
CONFIG_FILE=${1:-}
|
|
|
|
# Create a temporary file for stdin if needed
|
|
if [[ -z "$CONFIG_FILE" ]] || [[ "$CONFIG_FILE" == "-" ]]; then
|
|
TMP_CONFIG=$(mktemp)
|
|
cat > "$TMP_CONFIG"
|
|
CONFIG_FILE="$TMP_CONFIG"
|
|
trap 'rm -f "$TMP_CONFIG"' EXIT
|
|
fi
|
|
|
|
# Extract and set environment variables from the config
|
|
eval "$("$JQ" -r '.env | to_entries | .[] | "export " + .key + "=\"" + .value + "\""' "$CONFIG_FILE")"
|
|
|
|
# Extract arguments from the config
|
|
ARGS=()
|
|
while IFS= read -r arg; do
|
|
ARGS+=("$arg")
|
|
done < <("$JQ" -r '.args[]' "$CONFIG_FILE")
|
|
|
|
# Run the execution with both environment variables (already set) and arguments
|
|
exec "$EXECUTE_BINARY" "${ARGS[@]}"
|