#!/bin/bash
# ===========================================================================
# Copyright (c) 2021, 2023 Eclipse Foundation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#    Christopher Guindon (Eclipse Foundation)
# ==========================================================================

# Projects
WWW=(
"sponsor"
"projects"
"proposals"
"downloads"
"eclipse.org-common"
"errors"
"go"
"community"
"org"
)

GITLABWWWPREFIX="git@gitlab.eclipse.org:eclipsefdn/it/websites/www.eclipse.org"
LOCALSITEWWW="www/eclipse.org"
mkdir -p $LOCALSITEWWW
cd $LOCALSITEWWW

for X in "${WWW[@]}"
do
    echo $X
    folder_name=${X##*/}
    if [ ! -d "$folder_name" ]; then
        # Try GitLab first
        if git clone $GITLABWWWPREFIX/$X.git &>/dev/null; then
            echo "$X (GitLab) cloned successfully"
        else
            echo "Error: Could not clone $X from GitLab" 1>&2
        fi
    else
        cd $folder_name
        git pull origin master 2>/dev/null
        cd ../
    fi
done

cd ../
echo "Done"
