2018-02-20 09:20:12 +00:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
2018-12-17 18:36:59 +00:00
|
|
|
BLACK=`tput setaf 0`
|
|
|
|
RED=`tput setaf 1`
|
|
|
|
GREEN=`tput setaf 2`
|
|
|
|
YELLOW=`tput setaf 3`
|
|
|
|
BLUE=`tput setaf 4`
|
|
|
|
MAGENTA=`tput setaf 5`
|
|
|
|
CYAN=`tput setaf 6`
|
|
|
|
WHITE=`tput setaf 7`
|
|
|
|
|
|
|
|
BOLD=`tput bold`
|
|
|
|
RESET=`tput sgr0`
|
|
|
|
|
|
|
|
# for macos machines, we need proper OpenSSL...
|
|
|
|
OPENSSL_VERSION=$(openssl version -v)
|
|
|
|
if [[ "${OPENSSL_VERSION}" =~ ^LibreSSL.*$ ]]; then
|
|
|
|
echo -e "${RED}ERROR: You may not have a compatible OpenSSL version (${OPENSSL_VERSION}). Please install OpenSSL version 1.0.2q or above.${RESET}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
source "${BASH_SOURCE%/*}/_realpath"
|
|
|
|
|
2018-02-20 09:20:12 +00:00
|
|
|
CMD="$(realpath "$0")"
|
|
|
|
DIR="$(dirname "${CMD}")"
|
|
|
|
BASE_DIR="$(dirname "${DIR}")"
|
|
|
|
CONFIG_DIR="${BASE_DIR}/config"
|
|
|
|
CERTS_DIR="${CONFIG_DIR}/certs"
|
|
|
|
|
|
|
|
DOMAIN=openbalena.local
|
|
|
|
|
|
|
|
usage() {
|
2018-11-06 16:19:21 +00:00
|
|
|
echo "usage: $0 [-h] [-p] [-d DOMAIN] -U EMAIL -P PASSWORD"
|
2018-02-20 09:20:12 +00:00
|
|
|
echo
|
2018-11-06 16:19:21 +00:00
|
|
|
echo " -p patch hosts - patch the host /etc/hosts file"
|
|
|
|
echo " -d DOMAIN the domain name this deployment will run as, eg. example.com. Default is 'openbalena.local'"
|
|
|
|
echo " -U EMAIL the email address of the superuser account, used to login to your install from the Balena CLI"
|
|
|
|
echo " -P PASSWORD the password to use for the superuser account."
|
2018-02-20 09:20:12 +00:00
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
show_help=false
|
|
|
|
patch_hosts=false
|
2018-12-17 18:36:59 +00:00
|
|
|
while getopts ":hpxd:U:P:" opt; do
|
2018-02-20 09:20:12 +00:00
|
|
|
case "${opt}" in
|
|
|
|
h) show_help=true;;
|
|
|
|
p) patch_hosts=true;;
|
2018-12-17 18:36:59 +00:00
|
|
|
x) set -x;;
|
2018-02-20 09:20:12 +00:00
|
|
|
d) DOMAIN="${OPTARG}";;
|
2018-11-06 16:19:21 +00:00
|
|
|
U) SUPERUSER_EMAIL="${OPTARG}";;
|
|
|
|
P) SUPERUSER_PASSWORD="${OPTARG}";;
|
2018-02-20 09:20:12 +00:00
|
|
|
*)
|
|
|
|
echo "Invalid argument: -${OPTARG}"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
2018-11-06 16:19:21 +00:00
|
|
|
if [ -z "${SUPERUSER_EMAIL}" ] || [ -z "${SUPERUSER_PASSWORD}" ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-02-20 09:20:12 +00:00
|
|
|
if [ "$show_help" = "true" ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo_bold() {
|
|
|
|
printf "\\033[1m%s\\033[0m\\n" "${@}"
|
|
|
|
}
|
|
|
|
|
|
|
|
echo_bold "==> Creating new configuration at: $CONFIG_DIR"
|
|
|
|
mkdir -p "$CONFIG_DIR" "$CERTS_DIR"
|
|
|
|
|
2018-12-17 18:36:59 +00:00
|
|
|
echo_bold "==> Bootstrapping easy-rsa..."
|
|
|
|
source "${DIR}/ssl-common.sh"
|
|
|
|
|
2018-02-20 09:20:12 +00:00
|
|
|
echo_bold "==> Generating root CA cert..."
|
|
|
|
# shellcheck source=scripts/gen-root-ca
|
|
|
|
source "${DIR}/gen-root-ca" "${DOMAIN}" "${CERTS_DIR}"
|
|
|
|
|
|
|
|
echo_bold "==> Generating root cert chain for haproxy..."
|
|
|
|
# shellcheck source=scripts/gen-root-cert
|
|
|
|
source "${DIR}/gen-root-cert" "${DOMAIN}" "${CERTS_DIR}"
|
|
|
|
|
|
|
|
echo_bold "==> Generating token auth cert..."
|
|
|
|
# shellcheck source=scripts/gen-token-auth-cert
|
|
|
|
source "${DIR}/gen-token-auth-cert" "${DOMAIN}" "${CERTS_DIR}"
|
|
|
|
|
|
|
|
echo_bold "==> Generating VPN CA, cert and dhparam (this may take a while)..."
|
|
|
|
# shellcheck source=scripts/gen-vpn-certs
|
|
|
|
source "${DIR}/gen-vpn-certs" "${DOMAIN}" "${CERTS_DIR}"
|
|
|
|
|
|
|
|
echo_bold "==> Setting up environment..."
|
|
|
|
# shellcheck source=scripts/make-env
|
|
|
|
cat >"${CONFIG_DIR}/activate" <(source "${DIR}/make-env")
|
|
|
|
|
|
|
|
echo_bold "==> Adding default compose file..."
|
|
|
|
cp "${BASE_DIR}/compose/template.yml" "${CONFIG_DIR}/docker-compose.yml"
|
|
|
|
|
|
|
|
if [ "${patch_hosts}" = "true" ]; then
|
|
|
|
echo_bold "==> Patching /etc/hosts..."
|
|
|
|
# shellcheck source=scripts/patch-hosts
|
|
|
|
source "${DIR}/patch-hosts" "${DOMAIN}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo_bold "==> Success!"
|
|
|
|
echo ' - Start the instance with: ./scripts/compose up -d'
|
|
|
|
echo ' - Stop the instance with: ./scripts/compose stop'
|
|
|
|
echo ' - To create the superuser, see: ./scripts/create-superuser -h'
|
2018-12-17 12:57:49 +00:00
|
|
|
echo " - Use the following certificate with Balena CLI: ${CERTS_DIR}/root/ca.crt"
|