#!/bin/bash
# Script to add a repository from ARROMIS organization as a submodule
# Usage: ./ADD_REPOSITORY.sh <repository-name>

set -e

if [ -z "$1" ]; then
    echo "Usage: $0 <repository-name>"
    echo "Example: $0 my-repo"
    echo ""
    echo "This will add https://github.com/ARROMIS/<repository-name>.git as a submodule"
    exit 1
fi

REPO_NAME="$1"
REPO_URL="https://github.com/ARROMIS/${REPO_NAME}.git"
SUBMODULE_PATH="ARROMIS/${REPO_NAME}"

# Check if we're in the proxmox project root
if [ ! -f "../.gitmodules" ]; then
    echo "Error: This script must be run from the ARROMIS directory"
    echo "Please run: cd /home/intlc/projects/proxmox/ARROMIS && ./ADD_REPOSITORY.sh $REPO_NAME"
    exit 1
fi

# Go to project root
cd ..

# Check if submodule already exists
if [ -d "$SUBMODULE_PATH" ]; then
    echo "Error: Submodule already exists at $SUBMODULE_PATH"
    exit 1
fi

# Add the submodule
echo "Adding $REPO_NAME as submodule..."
git submodule add "$REPO_URL" "$SUBMODULE_PATH"

echo ""
echo "✅ Successfully added $REPO_NAME as submodule"
echo "Location: $SUBMODULE_PATH"
echo ""
echo "To initialize and update submodules, run:"
echo "  git submodule update --init --recursive"
