#!/bin/bash

# List of servers
SERVERS=("root@de.mirrors.clouvider.net" "root@nl.mirrors.clouvider.net" "root@nyc.mirrors.clouvider.net" "root@ash.mirrors.clouvider.net" "root@atl.mirrors.clouvider.net" "root@dal.mirrors.clouvider.net" "root@phx.mirrors.clouvider.net" "root@la.mirrors.clouvider.net")

# Source directory
SOURCE_DIR="./"

# Destination directory
DEST_DIR="/srv/seed/sysres/QrUPMBhH4s9L4IYrFM3QQjJAlYK2j8smD0t8QDrw/"

# Function to copy files using scp excluding the specified patterns
copy_files() {
    local server=$1
    
    # Copy root-level files excluding the ones you mentioned
    find $SOURCE_DIR -maxdepth 1 -type f \( ! -iname "*.iso" ! -iname "win2019std.img.gz" ! -iname "win2022std.img.gz" \) -exec scp {} $server:$DEST_DIR \;
    
    # Copy files within ubuntu20 and ubuntu22 excluding .iso files
    for dir in "ubuntu20" "ubuntu22"; do
        find $SOURCE_DIR/$dir -type f \( ! -iname "*.iso" \) -exec scp {} $server:$DEST_DIR/$dir/ \;
    done
}

for server in "${SERVERS[@]}"; do
    echo "Copying to $server..."
    
    # Ensure the target directories exist
    ssh $server "mkdir -p $DEST_DIR/ubuntu20 $DEST_DIR/ubuntu22"
    
    # Start copying
    copy_files $server
    
    echo "Copying to $server completed."
done

echo "All done."

