Files
rust-package-builder/scripts/lib.sh
T
2026-10-08 22:22:11 +02:00

44 lines
877 B
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
# Increment when package payload/installation semantics change without a source commit.
PACKAGING_REVISION=2
log() {
printf '%s %s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ')" "$*"
}
fatal() {
log "ERROR: $*" >&2
exit 1
}
require_cmd() {
command -v "$1" >/dev/null 2>&1 || fatal "required command not found: $1"
}
trim_trailing_slash() {
local value=$1
while [[ "$value" == */ ]]; do value=${value%/}; done
printf '%s' "$value"
}
yaml_quote() {
python3 - "$1" <<'PY'
import json, sys
print(json.dumps(sys.argv[1]))
PY
}
read_first_field() {
local file=$1 key=$2
awk -v key="$key" 'BEGIN{IGNORECASE=1} $0 ~ "^" key ":[[:space:]]*" {sub(/^[^:]+:[[:space:]]*/, ""); print; exit}' "$file"
}
atomic_write() {
local path=$1
local tmp="${path}.tmp.$$"
cat > "$tmp"
mv -f "$tmp" "$path"
}