#!/bin/bash # Shared helpers for proxmox-configuration scripts. Sourced, not executed # directly: # SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # source "${SCRIPT_DIR}/lib/common.sh" require_root() { if [ "$(id -u)" -ne 0 ]; then echo "Must run as root." >&2 exit 1 fi } # Codename of the running Debian/PVE release, e.g. "trixie". pve_codename() { (. /etc/os-release && echo "$VERSION_CODENAME") } # backup_file # Copies an existing file to .bak.. No-op if it doesn't exist. backup_file() { local path="$1" if [ -f "$path" ]; then cp "$path" "${path}.bak.$(date +%s)" echo "Backed up ${path}" fi } # write_if_changed # Writes content to path only if it differs from what's already there, # backing up the previous version first. Prints what happened. write_if_changed() { local path="$1" content="$2" if [ -f "$path" ] && [ "$(cat "$path")" = "$content" ]; then echo "Already up to date: $path" return 0 fi backup_file "$path" printf '%s\n' "$content" > "$path" echo "Wrote $path" } # --- audit.sh status helpers --- # Callers should initialize: AUDIT_FAIL=0 audit_pass() { echo "PASS $1"; } audit_fail() { echo "FAIL $1"; AUDIT_FAIL=1; } audit_warn() { echo "WARN $1"; }