#!/bin/bash
set -e

cat > /home/ubuntu/cloud-env.sh << EOF
export REGION_CODE=${REGION_CODE}
export REGION_NAME=${REGION_NAME}
export HOST_MONITOR1_PRIVATE_IP=${HOST_MONITOR1_PRIVATE_IP}
export HOST_MONITOR1_PUBLIC_IP=${HOST_MONITOR1_PUBLIC_IP}
export SERVERLESS_CLUSTER_HOST=${SERVERLESS_CLUSTER_HOST}
export SERVERLESS_CLUSTER_PORT=${SERVERLESS_CLUSTER_PORT}
export SERVERLESS_CLUSTER_USERNAME=${SERVERLESS_CLUSTER_USERNAME}
export SERVERLESS_CLUSTER_PASSWORD=${SERVERLESS_CLUSTER_PASSWORD}
export SERVERLESS_CLUSTER_DATABASE_NAME=${SERVERLESS_CLUSTER_DATABASE_NAME}
EOF

case ${REGION_CODE} in
    "us-west-2")
        curl -O -fS https://pingcap-edu.s3.us-west-2.amazonaws.com/sp500insight.sql
        ;;
    "ap-northeast-1")
        curl -O -fS https://pingcap-edu-japan.s3.ap-northeast-1.amazonaws.com/sp500insight.sql
        ;;
    "ap-southeast-1")
        curl -O -fS https://pingcap-edu-apac.s3.ap-southeast-1.amazonaws.com/sp500insight.sql
        ;;
    "eu-central-1")
        curl -O -fS https://pingcap-edu-frankfurt.s3.eu-central-1.amazonaws.com/sp500insight.sql
        ;;
esac

curl -O -fS https://raw.githubusercontent.com/pingcap-inc/tidb-course-labs/refs/heads/main/labs/demo_203/books_populate.sql

curl -O -fS https://raw.githubusercontent.com/pingcap-inc/tidb-course-labs/refs/heads/main/labs/demo_203/create_bookshop_schema_in_current_db.sql
