|
@@ -1,29 +1,20 @@
|
|
|
#!/bin/bash
|
|
|
|
|
|
+CONFIG_FILE=netmaker.env
|
|
|
+# location of nm-quick.sh (usually `/root`)
|
|
|
+SCRIPT_DIR=$(dirname "$(realpath "$0")")
|
|
|
+CONFIG_PATH="$SCRIPT_DIR/$CONFIG_FILE"
|
|
|
LATEST=$(curl -s https://api.github.com/repos/gravitl/netmaker/releases/latest | grep "tag_name" | cut -d : -f 2,3 | tr -d [:space:],\")
|
|
|
|
|
|
-print_logo() {(
|
|
|
-cat << "EOF"
|
|
|
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-
|
|
|
- __ __ ______ ______ __ __ ______ __ __ ______ ______
|
|
|
-/\ "-.\ \ /\ ___\ /\__ _\ /\ "-./ \ /\ __ \ /\ \/ / /\ ___\ /\ == \
|
|
|
-\ \ \-. \ \ \ __\ \/_/\ \/ \ \ \-./\ \ \ \ __ \ \ \ _"-. \ \ __\ \ \ __<
|
|
|
- \ \_\\"\_\ \ \_____\ \ \_\ \ \_\ \ \_\ \ \_\ \_\ \ \_\ \_\ \ \_____\ \ \_\ \_\
|
|
|
- \/_/ \/_/ \/_____/ \/_/ \/_/ \/_/ \/_/\/_/ \/_/\/_/ \/_____/ \/_/ /_/
|
|
|
-
|
|
|
-
|
|
|
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
-EOF
|
|
|
-)}
|
|
|
-
|
|
|
if [ $(id -u) -ne 0 ]; then
|
|
|
- echo "This script must be run as root"
|
|
|
- exit 1
|
|
|
+ echo "This script must be run as root"
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
+# read the config file
|
|
|
+if [ -f "$CONFIG_PATH" ]; then
|
|
|
+ echo "Reading config from $CONFIG_PATH"
|
|
|
+ source "$CONFIG_PATH"
|
|
|
fi
|
|
|
|
|
|
unset INSTALL_TYPE
|
|
@@ -33,53 +24,52 @@ unset IMAGE_TAG
|
|
|
unset AUTO_BUILD
|
|
|
|
|
|
# usage - displays usage instructions
|
|
|
-usage () {
|
|
|
- echo "usage: ./nm-quick.sh [-e] [-b buildtype] [-t tag] [-a auto]"
|
|
|
- echo " -e if specified, will install netmaker EE"
|
|
|
- echo " -b type of build; options:"
|
|
|
+usage() {
|
|
|
+ echo "usage: ./nm-quick.sh [-e] [-b buildtype] [-t tag] [-a auto]"
|
|
|
+ echo " -e if specified, will install netmaker EE"
|
|
|
+ echo " -b type of build; options:"
|
|
|
echo " \"version\" - will install a specific version of Netmaker using remote git and dockerhub"
|
|
|
- echo " \"local\": - will install by cloning repo and and building images from git"
|
|
|
+ echo " \"local\": - will install by cloning repo and building images from git"
|
|
|
echo " \"branch\": - will install a specific branch using remote git and dockerhub"
|
|
|
- echo " -t tag of build; if buildtype=version, tag=version. If builtype=branch or builtype=local, tag=branch"
|
|
|
- echo " -a auto-build; skip prompts and use defaults, if none provided"
|
|
|
- echo "examples:"
|
|
|
+ echo " -t tag of build; if buildtype=version, tag=version. If builtype=branch or builtype=local, tag=branch"
|
|
|
+ echo " -a auto-build; skip prompts and use defaults, if none provided"
|
|
|
+ echo "examples:"
|
|
|
echo " nm-quick.sh -e -b version -t $LATEST"
|
|
|
- echo " nm-quick.sh -e -b local -t feature_v0.17.2_newfeature"
|
|
|
+ echo " nm-quick.sh -e -b local -t feature_v0.17.2_newfeature"
|
|
|
echo " nm-quick.sh -e -b branch -t develop"
|
|
|
- exit 1
|
|
|
+ exit 1
|
|
|
}
|
|
|
|
|
|
-while getopts evab:t: flag
|
|
|
-do
|
|
|
+while getopts evab:t: flag; do
|
|
|
case "${flag}" in
|
|
|
- e)
|
|
|
- INSTALL_TYPE="ee"
|
|
|
- ;;
|
|
|
- v)
|
|
|
+ e)
|
|
|
+ INSTALL_TYPE="ee"
|
|
|
+ ;;
|
|
|
+ v)
|
|
|
+ usage
|
|
|
+ exit 0
|
|
|
+ ;;
|
|
|
+ a)
|
|
|
+ AUTO_BUILD="on"
|
|
|
+ ;;
|
|
|
+ b)
|
|
|
+ BUILD_TYPE=${OPTARG}
|
|
|
+ if [[ ! "$BUILD_TYPE" =~ ^(version|local|branch)$ ]]; then
|
|
|
+ echo "error: $BUILD_TYPE is invalid"
|
|
|
+ echo "valid options: version, local, branch"
|
|
|
usage
|
|
|
- exit 0
|
|
|
- ;;
|
|
|
- a)
|
|
|
- AUTO_BUILD="on"
|
|
|
- ;;
|
|
|
- b)
|
|
|
- BUILD_TYPE=${OPTARG}
|
|
|
- if [[ ! "$BUILD_TYPE" =~ ^(version|local|branch)$ ]]; then
|
|
|
- echo "error: $BUILD_TYPE is invalid"
|
|
|
- echo "valid options: version, local, branch"
|
|
|
- usage
|
|
|
- exit 1
|
|
|
- fi
|
|
|
- ;;
|
|
|
- t)
|
|
|
- BUILD_TAG=${OPTARG}
|
|
|
- ;;
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
+ ;;
|
|
|
+ t)
|
|
|
+ BUILD_TAG=${OPTARG}
|
|
|
+ ;;
|
|
|
esac
|
|
|
done
|
|
|
|
|
|
# print_logo - prints the netmaker logo
|
|
|
print_logo() {
|
|
|
-cat << "EOF"
|
|
|
+ cat <<"EOF"
|
|
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
@@ -111,11 +101,11 @@ set_buildinfo() {
|
|
|
|
|
|
if [ -z "$BUILD_TAG" ] && [ ! -z "$BUILD_TYPE" ]; then
|
|
|
echo "error: must specify build tag when build type \"$BUILD_TYPE\" is specified"
|
|
|
- usage
|
|
|
+ usage
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
|
- IMAGE_TAG=$(sed 's/\//-/g' <<< "$BUILD_TAG")
|
|
|
+ IMAGE_TAG=$(sed 's/\//-/g' <<<"$BUILD_TAG")
|
|
|
|
|
|
if [ "$1" = "ce" ]; then
|
|
|
INSTALL_TYPE="ce"
|
|
@@ -131,48 +121,48 @@ set_buildinfo() {
|
|
|
echo "EE will require you to create an account at https://dashboard.license.netmaker.io"
|
|
|
echo "-----------------------------------------------------"
|
|
|
select install_option in "Community Edition" "Enterprise Edition"; do
|
|
|
- case $REPLY in
|
|
|
+ case $REPLY in
|
|
|
1)
|
|
|
- echo "installing Netmaker CE"
|
|
|
- INSTALL_TYPE="ce"
|
|
|
- break
|
|
|
- ;;
|
|
|
+ echo "installing Netmaker CE"
|
|
|
+ INSTALL_TYPE="ce"
|
|
|
+ break
|
|
|
+ ;;
|
|
|
2)
|
|
|
- echo "installing Netmaker EE"
|
|
|
- INSTALL_TYPE="ee"
|
|
|
- break
|
|
|
- ;;
|
|
|
- *) echo "invalid option $REPLY";;
|
|
|
- esac
|
|
|
+ echo "installing Netmaker EE"
|
|
|
+ INSTALL_TYPE="ee"
|
|
|
+ break
|
|
|
+ ;;
|
|
|
+ *) echo "invalid option $REPLY" ;;
|
|
|
+ esac
|
|
|
done
|
|
|
fi
|
|
|
echo "-----------Build Options-----------------------------"
|
|
|
- echo " EE or CE: $INSTALL_TYPE";
|
|
|
- echo " Build Type: $BUILD_TYPE";
|
|
|
- echo " Build Tag: $BUILD_TAG";
|
|
|
- echo " Image Tag: $IMAGE_TAG";
|
|
|
+ echo " EE or CE: $INSTALL_TYPE"
|
|
|
+ echo " Build Type: $BUILD_TYPE"
|
|
|
+ echo " Build Tag: $BUILD_TAG"
|
|
|
+ echo " Image Tag: $IMAGE_TAG"
|
|
|
echo "-----------------------------------------------------"
|
|
|
|
|
|
}
|
|
|
|
|
|
# install_yq - install yq if not present
|
|
|
install_yq() {
|
|
|
- if ! command -v yq &> /dev/null; then
|
|
|
- wget -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/v4.31.1/yq_linux_$(dpkg --print-architecture)
|
|
|
+ if ! command -v yq &>/dev/null; then
|
|
|
+ wget -qO /usr/bin/yq https://github.com/mikefarah/yq/releases/download/v4.31.1/yq_linux_$(dpkg --print-architecture)
|
|
|
chmod +x /usr/bin/yq
|
|
|
fi
|
|
|
set +e
|
|
|
- if ! command -v yq &> /dev/null; then
|
|
|
+ if ! command -v yq &>/dev/null; then
|
|
|
set -e
|
|
|
- wget -O /usr/bin/yq https://github.com/mikefarah/yq/releases/download/v4.31.1/yq_linux_amd64
|
|
|
+ wget -qO /usr/bin/yq https://github.com/mikefarah/yq/releases/download/v4.31.1/yq_linux_amd64
|
|
|
chmod +x /usr/bin/yq
|
|
|
fi
|
|
|
set -e
|
|
|
- if ! command -v yq &> /dev/null; then
|
|
|
+ if ! command -v yq &>/dev/null; then
|
|
|
echo "failed to install yq. Please install yq and try again."
|
|
|
echo "https://github.com/mikefarah/yq/#install"
|
|
|
exit 1
|
|
|
- fi
|
|
|
+ fi
|
|
|
}
|
|
|
|
|
|
# setup_netclient - adds netclient to docker-compose
|
|
@@ -182,21 +172,44 @@ setup_netclient() {
|
|
|
netclient uninstall
|
|
|
set -e
|
|
|
|
|
|
- wget -O netclient https://github.com/gravitl/netclient/releases/download/$LATEST/netclient-linux-amd64
|
|
|
+ # TODO arm support
|
|
|
+ wget -qO netclient https://github.com/gravitl/netclient/releases/download/$LATEST/netclient-linux-amd64
|
|
|
chmod +x netclient
|
|
|
./netclient install
|
|
|
+ echo "Register token: $TOKEN"
|
|
|
netclient register -t $TOKEN
|
|
|
|
|
|
- echo "waiting for client to become available"
|
|
|
- wait_seconds 10
|
|
|
+ echo "waiting for netclient to become available"
|
|
|
+ local found=false
|
|
|
+ local file=/etc/netclient/nodes.yml
|
|
|
+ for ((a = 1; a <= 90; a++)); do
|
|
|
+ if [ -f "$file" ]; then
|
|
|
+ found=true
|
|
|
+ break
|
|
|
+ fi
|
|
|
+ sleep 1
|
|
|
+ done
|
|
|
+
|
|
|
+ if [ "$found" = false ]; then
|
|
|
+ echo "Error - $file not present"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
}
|
|
|
|
|
|
# configure_netclient - configures server's netclient as a default host and an ingress gateway
|
|
|
configure_netclient() {
|
|
|
|
|
|
NODE_ID=$(sudo cat /etc/netclient/nodes.yml | yq -r .netmaker.commonnode.id)
|
|
|
+ if [ "$NODE_ID" = "" ] || [ "$NODE_ID" = "null" ]; then
|
|
|
+ echo "Error obtaining NODE_ID for the new network"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
echo "register complete. New node ID: $NODE_ID"
|
|
|
HOST_ID=$(sudo cat /etc/netclient/netclient.yml | yq -r .host.id)
|
|
|
+ if [ "$HOST_ID" = "" ] || [ "$HOST_ID" = "null" ]; then
|
|
|
+ echo "Error obtaining HOST_ID for the new network"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
echo "making host a default"
|
|
|
echo "Host ID: $HOST_ID"
|
|
|
# set as a default host
|
|
@@ -210,69 +223,162 @@ configure_netclient() {
|
|
|
# setup_nmctl - pulls nmctl and makes it executable
|
|
|
setup_nmctl() {
|
|
|
|
|
|
- wget -O /usr/bin/nmctl https://github.com/gravitl/netmaker/releases/download/$LATEST/nmctl-linux-amd64
|
|
|
-
|
|
|
- chmod +x /usr/bin/nmctl
|
|
|
- echo "using server api.$NETMAKER_BASE_DOMAIN"
|
|
|
- echo "using master key $MASTER_KEY"
|
|
|
- nmctl context set default --endpoint="https://api.$NETMAKER_BASE_DOMAIN" --master_key="$MASTER_KEY"
|
|
|
- nmctl context use default
|
|
|
- RESP=$(nmctl network list)
|
|
|
- if [[ $RESP == *"unauthorized"* ]]; then
|
|
|
- echo "Unable to properly configure NMCTL, exiting..."
|
|
|
- exit 1
|
|
|
- fi
|
|
|
+ # TODO arm support
|
|
|
+ local URL="https://github.com/gravitl/netmaker/releases/download/$LATEST/nmctl-linux-amd64"
|
|
|
+ echo "Downloading nmctl..."
|
|
|
+ wget -qO /usr/bin/nmctl "$URL"
|
|
|
+
|
|
|
+ if [ ! -f /usr/bin/nmctl ]; then
|
|
|
+ echo "Error downloading nmctl from '$URL'"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
+
|
|
|
+ chmod +x /usr/bin/nmctl
|
|
|
+ echo "using server api.$NETMAKER_BASE_DOMAIN"
|
|
|
+ echo "using master key $MASTER_KEY"
|
|
|
+ nmctl context set default --endpoint="https://api.$NETMAKER_BASE_DOMAIN" --master_key="$MASTER_KEY"
|
|
|
+ nmctl context use default
|
|
|
+ RESP=$(nmctl network list)
|
|
|
+ if [[ $RESP == *"unauthorized"* ]]; then
|
|
|
+ echo "Unable to properly configure NMCTL, exiting..."
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
}
|
|
|
|
|
|
# wait_seconds - wait for the specified period of time
|
|
|
-wait_seconds() {(
|
|
|
- for ((a=1; a <= $1; a++))
|
|
|
- do
|
|
|
- echo ". . ."
|
|
|
- sleep 1
|
|
|
- done
|
|
|
-)}
|
|
|
+wait_seconds() { (
|
|
|
+ for ((a = 1; a <= $1; a++)); do
|
|
|
+ echo ". . ."
|
|
|
+ sleep 1
|
|
|
+ done
|
|
|
+); }
|
|
|
|
|
|
# confirm - get user input to confirm that they want to perform the next step
|
|
|
-confirm() {(
|
|
|
- if [ "$AUTO_BUILD" = "on" ]; then
|
|
|
- return 0
|
|
|
- fi
|
|
|
- while true; do
|
|
|
- read -p 'Does everything look right? [y/n]: ' yn
|
|
|
- case $yn in
|
|
|
- [Yy]* ) override="true"; break;;
|
|
|
- [Nn]* ) echo "exiting..."; exit 1;;
|
|
|
- * ) echo "Please answer yes or no.";;
|
|
|
- esac
|
|
|
- done
|
|
|
-)}
|
|
|
+confirm() { (
|
|
|
+ if [ "$AUTO_BUILD" = "on" ]; then
|
|
|
+ return 0
|
|
|
+ fi
|
|
|
+ while true; do
|
|
|
+ read -p 'Does everything look right? [y/n]: ' yn
|
|
|
+ case $yn in
|
|
|
+ [Yy]*)
|
|
|
+ override="true"
|
|
|
+ break
|
|
|
+ ;;
|
|
|
+ [Nn]*)
|
|
|
+ echo "exiting..."
|
|
|
+ exit 1
|
|
|
+ # TODO start from the beginning instead
|
|
|
+ ;;
|
|
|
+ *) echo "Please answer yes or no." ;;
|
|
|
+ esac
|
|
|
+ done
|
|
|
+) }
|
|
|
+
|
|
|
+save_config() { (
|
|
|
+ echo "Saving the config to $CONFIG_PATH"
|
|
|
+ touch "$CONFIG_PATH"
|
|
|
+ save_config_item NM_EMAIL "$EMAIL"
|
|
|
+ save_config_item NM_DOMAIN "$NETMAKER_BASE_DOMAIN"
|
|
|
+ save_config_item UI_IMAGE_TAG "$IMAGE_TAG"
|
|
|
+ if [ "$BUILD_TYPE" = "local" ]; then
|
|
|
+ save_config_item UI_IMAGE_TAG "$LATEST"
|
|
|
+ else
|
|
|
+ save_config_item UI_IMAGE_TAG "$IMAGE_TAG"
|
|
|
+ fi
|
|
|
+ # version-specific entries
|
|
|
+ if [ "$INSTALL_TYPE" = "ee" ]; then
|
|
|
+ save_config_item NETMAKER_ACCOUNT_ID "$ACCOUNT_ID"
|
|
|
+ save_config_item LICENSE_KEY "$LICENSE_KEY"
|
|
|
+ save_config_item METRICS_EXPORTER "on"
|
|
|
+ save_config_item PROMETHEUS "on"
|
|
|
+ if [ "$BUILD_TYPE" = "version" ]; then
|
|
|
+ save_config_item SERVER_IMAGE_TAG "$IMAGE_TAG-ee"
|
|
|
+ else
|
|
|
+ save_config_item SERVER_IMAGE_TAG "$IMAGE_TAG"
|
|
|
+ fi
|
|
|
+ else
|
|
|
+ save_config_item METRICS_EXPORTER "off"
|
|
|
+ save_config_item PROMETHEUS "off"
|
|
|
+ save_config_item SERVER_IMAGE_TAG "$IMAGE_TAG"
|
|
|
+ fi
|
|
|
+ # copy entries from the previous config
|
|
|
+ local toCopy=("SERVER_HOST" "MASTER_KEY" "TURN_USERNAME" "MQ_USERNAME" "MQ_PASSWORD"
|
|
|
+ "INSTALL_TYPE" "NODE_ID" "METRICS_EXPORTER" "PROMETHEUS" "DNS_MODE" "NETCLIENT_AUTO_UPDATE" "API_PORT"
|
|
|
+ "CORS_ALLOWED_ORIGIN" "DISPLAY_KEYS" "DATABASE" "SERVER_BROKER_ENDPOINT" "STUN_PORT" "VERBOSITY"
|
|
|
+ "DEFAULT_PROXY_MODE" "TURN_PORT" "USE_TURN" "DEBUG_MODE" "TURN_API_PORT" "REST_BACKEND" "DISABLE_REMOTE_IP_CHECK"
|
|
|
+ "TELEMETRY" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET" "FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER"
|
|
|
+ "EXPORTER_API_PORT")
|
|
|
+ for name in "${toCopy[@]}"; do
|
|
|
+ save_config_item $name "${!name}"
|
|
|
+ done
|
|
|
+ # preserve debug entries
|
|
|
+ if test -n "$NM_SKIP_BUILD"; then
|
|
|
+ save_config_item NM_SKIP_BUILD "$NM_SKIP_BUILD"
|
|
|
+ fi
|
|
|
+ if test -n "$NM_SKIP_CLONE"; then
|
|
|
+ save_config_item NM_SKIP_CLONE "$NM_SKIP_CLONE"
|
|
|
+ fi
|
|
|
+ if test -n "$NM_SKIP_DEPS"; then
|
|
|
+ save_config_item NM_SKIP_DEPS "$NM_SKIP_DEPS"
|
|
|
+ fi
|
|
|
+); }
|
|
|
+
|
|
|
+save_config_item() { (
|
|
|
+ local NAME="$1"
|
|
|
+ local VALUE="$2"
|
|
|
+ # echo "NAME $NAME"
|
|
|
+ # echo "VALUE $VALUE"
|
|
|
+ if grep -q "^$NAME=" "$CONFIG_PATH"; then
|
|
|
+ # TODO escape | in the value
|
|
|
+ sed -i "s|$NAME=.*|$NAME='$VALUE'|" "$CONFIG_PATH"
|
|
|
+ else
|
|
|
+ echo "$NAME=\"$VALUE\"" >>"$CONFIG_PATH"
|
|
|
+ fi
|
|
|
+); }
|
|
|
|
|
|
# local_install_setup - builds artifacts based on specified branch locally to use in install
|
|
|
-local_install_setup() {(
|
|
|
- rm -rf netmaker-tmp
|
|
|
- mkdir netmaker-tmp
|
|
|
- cd netmaker-tmp
|
|
|
- git clone https://www.github.com/gravitl/netmaker
|
|
|
+local_install_setup() { (
|
|
|
+ if test -z "$NM_SKIP_CLONE"; then
|
|
|
+ rm -rf netmaker-tmp
|
|
|
+ mkdir netmaker-tmp
|
|
|
+ cd netmaker-tmp
|
|
|
+ git clone --single-branch --depth=1 --branch=$BUILD_TAG https://www.github.com/gravitl/netmaker
|
|
|
+ else
|
|
|
+ cd netmaker-tmp
|
|
|
+ echo "Skipping git clone on NM_SKIP_CLONE"
|
|
|
+ fi
|
|
|
cd netmaker
|
|
|
- git checkout $BUILD_TAG
|
|
|
- git pull origin $BUILD_TAG
|
|
|
- docker build --no-cache --build-arg version=$IMAGE_TAG -t gravitl/netmaker:$IMAGE_TAG .
|
|
|
+ if test -z "$NM_SKIP_BUILD"; then
|
|
|
+ docker build --no-cache --build-arg version=$IMAGE_TAG -t gravitl/netmaker:$IMAGE_TAG .
|
|
|
+ else
|
|
|
+ echo "Skipping build on NM_SKIP_BUILD"
|
|
|
+ fi
|
|
|
+ cp compose/docker-compose.yml "$SCRIPT_DIR/docker-compose.yml"
|
|
|
if [ "$INSTALL_TYPE" = "ee" ]; then
|
|
|
- cp compose/docker-compose.ee.yml /root/docker-compose.yml
|
|
|
- cp docker/Caddyfile-EE /root/Caddyfile
|
|
|
+ cp compose/docker-compose.ee.yml "$SCRIPT_DIR/docker-compose.override.yml"
|
|
|
+ cp docker/Caddyfile-EE "$SCRIPT_DIR/Caddyfile"
|
|
|
else
|
|
|
- cp compose/docker-compose.yml /root/docker-compose.yml
|
|
|
- cp docker/Caddyfile /root/Caddyfile
|
|
|
+ cp docker/Caddyfile "$SCRIPT_DIR/Caddyfile"
|
|
|
fi
|
|
|
- cp docker/mosquitto.conf /root/mosquitto.conf
|
|
|
- cp docker/wait.sh /root/wait.sh
|
|
|
+ cp scripts/nm-certs.sh "$SCRIPT_DIR/nm-certs.sh"
|
|
|
+ cp scripts/netmaker.env "$SCRIPT_DIR/netmaker.env"
|
|
|
+ ln -fs "$SCRIPT_DIR/netmaker.env" "$SCRIPT_DIR/.env"
|
|
|
+ cp docker/mosquitto.conf "$SCRIPT_DIR/mosquitto.conf"
|
|
|
+ cp docker/wait.sh "$SCRIPT_DIR/wait.sh"
|
|
|
cd ../../
|
|
|
- rm -rf netmaker-tmp
|
|
|
-)}
|
|
|
+ if test -z "$NM_SKIP_CLONE"; then
|
|
|
+ rm -rf netmaker-tmp
|
|
|
+ fi
|
|
|
+); }
|
|
|
|
|
|
-# install_dependencies - install necessary packages to run netmaker
|
|
|
+# install_dependencies - install necessary packages to run netmaker
|
|
|
install_dependencies() {
|
|
|
+
|
|
|
+ if test -n "$NM_SKIP_DEPS"; then
|
|
|
+ return
|
|
|
+ fi
|
|
|
+
|
|
|
echo "checking dependencies..."
|
|
|
|
|
|
OS=$(uname)
|
|
@@ -297,29 +403,21 @@ install_dependencies() {
|
|
|
update_cmd='yum update'
|
|
|
install_cmd='yum install -y'
|
|
|
elif [ -f /etc/arch-release ]; then
|
|
|
- dependecies="git wireguard-tools dnsutils jq docker.io docker-compose"
|
|
|
+ dependencies="git wireguard-tools dnsutils jq docker.io docker-compose"
|
|
|
update_cmd='pacman -Sy'
|
|
|
install_cmd='pacman -S --noconfirm'
|
|
|
elif [ "${OS}" = "FreeBSD" ]; then
|
|
|
dependencies="git wireguard wget jq docker.io docker-compose"
|
|
|
update_cmd='pkg update'
|
|
|
install_cmd='pkg install -y'
|
|
|
- elif [ -f /etc/turris-version ]; then
|
|
|
- dependencies="git wireguard-tools bash jq docker.io docker-compose"
|
|
|
- OS="TurrisOS"
|
|
|
- update_cmd='opkg update'
|
|
|
- install_cmd='opkg install'
|
|
|
- elif [ -f /etc/openwrt_release ]; then
|
|
|
- dependencies="git wireguard-tools bash jq docker.io docker-compose"
|
|
|
- OS="OpenWRT"
|
|
|
- update_cmd='opkg update'
|
|
|
- install_cmd='opkg install'
|
|
|
else
|
|
|
install_cmd=''
|
|
|
fi
|
|
|
|
|
|
if [ -z "${install_cmd}" ]; then
|
|
|
- echo "OS unsupported for automatic dependency install"
|
|
|
+ echo "OS unsupported for automatic dependency install"
|
|
|
+ # TODO shouldnt exit, check if deps available, if not
|
|
|
+ # ask the user to install manually and continue when ready
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
@@ -345,7 +443,7 @@ install_dependencies() {
|
|
|
echo " " FAILED TO INSTALL $1
|
|
|
echo " " This may break functionality.
|
|
|
fi
|
|
|
- fi
|
|
|
+ fi
|
|
|
else
|
|
|
if [ "${OS}" = "OpenWRT" ] || [ "${OS}" = "TurrisOS" ]; then
|
|
|
is_installed=$(opkg list-installed $1 | grep $1)
|
|
@@ -379,7 +477,7 @@ install_dependencies() {
|
|
|
echo "-----------------------------------------------------"
|
|
|
echo "dependency check complete"
|
|
|
echo "-----------------------------------------------------"
|
|
|
-}
|
|
|
+}
|
|
|
set -e
|
|
|
|
|
|
# set_install_vars - sets the variables that will be used throughout installation
|
|
@@ -391,36 +489,38 @@ set_install_vars() {
|
|
|
fi
|
|
|
|
|
|
NETMAKER_BASE_DOMAIN=nm.$(echo $IP_ADDR | tr . -).nip.io
|
|
|
- COREDNS_IP=$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p')
|
|
|
- SERVER_PUBLIC_IP=$IP_ADDR
|
|
|
- MASTER_KEY=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 30 ; echo '')
|
|
|
+ SERVER_HOST=$IP_ADDR
|
|
|
+ MASTER_KEY=$(
|
|
|
+ tr -dc A-Za-z0-9 </dev/urandom | head -c 30
|
|
|
+ echo ''
|
|
|
+ )
|
|
|
DOMAIN_TYPE=""
|
|
|
echo "-----------------------------------------------------"
|
|
|
echo "Would you like to use your own domain for netmaker, or an auto-generated domain?"
|
|
|
- echo "To use your own domain, add a Wildcard DNS record (e.x: *.netmaker.example.com) pointing to $SERVER_PUBLIC_IP"
|
|
|
+ echo "To use your own domain, add a Wildcard DNS record (e.x: *.netmaker.example.com) pointing to $SERVER_HOST"
|
|
|
echo "IMPORTANT: Due to the high volume of requests, the auto-generated domain has been rate-limited by the certificate provider."
|
|
|
echo "For this reason, we STRONGLY RECOMMEND using your own domain. Using the auto-generated domain may lead to a failed installation due to rate limiting."
|
|
|
echo "-----------------------------------------------------"
|
|
|
|
|
|
if [ "$AUTO_BUILD" = "on" ]; then
|
|
|
- DOMAIN_TYPE="auto"
|
|
|
+ DOMAIN_TYPE="auto"
|
|
|
else
|
|
|
select domain_option in "Auto Generated ($NETMAKER_BASE_DOMAIN)" "Custom Domain (e.x: netmaker.example.com)"; do
|
|
|
- case $REPLY in
|
|
|
+ case $REPLY in
|
|
|
1)
|
|
|
- echo "using $NETMAKER_BASE_DOMAIN for base domain"
|
|
|
- DOMAIN_TYPE="auto"
|
|
|
- break
|
|
|
- ;;
|
|
|
+ echo "using $NETMAKER_BASE_DOMAIN for base domain"
|
|
|
+ DOMAIN_TYPE="auto"
|
|
|
+ break
|
|
|
+ ;;
|
|
|
2)
|
|
|
- read -p "Enter Custom Domain (make sure *.domain points to $SERVER_PUBLIC_IP first): " domain
|
|
|
- NETMAKER_BASE_DOMAIN=$domain
|
|
|
- echo "using $NETMAKER_BASE_DOMAIN"
|
|
|
- DOMAIN_TYPE="custom"
|
|
|
- break
|
|
|
- ;;
|
|
|
- *) echo "invalid option $REPLY";;
|
|
|
- esac
|
|
|
+ read -p "Enter Custom Domain (make sure *.domain points to $SERVER_HOST first): " domain
|
|
|
+ NETMAKER_BASE_DOMAIN=$domain
|
|
|
+ echo "using $NETMAKER_BASE_DOMAIN"
|
|
|
+ DOMAIN_TYPE="custom"
|
|
|
+ break
|
|
|
+ ;;
|
|
|
+ *) echo "invalid option $REPLY" ;;
|
|
|
+ esac
|
|
|
done
|
|
|
fi
|
|
|
|
|
@@ -433,7 +533,7 @@ set_install_vars() {
|
|
|
echo " broker.$NETMAKER_BASE_DOMAIN"
|
|
|
echo " stun.$NETMAKER_BASE_DOMAIN"
|
|
|
echo " turn.$NETMAKER_BASE_DOMAIN"
|
|
|
- echo " turnapi.$NETMAKER_BASE_DOMAIN"
|
|
|
+ echo " turnapi.$NETMAKER_BASE_DOMAIN"
|
|
|
|
|
|
if [ "$INSTALL_TYPE" = "ee" ]; then
|
|
|
echo " prometheus.$NETMAKER_BASE_DOMAIN"
|
|
@@ -444,7 +544,7 @@ set_install_vars() {
|
|
|
echo "-----------------------------------------------------"
|
|
|
|
|
|
if [[ "$DOMAIN_TYPE" == "custom" ]]; then
|
|
|
- echo "before continuing, confirm DNS is configured correctly, with records pointing to $SERVER_PUBLIC_IP"
|
|
|
+ echo "before continuing, confirm DNS is configured correctly, with records pointing to $SERVER_HOST"
|
|
|
confirm
|
|
|
fi
|
|
|
|
|
@@ -471,15 +571,21 @@ set_install_vars() {
|
|
|
|
|
|
unset GET_EMAIL
|
|
|
unset RAND_EMAIL
|
|
|
- RAND_EMAIL="$(echo $RANDOM | md5sum | head -c 16)@email.com"
|
|
|
+ RAND_EMAIL="$(echo $RANDOM | md5sum | head -c 16)@email.com"
|
|
|
+ # suggest the prev email or a random one
|
|
|
+ EMAIL_SUGGESTED=${NM_EMAIL:-$RAND_EMAIL}
|
|
|
if [ -z $AUTO_BUILD ]; then
|
|
|
- read -p "Email Address for Domain Registration (click 'enter' to use $RAND_EMAIL): " GET_EMAIL
|
|
|
+ read -p "Email Address for Domain Registration (click 'enter' to use $EMAIL_SUGGESTED): " GET_EMAIL
|
|
|
fi
|
|
|
if [ -z "$GET_EMAIL" ]; then
|
|
|
- echo "using rand email"
|
|
|
- EMAIL="$RAND_EMAIL"
|
|
|
+ EMAIL="$EMAIL_SUGGESTED"
|
|
|
+ if [ "$EMAIL" = "$NM_EMAIL" ]; then
|
|
|
+ echo "using config email"
|
|
|
+ else
|
|
|
+ echo "using rand email"
|
|
|
+ fi
|
|
|
else
|
|
|
- EMAIL="$GET_EMAIL"
|
|
|
+ EMAIL="$GET_EMAIL"
|
|
|
fi
|
|
|
|
|
|
wait_seconds 1
|
|
@@ -492,40 +598,42 @@ set_install_vars() {
|
|
|
read -p "MQ Username (click 'enter' to use 'netmaker'): " GET_MQ_USERNAME
|
|
|
fi
|
|
|
if [ -z "$GET_MQ_USERNAME" ]; then
|
|
|
- echo "using default username for mq"
|
|
|
- MQ_USERNAME="netmaker"
|
|
|
+ echo "using default username for mq"
|
|
|
+ MQ_USERNAME="netmaker"
|
|
|
else
|
|
|
- MQ_USERNAME="$GET_MQ_USERNAME"
|
|
|
+ MQ_USERNAME="$GET_MQ_USERNAME"
|
|
|
fi
|
|
|
|
|
|
- MQ_PASSWORD=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 30 ; echo '')
|
|
|
+ MQ_PASSWORD=$(
|
|
|
+ tr -dc A-Za-z0-9 </dev/urandom | head -c 30
|
|
|
+ echo ''
|
|
|
+ )
|
|
|
|
|
|
- if [ -z $AUTO_BUILD ]; then
|
|
|
+ if [ -z $AUTO_BUILD ]; then
|
|
|
select domain_option in "Auto Generated Password" "Input Your Own Password"; do
|
|
|
case $REPLY in
|
|
|
1)
|
|
|
- echo "using random password for mq"
|
|
|
- break
|
|
|
- ;;
|
|
|
+ echo "using random password for mq"
|
|
|
+ break
|
|
|
+ ;;
|
|
|
2)
|
|
|
- while true
|
|
|
- do
|
|
|
- echo "Enter your Password For MQ: "
|
|
|
- read -s GET_MQ_PASSWORD
|
|
|
- echo "Enter your password again to confirm: "
|
|
|
- read -s CONFIRM_MQ_PASSWORD
|
|
|
- if [ ${GET_MQ_PASSWORD} != ${CONFIRM_MQ_PASSWORD} ]; then
|
|
|
- echo "wrong password entered, try again..."
|
|
|
- continue
|
|
|
- fi
|
|
|
- MQ_PASSWORD="$GET_MQ_PASSWORD"
|
|
|
- echo "MQ Password Saved Successfully!!"
|
|
|
+ while true; do
|
|
|
+ echo "Enter your Password For MQ: "
|
|
|
+ read -s GET_MQ_PASSWORD
|
|
|
+ echo "Enter your password again to confirm: "
|
|
|
+ read -s CONFIRM_MQ_PASSWORD
|
|
|
+ if [ ${GET_MQ_PASSWORD} != ${CONFIRM_MQ_PASSWORD} ]; then
|
|
|
+ echo "wrong password entered, try again..."
|
|
|
+ continue
|
|
|
+ fi
|
|
|
+ MQ_PASSWORD="$GET_MQ_PASSWORD"
|
|
|
+ echo "MQ Password Saved Successfully!!"
|
|
|
+ break
|
|
|
+ done
|
|
|
break
|
|
|
- done
|
|
|
- break
|
|
|
- ;;
|
|
|
- *) echo "invalid option $REPLY";;
|
|
|
- esac
|
|
|
+ ;;
|
|
|
+ *) echo "invalid option $REPLY" ;;
|
|
|
+ esac
|
|
|
done
|
|
|
fi
|
|
|
|
|
@@ -537,40 +645,42 @@ set_install_vars() {
|
|
|
read -p "TURN Username (click 'enter' to use 'netmaker'): " GET_TURN_USERNAME
|
|
|
fi
|
|
|
if [ -z "$GET_TURN_USERNAME" ]; then
|
|
|
- echo "using default username for mq"
|
|
|
- TURN_USERNAME="netmaker"
|
|
|
+ echo "using default username for TURN"
|
|
|
+ TURN_USERNAME="netmaker"
|
|
|
else
|
|
|
- TURN_USERNAME="$GET_TURN_USERNAME"
|
|
|
+ TURN_USERNAME="$GET_TURN_USERNAME"
|
|
|
fi
|
|
|
|
|
|
- TURN_PASSWORD=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 30 ; echo '')
|
|
|
+ TURN_PASSWORD=$(
|
|
|
+ tr -dc A-Za-z0-9 </dev/urandom | head -c 30
|
|
|
+ echo ''
|
|
|
+ )
|
|
|
|
|
|
- if [ -z $AUTO_BUILD ]; then
|
|
|
+ if [ -z $AUTO_BUILD ]; then
|
|
|
select domain_option in "Auto Generated Password" "Input Your Own Password"; do
|
|
|
case $REPLY in
|
|
|
1)
|
|
|
- echo "using random password for turn"
|
|
|
- break
|
|
|
- ;;
|
|
|
+ echo "using random password for turn"
|
|
|
+ break
|
|
|
+ ;;
|
|
|
2)
|
|
|
- while true
|
|
|
- do
|
|
|
- echo "Enter your Password For TURN: "
|
|
|
- read -s GET_TURN_PASSWORD
|
|
|
- echo "Enter your password again to confirm: "
|
|
|
- read -s CONFIRM_TURN_PASSWORD
|
|
|
- if [ ${GET_TURN_PASSWORD} != ${CONFIRM_TURN_PASSWORD} ]; then
|
|
|
- echo "wrong password entered, try again..."
|
|
|
- continue
|
|
|
- fi
|
|
|
- TURN_PASSWORD="$GET_TURN_PASSWORD"
|
|
|
- echo "TURN Password Saved Successfully!!"
|
|
|
+ while true; do
|
|
|
+ echo "Enter your Password For TURN: "
|
|
|
+ read -s GET_TURN_PASSWORD
|
|
|
+ echo "Enter your password again to confirm: "
|
|
|
+ read -s CONFIRM_TURN_PASSWORD
|
|
|
+ if [ ${GET_TURN_PASSWORD} != ${CONFIRM_TURN_PASSWORD} ]; then
|
|
|
+ echo "wrong password entered, try again..."
|
|
|
+ continue
|
|
|
+ fi
|
|
|
+ TURN_PASSWORD="$GET_TURN_PASSWORD"
|
|
|
+ echo "TURN Password Saved Successfully!!"
|
|
|
+ break
|
|
|
+ done
|
|
|
break
|
|
|
- done
|
|
|
- break
|
|
|
- ;;
|
|
|
- *) echo "invalid option $REPLY";;
|
|
|
- esac
|
|
|
+ ;;
|
|
|
+ *) echo "invalid option $REPLY" ;;
|
|
|
+ esac
|
|
|
done
|
|
|
fi
|
|
|
|
|
@@ -581,7 +691,7 @@ set_install_vars() {
|
|
|
echo "-----------------------------------------------------------------"
|
|
|
echo " domain: $NETMAKER_BASE_DOMAIN"
|
|
|
echo " email: $EMAIL"
|
|
|
- echo " public ip: $SERVER_PUBLIC_IP"
|
|
|
+ echo " public ip: $SERVER_HOST"
|
|
|
if [ "$INSTALL_TYPE" = "ee" ]; then
|
|
|
echo " license: $LICENSE_KEY"
|
|
|
echo " account id: $ACCOUNT_ID"
|
|
@@ -590,8 +700,11 @@ set_install_vars() {
|
|
|
echo "Confirm Settings for Installation"
|
|
|
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
|
|
|
|
|
|
- confirm
|
|
|
+ if [ ! "$BUILD_TYPE" = "local" ]; then
|
|
|
+ IMAGE_TAG="$LATEST"
|
|
|
+ fi
|
|
|
|
|
|
+ confirm
|
|
|
}
|
|
|
|
|
|
# install_netmaker - sets the config files and starts docker-compose
|
|
@@ -605,53 +718,45 @@ install_netmaker() {
|
|
|
|
|
|
echo "Pulling config files..."
|
|
|
|
|
|
+ if [ "$BUILD_TYPE" = "local" ]; then
|
|
|
+ local_install_setup
|
|
|
+ else
|
|
|
+ local BASE_URL="https://raw.githubusercontent.com/gravitl/netmaker/$BUILD_TAG"
|
|
|
|
|
|
- COMPOSE_URL="https://raw.githubusercontent.com/gravitl/netmaker/$BUILD_TAG/compose/docker-compose.yml"
|
|
|
- CADDY_URL="https://raw.githubusercontent.com/gravitl/netmaker/$BUILD_TAG/docker/Caddyfile"
|
|
|
- if [ "$INSTALL_TYPE" = "ee" ]; then
|
|
|
- COMPOSE_URL="https://raw.githubusercontent.com/gravitl/netmaker/$BUILD_TAG/compose/docker-compose.ee.yml"
|
|
|
- CADDY_URL="https://raw.githubusercontent.com/gravitl/netmaker/$BUILD_TAG/docker/Caddyfile-EE"
|
|
|
- fi
|
|
|
- if [ ! "$BUILD_TYPE" = "local" ]; then
|
|
|
- wget -O /root/docker-compose.yml $COMPOSE_URL && wget -O /root/mosquitto.conf https://raw.githubusercontent.com/gravitl/netmaker/$BUILD_TAG/docker/mosquitto.conf && wget -O /root/Caddyfile $CADDY_URL
|
|
|
- wget -O /root/wait.sh https://raw.githubusercontent.com/gravitl/netmaker/$BUILD_TAG/docker/wait.sh
|
|
|
+ local COMPOSE_URL="$BASE_URL/compose/docker-compose.yml"
|
|
|
+ local CADDY_URL="$BASE_URL/docker/Caddyfile"
|
|
|
+ if [ "$INSTALL_TYPE" = "ee" ]; then
|
|
|
+ local COMPOSE_OVERRIDE_URL="$BASE_URL/compose/docker-compose.ee.yml"
|
|
|
+ local CADDY_URL="$BASE_URL/docker/Caddyfile-EE"
|
|
|
+ fi
|
|
|
+ wget -qO "$SCRIPT_DIR"/docker-compose.yml $COMPOSE_URL
|
|
|
+ if test -n "$COMPOSE_OVERRIDE_URL"; then
|
|
|
+ wget -qO "$SCRIPT_DIR"/docker-compose.override.yml $COMPOSE_OVERRIDE_URL
|
|
|
+ fi
|
|
|
+ wget -qO "$SCRIPT_DIR"/Caddyfile "$CADDY_URL"
|
|
|
+ wget -qO "$SCRIPT_DIR"/netmaker.env "$BASE_URL/scripts/netmaker.env"
|
|
|
+ ln -fs "$SCRIPT_DIR/netmaker.env" "$SCRIPT_DIR/.env"
|
|
|
+ wget -qO "$SCRIPT_DIR"/mosquitto.conf "$BASE_URL/docker/mosquitto.conf"
|
|
|
+ wget -qO "$SCRIPT_DIR"/nm-certs.sh "$BASE_URL/scripts/nm-certs.sh"
|
|
|
+ wget -qO "$SCRIPT_DIR"/wait.sh "$BASE_URL/docker/wait.sh"
|
|
|
fi
|
|
|
|
|
|
- chmod +x /root/wait.sh
|
|
|
+ chmod +x "$SCRIPT_DIR"/wait.sh
|
|
|
mkdir -p /etc/netmaker
|
|
|
|
|
|
- echo "Setting docker-compose and Caddyfile..."
|
|
|
+ save_config
|
|
|
|
|
|
- sed -i "s/SERVER_PUBLIC_IP/$SERVER_PUBLIC_IP/g" /root/docker-compose.yml
|
|
|
- sed -i "s/NETMAKER_BASE_DOMAIN/$NETMAKER_BASE_DOMAIN/g" /root/Caddyfile
|
|
|
- sed -i "s/NETMAKER_BASE_DOMAIN/$NETMAKER_BASE_DOMAIN/g" /root/docker-compose.yml
|
|
|
- sed -i "s/REPLACE_MASTER_KEY/$MASTER_KEY/g" /root/docker-compose.yml
|
|
|
- sed -i "s/YOUR_EMAIL/$EMAIL/g" /root/Caddyfile
|
|
|
- sed -i "s/REPLACE_MQ_USERNAME/$MQ_USERNAME/g" /root/docker-compose.yml
|
|
|
- sed -i "s/REPLACE_MQ_PASSWORD/$MQ_PASSWORD/g" /root/docker-compose.yml
|
|
|
- sed -i "s/REPLACE_TURN_USERNAME/$TURN_USERNAME/g" /root/docker-compose.yml
|
|
|
- sed -i "s/REPLACE_TURN_PASSWORD/$TURN_PASSWORD/g" /root/docker-compose.yml
|
|
|
-
|
|
|
- if [ "$INSTALL_TYPE" = "ee" ]; then
|
|
|
- sed -i "s~YOUR_LICENSE_KEY~$LICENSE_KEY~g" /root/docker-compose.yml
|
|
|
- sed -i "s/YOUR_ACCOUNT_ID/$ACCOUNT_ID/g" /root/docker-compose.yml
|
|
|
- fi
|
|
|
-
|
|
|
- if [ "$BUILD_TYPE" = "version" ] && [ "$INSTALL_TYPE" = "ee" ]; then
|
|
|
- sed -i "s/REPLACE_SERVER_IMAGE_TAG/$IMAGE_TAG-ee/g" /root/docker-compose.yml
|
|
|
- else
|
|
|
- sed -i "s/REPLACE_SERVER_IMAGE_TAG/$IMAGE_TAG/g" /root/docker-compose.yml
|
|
|
- fi
|
|
|
-
|
|
|
- if [ "$BUILD_TYPE" = "local" ]; then
|
|
|
- sed -i "s/REPLACE_UI_IMAGE_TAG/$LATEST/g" /root/docker-compose.yml
|
|
|
- else
|
|
|
- sed -i "s/REPLACE_UI_IMAGE_TAG/$IMAGE_TAG/g" /root/docker-compose.yml
|
|
|
- fi
|
|
|
+ # Fetch / update certs using certbot
|
|
|
+ "$SCRIPT_DIR"/nm-certs.sh
|
|
|
|
|
|
echo "Starting containers..."
|
|
|
|
|
|
- docker-compose -f /root/docker-compose.yml up -d
|
|
|
+ # increase the timeouts
|
|
|
+ export DOCKER_CLIENT_TIMEOUT=120
|
|
|
+ export COMPOSE_HTTP_TIMEOUT=120
|
|
|
+
|
|
|
+ # start docker and rebuild containers / networks
|
|
|
+ docker-compose -f "$SCRIPT_DIR"/docker-compose.yml up -d --force-recreate
|
|
|
|
|
|
wait_seconds 2
|
|
|
|
|
@@ -661,25 +766,24 @@ install_netmaker() {
|
|
|
test_connection() {
|
|
|
|
|
|
echo "Testing Caddy setup (please be patient, this may take 1-2 minutes)"
|
|
|
- for i in 1 2 3 4 5 6 7 8
|
|
|
- do
|
|
|
- curlresponse=$(curl -vIs https://api.${NETMAKER_BASE_DOMAIN} 2>&1)
|
|
|
-
|
|
|
- if [[ "$i" == 8 ]]; then
|
|
|
- echo " Caddy is having an issue setting up certificates, please investigate (docker logs caddy)"
|
|
|
- echo " Exiting..."
|
|
|
- exit 1
|
|
|
- elif [[ "$curlresponse" == *"failed to verify the legitimacy of the server"* ]]; then
|
|
|
- echo " Certificates not yet configured, retrying..."
|
|
|
-
|
|
|
- elif [[ "$curlresponse" == *"left intact"* ]]; then
|
|
|
- echo " Certificates ok"
|
|
|
- break
|
|
|
- else
|
|
|
- secs=$(($i*5+10))
|
|
|
- echo " Issue establishing connection...retrying in $secs seconds..."
|
|
|
- fi
|
|
|
- sleep $secs
|
|
|
+ for i in 1 2 3 4 5 6 7 8; do
|
|
|
+ curlresponse=$(curl -vIs https://api.${NETMAKER_BASE_DOMAIN} 2>&1)
|
|
|
+
|
|
|
+ if [[ "$i" == 8 ]]; then
|
|
|
+ echo " Caddy is having an issue setting up certificates, please investigate (docker logs caddy)"
|
|
|
+ echo " Exiting..."
|
|
|
+ exit 1
|
|
|
+ elif [[ "$curlresponse" == *"failed to verify the legitimacy of the server"* ]]; then
|
|
|
+ echo " Certificates not yet configured, retrying..."
|
|
|
+
|
|
|
+ elif [[ "$curlresponse" == *"left intact"* ]]; then
|
|
|
+ echo " Certificates ok"
|
|
|
+ break
|
|
|
+ else
|
|
|
+ secs=$(($i * 5 + 10))
|
|
|
+ echo " Issue establishing connection...retrying in $secs seconds..."
|
|
|
+ fi
|
|
|
+ sleep $secs
|
|
|
done
|
|
|
|
|
|
}
|
|
@@ -689,16 +793,28 @@ setup_mesh() {
|
|
|
|
|
|
wait_seconds 5
|
|
|
|
|
|
- echo "Creating netmaker network (10.101.0.0/16)"
|
|
|
+ local networkCount=$(nmctl network list -o json | jq '. | length')
|
|
|
|
|
|
- nmctl network create --name netmaker --ipv4_addr 10.101.0.0/16
|
|
|
+ # add a network if none present
|
|
|
+ if [ "$networkCount" -lt 1 ]; then
|
|
|
+ echo "Creating netmaker network (10.101.0.0/16)"
|
|
|
|
|
|
- wait_seconds 5
|
|
|
+ # TODO causes "Error Status: 400 Response: {"Code":400,"Message":"could not find any records"}"
|
|
|
+ nmctl network create --name netmaker --ipv4_addr 10.101.0.0/16
|
|
|
+
|
|
|
+ wait_seconds 5
|
|
|
+ fi
|
|
|
|
|
|
- echo "Creating netmaker enrollment key"
|
|
|
+ echo "Obtaining a netmaker enrollment key..."
|
|
|
|
|
|
- tokenJson=$(nmctl enrollment_key create --unlimited --networks netmaker)
|
|
|
- TOKEN=$(jq -r '.token' <<< ${tokenJson})
|
|
|
+ local tokenJson=$(nmctl enrollment_key create --unlimited --networks netmaker)
|
|
|
+ TOKEN=$(jq -r '.token' <<<${tokenJson})
|
|
|
+ if test -z "$TOKEN"; then
|
|
|
+ echo "Error creating an enrollment key"
|
|
|
+ exit 1
|
|
|
+ else
|
|
|
+ echo "Enrollment key ready"
|
|
|
+ fi
|
|
|
|
|
|
wait_seconds 3
|
|
|
|
|
@@ -714,6 +830,32 @@ print_success() {
|
|
|
echo "-----------------------------------------------------------------"
|
|
|
}
|
|
|
|
|
|
+cleanup() {
|
|
|
+ # remove the existing netclient's instance from the existing network
|
|
|
+ if command -v nmctl >/dev/null 2>&1; then
|
|
|
+ local node_id=$(netclient list | jq '.[0].node_id' 2>/dev/null)
|
|
|
+ # trim doublequotes
|
|
|
+ node_id="${node_id//\"/}"
|
|
|
+ if test -n "$node_id"; then
|
|
|
+ echo "De-registering the existing netclient..."
|
|
|
+ nmctl node delete netmaker $node_id >/dev/null 2>&1
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
+ echo "Stopping all containers..."
|
|
|
+ local containers=("mq" "netmaker-ui" "coredns" "turn" "caddy" "netmaker" "netmaker-exporter" "prometheus" "grafana")
|
|
|
+ for name in "${containers[@]}"; do
|
|
|
+ local running=$(docker ps | grep -w "$name")
|
|
|
+ local exists=$(docker ps -a | grep -w "$name")
|
|
|
+ if test -n "$running"; then
|
|
|
+ docker stop "$name" 1>/dev/null
|
|
|
+ fi
|
|
|
+ if test -n "$exists"; then
|
|
|
+ docker rm "$name" 1>/dev/null
|
|
|
+ fi
|
|
|
+ done
|
|
|
+}
|
|
|
+
|
|
|
# 1. print netmaker logo
|
|
|
print_logo
|
|
|
|
|
@@ -728,16 +870,15 @@ install_dependencies
|
|
|
# 4. install yq if necessary
|
|
|
install_yq
|
|
|
|
|
|
-# 5. if running a local build, clone git and build artifacts
|
|
|
-if [ "$BUILD_TYPE" = "local" ]; then
|
|
|
- local_install_setup
|
|
|
-fi
|
|
|
-
|
|
|
set -e
|
|
|
|
|
|
# 6. get user input for variables
|
|
|
set_install_vars
|
|
|
|
|
|
+set +e
|
|
|
+cleanup
|
|
|
+set -e
|
|
|
+
|
|
|
# 7. get and set config files, startup docker-compose
|
|
|
install_netmaker
|
|
|
|