56 lines
1.5 KiB
Bash
Executable File
56 lines
1.5 KiB
Bash
Executable File
|
|
#!/usr/bin/env bash
|
|
# manifest_gen.sh — minimal manifest generator using find + md5sum
|
|
# Default output: /tmp/manifest-<hostname>.txt
|
|
# Format: "<md5> <absolute_path>"
|
|
|
|
set -euo pipefail
|
|
|
|
HOST="$(hostname -s 2>/dev/null || hostname 2>/dev/null || echo unknown)"
|
|
OUT="./manifest-${HOST}.txt"
|
|
ROOT="${1:-/}"
|
|
|
|
# Default excludes (edit here)
|
|
EXCLUDES=(/proc /sys /dev /run /tmp /var/run /var/lock /lost+found /mnt /media /cloudian* /var/lib/cassandra)
|
|
|
|
ERR="${OUT}.err"
|
|
: > "$OUT"
|
|
: > "$ERR"
|
|
|
|
ROOT="$(cd "$ROOT" && pwd -P)"
|
|
|
|
{
|
|
echo "# manifest_version=md5sum-v1"
|
|
echo "# created_utc=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
echo "# host=$HOST"
|
|
echo "# root=$ROOT"
|
|
echo -n "# excludes="
|
|
printf "%s " "${EXCLUDES[@]}"
|
|
echo
|
|
echo "# format=<md5> <absolute_path>"
|
|
} >> "$OUT"
|
|
|
|
# Build prune expression
|
|
PRUNE=()
|
|
for ex in "${EXCLUDES[@]}"; do
|
|
# normalize excludes if they exist; if they don't, still keep as-is
|
|
if [ -e "$ex" ]; then
|
|
ex="$(cd "$ex" 2>/dev/null && pwd -P || echo "$ex")"
|
|
fi
|
|
PRUNE+=( -path "$ex" -o -path "$ex/*" -o )
|
|
done
|
|
unset 'PRUNE[${#PRUNE[@]}-1]' # drop last -o
|
|
|
|
# Deterministic ordering if available (GNU sort -z)
|
|
if sort -z </dev/null >/dev/null 2>&1; then
|
|
find "$ROOT" \( "${PRUNE[@]}" \) -prune -o -type f -print0 2>>"$ERR" \
|
|
| sort -z 2>>"$ERR" \
|
|
| xargs -0 -r md5sum -- 2>>"$ERR" >> "$OUT"
|
|
else
|
|
find "$ROOT" \( "${PRUNE[@]}" \) -prune -o -type f -print0 2>>"$ERR" \
|
|
| xargs -0 -r md5sum -- 2>>"$ERR" >> "$OUT"
|
|
fi
|
|
|
|
echo "Wrote: $OUT" >&2
|
|
echo "Errs: $ERR" >&2
|