#!/usr/bin/env bash
set -euo pipefail
ROOT="${1:-/srv/project-frankenstein}"

echo "Project Frankenstein repository preflight"
echo "timestamp_utc=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "hostname=$(hostname)"
echo "kernel=$(uname -srmo)"
echo

echo '== Memory =='
free -h || true
echo

echo '== Block devices and filesystems =='
lsblk -e7 -o NAME,PATH,SIZE,TYPE,FSTYPE,FSVER,LABEL,UUID,MOUNTPOINTS,MODEL,SERIAL || true
echo

echo '== Mounts =='
findmnt -D || true
echo

echo '== Filesystem capacity =='
df -hT / || true
if [[ -e "$ROOT" ]]; then
  df -hT "$ROOT" || true
  stat -f -c 'root=%n fs_type=%T block_size=%S blocks=%b free_blocks=%f' "$ROOT" || true
else
  echo "$ROOT does not exist yet"
fi
echo

echo '== Git =='
command -v git >/dev/null && git --version || echo 'git not installed'
echo

echo '== SMART capability =='
if command -v smartctl >/dev/null; then
  smartctl --scan-open || true
else
  echo 'smartctl not installed'
fi
echo

echo 'READ-ONLY PREFLIGHT COMPLETE'
echo 'No partition, filesystem, mount, or repository was modified.'
