#!/bin/bash
set -e

# Saikyo OS meta package postinst: ensure audit-report, forensics collector, and rollback utilities are available

# Ensure forensics collector is available system-wide
if [ -f /usr/share/saikyo-os/forensics/collect-artifacts.sh ]; then
  ln -sf /usr/share/saikyo-os/forensics/collect-artifacts.sh /usr/local/sbin/saikyo-forensics
  chmod +x /usr/local/sbin/saikyo-forensics
fi

# Ensure audit-report is in PATH
if [ -f /usr/share/saikyo-os/bin/saikyo-audit-report ]; then
  ln -sf /usr/share/saikyo-os/bin/saikyo-audit-report /usr/local/bin/saikyo-audit-report
fi

# Ensure rollback utility is in PATH
if [ -f /usr/local/sbin/saikyo-rollback ]; then
  chmod +x /usr/local/sbin/saikyo-rollback
fi

# Enable systemd services for log forwarding (if configured)
if [ -f /etc/systemd/system/saikyo-log-forward.service ]; then
  systemctl daemon-reload
  systemctl enable saikyo-log-forward.service || true
fi

echo "Saikyo OS meta package postinst completed."
