#!/bin/bash

# 进入 versions 目录
cd versions

# 遍历所有版本目录
for version in v[6-9].[0-9].[0-9]*; do
    if [ -d "$version/instances" ]; then
        echo "Processing $version..."
        
        # 创建目标目录
        mkdir -p "$version/instances/gcp.n2-standard-32"
        
        # 如果源目录存在,则复制文件
        if [ -d "$version/instances/aws.m6g.8xlarge" ]; then
            # 复制所有文件
            cp -r "$version/instances/aws.m6g.8xlarge/"* "$version/instances/gcp.n2-standard-32/"
            
            # 处理目标目录中的每个文件
            for file in "$version/instances/gcp.n2-standard-32"/*; do
                if [ -f "$file" ]; then
                    # 使用临时文件替换第一行
                    sed '1c\# n2-standard-32 (32 CPU, 128 GB mem)' "$file" > "$file.tmp"
                    mv "$file.tmp" "$file"
                    echo "Processed $file"
                fi
            done
            
            echo "Copied and modified configs from aws.m6g.8xlarge to gcp.n2-standard-32 in $version"
        else
            echo "Warning: aws.m6g.8xlarge not found in $version/instances"
        fi
    fi
done

echo "Done!"