import re, sys

with open("/opt/getting-started.sh") as f:
    content = f.read()

patches = {
    "read_nb_domain": '''read_nb_domain() {
  echo "$NETBIRD_DOMAIN"
  return 0
}''',
    "read_reverse_proxy_type": '''read_reverse_proxy_type() {
  echo "${REVERSE_PROXY_TYPE:-0}"
  return 0
}''', 
    "read_traefik_acme_email": '''read_traefik_acme_email() {
  echo "$TRAEFIK_ACME_EMAIL"
  return 0
}''',
    "read_enable_proxy": '''read_enable_proxy() {
  echo "${ENABLE_PROXY:-false}"
  return 0
}''',
    "read_enable_crowdsec": '''read_enable_crowdsec() {
  echo "${ENABLE_CROWDSEC:-false}"
  return 0
}'''
}

for func_name, new_body in patches.items():
    pattern = rf'{re.escape(func_name)}\(\) \{{\n(.*?)\n\}}'
    content = re.sub(pattern, new_body, content, count=1, flags=re.DOTALL)

with open("/opt/getting-started.sh", "w") as f:
    f.write(content)
print("OK - patched all")
