#!/bin/bash

# Ansible Admin Service Installation Script
# This script installs the ansible-admin service for automatic startup

SERVICE_NAME="ansible-admin"
SERVICE_FILE="/home/dionipe/ansible-admin/ansible-admin.service"
SYSTEMD_PATH="/etc/systemd/system/${SERVICE_NAME}.service"

echo "🔧 Installing Ansible Admin Service..."

# Check if running as root
if [[ $EUID -ne 0 ]]; then
   echo "❌ This script must be run as root (sudo)"
   exit 1
fi

# Copy service file to systemd directory
echo "📋 Copying service file to systemd..."
cp "$SERVICE_FILE" "$SYSTEMD_PATH"

# Set proper permissions
chmod 644 "$SYSTEMD_PATH"

# Reload systemd daemon
echo "🔄 Reloading systemd daemon..."
systemctl daemon-reload

# Enable the service
echo "✅ Enabling service to start on boot..."
systemctl enable "$SERVICE_NAME"

echo ""
echo "🎉 Service installation complete!"
echo ""
echo "📋 Service Commands:"
echo "  Start service:   sudo systemctl start $SERVICE_NAME"
echo "  Stop service:    sudo systemctl stop $SERVICE_NAME"
echo "  Restart service: sudo systemctl restart $SERVICE_NAME"
echo "  Status:          sudo systemctl status $SERVICE_NAME"
echo "  View logs:       sudo journalctl -u $SERVICE_NAME -f"
echo ""
echo "🌐 Web interface will be available at: http://localhost:8000"
echo ""
echo "💡 To start the service now, run: sudo systemctl start $SERVICE_NAME"
