#!/bin/bash

set -eu

# openssl enc -in do-setup-circleci-secrets.orig -out setup-circleci-secrets.orig -e -aes256 -pass stdin
# openssl base64 < setup-circleci-secrets.orig

if [ -z "${SECRET_SCRIPT+x}" ]; then
    # "read" return a non-zero value when reading until EOF, see "help read"
    read -r -d '' SECRET_SCRIPT <<EOF || true
[encoded data, 6110 characters]
DJcoVj5UyCTFEyZMdtVWloF4TOVODNNxA+zAE9fUgrI=
EOF
fi

echo "${SECRET_SCRIPT}" | base64 -d | openssl enc \
    -out bin/do-setup-circleci-secrets \
    -d -aes256 -pass pass:"$1"

exec sh bin/do-setup-circleci-secrets
