#!/bin/bash
set -euo pipefail
# When changing this script, remember to modify the corresponding github action
vendor=${1}
env=${2}
region=${3}
logical_region=${4}
cluster=${5}
json_file_path=${6}
args=$(jq -r '.' "${json_file_path}")

if [ "${vendor}" != "alicloud" ]; then
  echo "Skip external-secret deployment: vendor ${vendor} is not alicloud"
  exit 0
fi

ROOT=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)
deploy_dir="${ROOT}/envs"
deploy_file="${deploy_dir}/${env}-${vendor}-${logical_region}.yaml"
variant_dir="${ROOT}/variants"
mkdir -p ${deploy_dir}

template_file="${variant_dir}/${env}-values_tmpl.yaml"

if [ ! -e "${template_file}" ]; then
  echo "Template file not found: ${template_file}"
  exit 1
fi

if [ -e ${deploy_file} ]; then
  echo "New region deploy file already exist, skip it"
else
  echo "Prepare manifest files"
  cp "${template_file}" "${deploy_file}"
  echo "Created ${deploy_file}"
fi

