#!/bin/bash

# File containing the list of repositories
REPO_LIST="/home/pedroabgmarques/downloads/repo_list.txt"

# Base URL for the repositories
BASE_URL="https://gitea.wavefunctionvr.com/WaveFunction-VR/"

# Directory where repositories will be cloned
CLONE_DIR="/var/www/html"

echo `date`
echo "Starting cloning process.."

# Loop through each line in the repo list file
while IFS= read -r repo_name
do
    # Construct the full Git URL
    FULL_URL="${BASE_URL}${repo_name}.git"

    # Clone the repository
    git clone "$FULL_URL" "$CLONE_DIR/$repo_name"
    if [ $? -ne 0 ]; then
        echo "Error cloning repository: $repo_name"
        exit 1
    fi
    echo "Repo cloned: $repo_name"

    # Copy .htaccess_sites to the new repo directory
    cp "$CLONE_DIR/.htaccess_sites" "$CLONE_DIR/$repo_name/.htaccess"
    echo ".htaccess copied!"

    # Remove the .git directory
    rm -rf "$CLONE_DIR/$repo_name/.git"
    echo ".git folder removed."

done < "$REPO_LIST"

echo "All repositories processed successfully."
echo `date`

