#!/usr/bin/env bash
set -Eeuo pipefail

#
# Operational toggle
#
export DESTROY_VOLUME=

#
# Variables defined by commands
#
VPS_COMMIT_SHA="$(cat .git/refs/heads/master)"
export VPS_COMMIT_SHA
# Used for keeping bash variables for run-time substituion instead of execution time substitution.
# Taken from:
# https://stackoverflow.com/questions/24963705/is-there-an-escape-character-for-envsubst
export DOLLAR='$'

#
# docker-compose
#
export VOLUME_HOME="/home/vps/volumes"

#
# Nix
#
# Use the same $NIX_PATH as in the CI
# See also:
# https://discourse.nixos.org/t/inconsistent-hash-of-buildgomodule/3127/4
export NIX_PATH=nixpkgs=channel:nixos-unstable

if [[ "$(file -b ./secrets/secret-envrc.sh)" = "data" ]];
then
  echo 'The ./secrets/secret-envrc.sh is encrypted, not sourcing it.'
  return
fi

SSH_SERVER_PRIVATE_KEY="$(cat ./secrets/ssh/vps-box-server)"
export SSH_SERVER_PRIVATE_KEY
SSH_SERVER_PUBLIC_KEY="$(cat ./secrets/ssh/vps-box-server.pub)"
export SSH_SERVER_PUBLIC_KEY

source ./secrets/secret-envrc.sh
