odex25_standard/clone.sh

139 lines
3.6 KiB
Bash

#!/bin/bash
# Git repository URL
USERNAME=$1
TOKEN=$2
# Retry limit for failed clone attempts
RETRY_LIMIT=3
# Branch types and their corresponding directories
declare -A branch_dirs=(
["dev"]="test"
["preprod"]="preprod"
["master"]="master"
)
# List of branches
branches=(
"dev_odex-event"
"dev_odex25_accounting"
"dev_odex25_base"
"dev_odex25_dms"
"dev_odex25_fleet"
"dev_odex25_helpdesk"
"dev_odex25_hr"
"dev_odex25_inventory"
"dev_odex25_maintenance"
"dev_odex25_mobile"
"dev_odex25_pos"
"dev_odex25_project"
"dev_odex25_purchase"
"dev_odex25_realstate"
"dev_odex25_sales"
"dev_odex25_survey"
"dev_odex25_transactions"
"dev_odex25_website"
"dev_openeducat_erp-14.0.1.0"
"dev_odex25_ensan"
"preprod_odex-event"
"preprod_odex25_accounting"
"preprod_odex25_base"
"preprod_odex25_dms"
"preprod_odex25_fleet"
"preprod_odex25_helpdesk"
"preprod_odex25_hr"
"preprod_odex25_inventory"
"preprod_odex25_maintenance"
"preprod_odex25_mobile"
"preprod_odex25_pos"
"preprod_odex25_project"
"preprod_odex25_purchase"
"preprod_odex25_realstate"
"preprod_odex25_sales"
"preprod_odex25_survey"
"preprod_odex25_transactions"
"preprod_odex25_website"
"preprod_openeducat_erp-14.0.1.0"
"preprod_odex25_ensan"
"master_odex-event"
"master_odex25_accounting"
"master_odex25_base"
"master_odex25_dms"
"master_odex25_fleet"
"master_odex25_helpdesk"
"master_odex25_hr"
"master_odex25_inventory"
"master_odex25_maintenance"
"master_odex25_mobile"
"master_odex25_pos"
"master_odex25_project"
"master_odex25_purchase"
"master_odex25_realstate"
"master_odex25_sales"
"master_odex25_survey"
"master_odex25_transactions"
"master_odex25_website"
"master_openeducat_erp-14.0.1.0"
"master_odex25_ensan"
)
# Error log file
error_log="clone_error_log.txt" > "$error_log" # Clear log file at the start
# Clone branch function with retry mechanism
clone_branch() {
local branch=$1
local full_path=$2
local attempt=1
while [ $attempt -le $RETRY_LIMIT ]; do
echo "Cloning $branch into $full_path (Attempt $attempt/$RETRY_LIMIT)..."
git clone --depth=1 -b "$branch" "https://$USERNAME:$TOKEN@github.com/expsa/odex25-standard-modules.git" "$full_path"
if [ $? -eq 0 ]; then
echo "Successfully cloned $branch into $full_path"
return 0
else
echo "Failed to clone $branch (Attempt $attempt)."
attempt=$((attempt + 1))
fi
done
# If the retry limit is reached, log the failure
echo "Failed to clone $branch after $RETRY_LIMIT attempts." >> "$error_log"
return 1
}
# Loop through each branch
for branch in "${branches[@]}"; do
# Extract the prefix (dev, preprod, master) and the branch name
prefix="${branch%%_*}"
folder_name="${branch#*_}"
# Determine the base directory based on the prefix
base_dir="${branch_dirs[$prefix]}"
# Full path for the folder inside the corresponding directory
full_path="$base_dir/$folder_name"
# Skip cloning if the folder already exists
if [ -d "$full_path" ]; then
echo "Skipping $branch: already cloned in $full_path"
continue
fi
# Create the directory if it doesn't exist
mkdir -p "$full_path"
# Clone the specific branch with error handling
clone_branch "$branch" "$full_path"
done
# Check if any errors were logged
if [ -s "$error_log" ]; then
echo "Some branches failed to clone. Check $error_log for details."
else
echo "All branches cloned successfully."
fi