#!/bin/bash
# NIP Installation Script
set -e

echo "🌱 Installing NIP v0.1.0"
echo "============================"
echo ""

# Check if running as root
if [ "$EUID" -ne 0 ]; then
    echo "⚠️  This installer requires root privileges"
    echo "   Please run: sudo ./install.sh"
    exit 1
fi

# Install binary
echo "📦 Installing NIP binary..."
cp nip /usr/local/bin/nip
chmod +x /usr/local/bin/nip
echo "   Installed to: /usr/local/bin/nip"
echo ""

# Create directories
echo "📁 Creating directories..."
mkdir -p /Programs
mkdir -p /System/Links/{Executables,Libraries,Headers,Shared}
mkdir -p /var/nip/{cache,db}
mkdir -p /etc/nip
echo "   Created system directories"
echo ""

# Setup system integration
echo "🔧 Setting up system integration..."
if /usr/local/bin/nip setup; then
    echo "   System integration complete"
else
    echo "   System integration partially complete"
fi
echo ""

echo "✅ NIP installation complete!"
echo ""
echo "🎉 You can now use NIP:"
echo "   nip --help              # Show help"
echo "   nip config init         # Initialize user config"
echo "   nip graft nix:hello     # Graft a package"
echo "   nip status              # Show system status"
echo ""
echo "📚 For more information:"
echo "   https://git.maiwald.work/Nexus/NexusToolKit"
