#!/bin/bash
#
# Verify that the API service is configured to start on boot
#

echo "=========================================="
echo "Boot Configuration Verification"
echo "=========================================="
echo ""

# Check if service is enabled
echo "1. Checking if service is enabled for boot:"
if systemctl is-enabled --quiet plagis-aumentum-api 2>/dev/null; then
    echo "   ✅ Service is ENABLED - will start on boot"
else
    echo "   ❌ Service is NOT enabled"
    echo "   Fix: sudo systemctl enable plagis-aumentum-api"
fi
echo ""

# Check if mount is in fstab
echo "2. Checking if contentstore mount is in /etc/fstab:"
if grep -q "aumentum_contentstore" /etc/fstab 2>/dev/null; then
    echo "   ✅ Mount is configured in /etc/fstab - will mount on boot"
    echo "   Entry:"
    grep "aumentum_contentstore" /etc/fstab | sed 's/^/      /'
else
    echo "   ⚠️  Mount is NOT in /etc/fstab"
    echo "   The mount will NOT persist across reboots"
    echo "   Fix: Add mount entry to /etc/fstab"
fi
echo ""

# Check current mount status
echo "3. Current mount status:"
if mountpoint -q /mnt/aumentum_contentstore 2>/dev/null; then
    echo "   ✅ Currently mounted"
    df -h /mnt/aumentum_contentstore | tail -1
else
    echo "   ⚠️  Not currently mounted"
fi
echo ""

# Check service status
echo "4. Current service status:"
systemctl is-active --quiet plagis-aumentum-api 2>/dev/null && echo "   ✅ Service is RUNNING" || echo "   ⚠️  Service is NOT running"
echo ""

# Summary
echo "=========================================="
echo "Summary"
echo "=========================================="
echo ""

ENABLED=$(systemctl is-enabled plagis-aumentum-api 2>/dev/null)
IN_FSTAB=$(grep -q "aumentum_contentstore" /etc/fstab 2>/dev/null && echo "yes" || echo "no")

if [ "$ENABLED" = "enabled" ] && [ "$IN_FSTAB" = "yes" ]; then
    echo "✅ API will start automatically on boot"
    echo "✅ Contentstore will mount automatically on boot"
    echo ""
    echo "Everything is configured correctly!"
else
    echo "⚠️  Configuration incomplete:"
    [ "$ENABLED" != "enabled" ] && echo "   - Service not enabled for boot"
    [ "$IN_FSTAB" != "yes" ] && echo "   - Mount not in /etc/fstab"
    echo ""
    echo "The API may not start correctly after reboot."
fi

