#!/bin/bash
# Replace app name in Kubernetes manifest files
# Usage: ./replace-app-name.sh <app_name> <old_name>
# Example: ./replace-app-name.sh bursatil inversionistas

if [ $# -ne 2 ]; then
  echo "Usage: $0 <app_name> <old_name>"
  echo "Example: $0 bursatil inversionistas"
  exit 1
fi

APP_NAME=$1
OLD_NAME=$2
K8S_DIR="apps/$APP_NAME/.k8s"

if [ ! -d "$K8S_DIR" ]; then
  echo "Error: Directory $K8S_DIR does not exist"
  exit 1
fi

echo "Replacing '$OLD_NAME' with '$APP_NAME' in $K8S_DIR"

for file in "$K8S_DIR"/*.yaml; do
  if [ -f "$file" ]; then
    echo "  Processing: $(basename $file)"
    sed -i "s/$OLD_NAME/$APP_NAME/g" "$file"
  fi
done

echo "Done!"
