#!/bin/bash
# Install DocSys as a systemd user service

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

echo "📦 Installing DocSys..."

# Create systemd user directory
mkdir -p ~/.config/systemd/user

# Copy service file
cp "$SCRIPT_DIR/docsys.service" ~/.config/systemd/user/

# Update paths in service file to use absolute paths
sed -i "s|/home/johan/dev/docsys|$SCRIPT_DIR|g" ~/.config/systemd/user/docsys.service
sed -i "s|HOME=/home/johan|HOME=$HOME|g" ~/.config/systemd/user/docsys.service

# Reload systemd
systemctl --user daemon-reload

# Enable and start
systemctl --user enable docsys.service
systemctl --user start docsys.service

echo "✅ DocSys installed and started!"
echo "📊 Dashboard: http://localhost:9201"
echo ""
echo "Commands:"
echo "  systemctl --user status docsys   # Check status"
echo "  systemctl --user restart docsys  # Restart"
echo "  systemctl --user stop docsys     # Stop"
echo "  journalctl --user -u docsys -f   # View logs"
