apiVersion: v1
kind: ConfigMap
metadata:
  name: "home-assistance-initial-script-configmap"
  annotations:
    rollme: {{ randAlphaNum 5 | quote }}
data:
  configuration.yaml.default: |-
    # Configure a default setup of Home Assistant (frontend, api, etc)
    default_config:

    # Text to speech
    tts:
      - platform: google_translate


  init.sh: |-
    #!/bin/sh
    if test -f "/config/configuration.yaml"; then
      echo "configuration.yaml exists."
      if grep -q recorder: "/config/configuration.yaml"; then
      echo "configuration.yaml already contains recorder"
      else
      cat /config/init/recorder.default >> /config/configuration.yaml
      echo " postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}" >> /config/configuration.yaml
      fi
    else
    echo "configuration.yaml does NOT exist."
    cp /config/init/configuration.yaml.default /config/configuration.yaml
    cat /config/init/recorder.default >> /config/configuration.yaml
    echo " postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}" >> /config/configuration.yaml
    cat /config/init/http.default >> /config/configuration.yaml
    fi
  recorder.default: |-

    recorder:
      purge_keep_days: 30
      commit_interval: 3
      db_url:

