#!/bin/bash
set -eo pipefail

# if the keyspace already exists, exit early
etcdctl -C $ETCD ls $ETCD_PATH >/dev/null && exit 0

# otherwise seed initial values
etcdctl -C $ETCD set $ETCD_PATH/protocol ${DEIS_PROTOCOL:-http}
etcdctl -C $ETCD set $ETCD_PATH/secretKey ${DEIS_SECRET_KEY:-`openssl rand -base64 64 | tr -d '\n'`}
etcdctl -C $ETCD set $ETCD_PATH/builderKey ${DEIS_BUILDER_KEY:-`openssl rand -base64 64 | tr -d '\n'`}
etcdctl -C $ETCD set $ETCD_PATH/cmModule ${DEIS_CM_MODULE:-cm.chef}

exit 0