#!/bin/bash -e usage() { echo "usage: $0" echo echo "Required Variables:" echo echo " DOMAIN" echo " ROOT_CA Path to root CA certificate" echo " ROOT_CRT Path to root/wildcard certificate" echo " ROOT_KEY Path to root/wildcard private key" echo " JWT_CRT Path to Token Auth certificate" echo " JWT_KEY Path to Token Auth private key" echo " JWT_KID Path to KeyID for the Token Auth certificate" echo " VPN_CA Path to the VPN sub-CA certificate" echo " VPN_CRT Path to the VPN server certificate" echo " VPN_KEY Path to the VPN server private key" echo " VPN_DH Path to the VPN server Diffie Hellman parameters" echo " SUPERUSER_EMAIL Email address of the superuser" echo " SUPERUSER_PASSWORD Password of the superuser" echo } for var in DOMAIN ROOT_CA ROOT_CRT ROOT_KEY JWT_CRT JWT_KEY JWT_KID VPN_CA VPN_CRT VPN_KEY VPN_DH SUPERUSER_EMAIL SUPERUSER_PASSWORD; do if [ -z "${!var-}" ]; then usage exit 1 fi done randstr() { LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom | fold -w "${1:-32}" | head -n 1 } b64encode() { echo "$@" | base64 --wrap=0 2>/dev/null || echo "$@" | base64 --break=0 2>/dev/null } b64file() { b64encode "$(cat "$@")" } VPN_CONFIG=$(cat <