|
@@ -1,29 +1,29 @@
|
|
|
#!/bin/bash
|
|
|
|
|
|
# make sure current version is 0.17.1 before continuing
|
|
|
-check_version() {(
|
|
|
- CURRENT_VERSION=$(curl -s -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' https://$SERVER_HTTP_HOST/api/server/getserverinfo | jq ' .Version')
|
|
|
+check_version() {
|
|
|
+ IMG_TAG=$(yq -r '.services.netmaker.image' docker-compose.yml)
|
|
|
|
|
|
- if [[ $CURRENT_VERSION == '"v0.17.1"' ]]; then
|
|
|
- echo "version is $CURRENT_VERSION"
|
|
|
+ if [[ "$IMG_TAG" == *"v0.17.1"* ]]; then
|
|
|
+ echo "version is $IMG_TAG"
|
|
|
else
|
|
|
- echo "error, current version is $CURRENT_VERSION"
|
|
|
+ echo "error, current version is $IMG_TAG"
|
|
|
echo "please upgrade to v0.17.1 in order to use the upgrade script"
|
|
|
exit 1
|
|
|
fi
|
|
|
-)}
|
|
|
+}
|
|
|
|
|
|
# wait a number of seconds, print a log
|
|
|
-wait_seconds() {(
|
|
|
+wait_seconds() {
|
|
|
for ((a=1; a <= $1; a++))
|
|
|
do
|
|
|
echo ". . ."
|
|
|
sleep 1
|
|
|
done
|
|
|
-)}
|
|
|
+}
|
|
|
|
|
|
# confirm a choice, or exit script
|
|
|
-confirm() {(
|
|
|
+confirm() {
|
|
|
while true; do
|
|
|
read -p 'Does everything look right? [y/n]: ' yn
|
|
|
case $yn in
|
|
@@ -32,10 +32,10 @@ confirm() {(
|
|
|
* ) echo "Please answer yes or no.";;
|
|
|
esac
|
|
|
done
|
|
|
-)}
|
|
|
+}
|
|
|
|
|
|
# install system dependencies necessary for script to run
|
|
|
-install_dependencies() {(
|
|
|
+install_dependencies() {
|
|
|
OS=$(uname)
|
|
|
|
|
|
if [ -f /etc/debian_version ]; then
|
|
@@ -67,39 +67,13 @@ install_dependencies() {(
|
|
|
|
|
|
${update_cmd}
|
|
|
|
|
|
- while [ -n "$1" ]; do
|
|
|
- is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed")
|
|
|
- if [ "${is_installed}" != "" ]; then
|
|
|
- echo " " $1 is installed
|
|
|
- else
|
|
|
- echo " " $1 is not installed. Attempting install.
|
|
|
- ${install_cmd} $1
|
|
|
- sleep 5
|
|
|
- if [ "${OS}" = "OpenWRT" ] || [ "${OS}" = "TurrisOS" ]; then
|
|
|
- is_installed=$(opkg list-installed $1 | grep $1)
|
|
|
- else
|
|
|
- is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed")
|
|
|
- fi
|
|
|
- if [ "${is_installed}" != "" ]; then
|
|
|
- echo " " $1 is installed
|
|
|
- elif [ -x "$(command -v $1)" ]; then
|
|
|
- echo " " $1 is installed
|
|
|
- else
|
|
|
- echo " " FAILED TO INSTALL $1
|
|
|
- echo " " This may break functionality.
|
|
|
- fi
|
|
|
- fi
|
|
|
- shift
|
|
|
- done
|
|
|
-
|
|
|
echo "-----------------------------------------------------"
|
|
|
- echo "dependency check complete"
|
|
|
+ echo "dependency install complete"
|
|
|
echo "-----------------------------------------------------"
|
|
|
-)}
|
|
|
+}
|
|
|
|
|
|
# retrieve server settings from existing compose file
|
|
|
-collect_server_settings() {(
|
|
|
- unset MASTER_KEY
|
|
|
+collect_server_settings() {
|
|
|
MASTER_KEY=$(yq -r .services.netmaker.environment.MASTER_KEY docker-compose.yml)
|
|
|
echo "-----------------------------------------------------"
|
|
|
echo "Is $MASTER_KEY the correct master key for your Netmaker installation?"
|
|
@@ -116,23 +90,22 @@ collect_server_settings() {(
|
|
|
echo "using $MASTER_KEY"
|
|
|
break
|
|
|
;;
|
|
|
- *) echo "invalid option $REPLY";;
|
|
|
+ *) echo "invalid option $REPLY, choose 1 or 2";;
|
|
|
esac
|
|
|
done
|
|
|
|
|
|
- unset SERVER_HTTP_HOST
|
|
|
SERVER_HTTP_HOST=$(yq -r .services.netmaker.environment.SERVER_HTTP_HOST docker-compose.yml)
|
|
|
echo "-----------------------------------------------------"
|
|
|
- echo "Is $SERVER_HTTP_HOST the correct endpoint for your Netmaker installation?"
|
|
|
+ echo "Is $SERVER_HTTP_HOST the correct api endpoint for your Netmaker installation?"
|
|
|
echo "-----------------------------------------------------"
|
|
|
select endpoint_option in "yes" "no (enter manually)"; do
|
|
|
case $REPLY in
|
|
|
1)
|
|
|
- echo "using $SERVER_HTTP_HOST for endpoint"
|
|
|
+ echo "using $SERVER_HTTP_HOST for api endpoint"
|
|
|
break
|
|
|
;;
|
|
|
2)
|
|
|
- read -p "Enter Endpoint: " endpoint
|
|
|
+ read -p "Enter API Endpoint: " endpoint
|
|
|
SERVER_HTTP_HOST=$endpoint
|
|
|
echo "using $SERVER_HTTP_HOST"
|
|
|
break
|
|
@@ -141,7 +114,6 @@ collect_server_settings() {(
|
|
|
esac
|
|
|
done
|
|
|
|
|
|
- unset BROKER_NAME
|
|
|
BROKER_NAME=$(yq -r .services.netmaker.environment.SERVER_NAME docker-compose.yml)
|
|
|
echo "-----------------------------------------------------"
|
|
|
echo "Is $BROKER_NAME the correct domain for your MQ broker?"
|
|
@@ -162,7 +134,6 @@ collect_server_settings() {(
|
|
|
esac
|
|
|
done
|
|
|
|
|
|
- unset SERVER_NAME
|
|
|
SERVER_NAME=${BROKER_NAME#"broker."}
|
|
|
echo "-----------------------------------------------------"
|
|
|
echo "Is $SERVER_NAME the correct base domain for your installation?"
|
|
@@ -183,22 +154,20 @@ collect_server_settings() {(
|
|
|
esac
|
|
|
done
|
|
|
|
|
|
- unset STUN_NAME
|
|
|
- STUN_NAME="stun."+$SERVER_NAME
|
|
|
+ STUN_NAME="stun.$SERVER_NAME"
|
|
|
echo "-----------------------------------------------------"
|
|
|
echo "Netmaker v0.18.0 requires a new DNS entry for $STUN_NAME."
|
|
|
echo "Please confirm this is added to your DNS provider before continuing"
|
|
|
echo "(note: this is not required if using an nip.io address"
|
|
|
echo "-----------------------------------------------------"
|
|
|
confirm
|
|
|
-)}
|
|
|
+}
|
|
|
|
|
|
# get existing server node configuration
|
|
|
-collect_node_settings() {(
|
|
|
- curl -s -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' https://$SERVER_HTTP_HOST/api/nodes | jq -c '[ .[] | select(.isserver=="yes") ]' > nodejson
|
|
|
+collect_node_settings() {
|
|
|
+ curl -s -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' https://$SERVER_HTTP_HOST/api/nodes | jq -c '[ .[] | select(.isserver=="yes") ]' > nodejson.tmp
|
|
|
NODE_LEN=$(jq length nodejson.tmp)
|
|
|
HAS_INGRESS="no"
|
|
|
- echo $NODE_LEN
|
|
|
if [ "$NODE_LEN" -gt 0 ]; then
|
|
|
echo "===SERVER NODES==="
|
|
|
for i in $(seq 1 $NODE_LEN); do
|
|
@@ -232,10 +201,10 @@ collect_node_settings() {(
|
|
|
echo "WARNING: Your server contains an Ingress Gateway. After upgrading, existing Ext Clients will be lost and must be recreated. Please confirm that you would like to continue."
|
|
|
confirm
|
|
|
fi
|
|
|
-)}
|
|
|
+}
|
|
|
|
|
|
# set compose file with proper values
|
|
|
-set_compose() {(
|
|
|
+set_compose() {
|
|
|
|
|
|
# DEV_TEMP - Temporary instructions for testing
|
|
|
sed -i "s/v0.17.1/testing/g" /root/docker-compose.yml
|
|
@@ -246,18 +215,18 @@ set_compose() {(
|
|
|
yq ".services.netmaker.environment += {\"BROKER_NAME\": \"$BROKER_NAME\"}" -i /root/docker-compose.yml
|
|
|
yq ".services.netmaker.environment += {\"STUN_NAME\": \"$STUN_NAME\"}" -i /root/docker-compose.yml
|
|
|
yq ".services.netmaker.environment += {\"STUN_PORT\": \"3478\"}" -i /root/docker-compose.yml
|
|
|
-)}
|
|
|
+}
|
|
|
|
|
|
-start_containers() {(
|
|
|
+start_containers() {
|
|
|
docker-compose -f /root/docker-compose.yml up -d
|
|
|
-)}
|
|
|
+}
|
|
|
|
|
|
# make sure caddy is working
|
|
|
-test_caddy() {(
|
|
|
+test_caddy() {
|
|
|
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)
|
|
|
+ curlresponse=$(curl -vIs https://${SERVER_HTTP_HOST} 2>&1)
|
|
|
|
|
|
if [[ "$i" == 8 ]]; then
|
|
|
echo " Caddy is having an issue setting up certificates, please investigate (docker logs caddy)"
|
|
@@ -275,9 +244,9 @@ test_caddy() {(
|
|
|
fi
|
|
|
sleep $secs
|
|
|
done
|
|
|
-)}
|
|
|
+}
|
|
|
|
|
|
-setup_netclient() {( set -e
|
|
|
+setup_netclient() {
|
|
|
|
|
|
# DEV_TEMP - Temporary instructions for testing
|
|
|
wget https://fileserver.netmaker.org/testing/netclient
|
|
@@ -319,9 +288,9 @@ if [ -z "${install_cmd}" ]; then
|
|
|
echo "OS unsupported for automatic dependency install"
|
|
|
exit 1
|
|
|
fi
|
|
|
-)}
|
|
|
+}
|
|
|
|
|
|
-setup_nmctl() {(
|
|
|
+setup_nmctl() {
|
|
|
|
|
|
# DEV_TEMP - Temporary instructions for testing
|
|
|
wget https://fileserver.netmaker.org/testing/nmctl
|
|
@@ -329,6 +298,8 @@ setup_nmctl() {(
|
|
|
# RELEASE_REPLACE - Use this once release is ready
|
|
|
# wget https://github.com/gravitl/netmaker/releases/download/v0.17.1/nmctl
|
|
|
chmod +x nmctl
|
|
|
+ echo "using server $SERVER_HTTP_HOST"
|
|
|
+ echo "using master key $MASTER_KEY"
|
|
|
./nmctl context set default --endpoint="https://$SERVER_HTTP_HOST" --master_key="$MASTER_KEY"
|
|
|
./nmctl context use default
|
|
|
RESP=$(./nmctl network list)
|
|
@@ -336,47 +307,47 @@ setup_nmctl() {(
|
|
|
echo "Unable to properly configure NMCTL, exiting..."
|
|
|
exit 1
|
|
|
fi
|
|
|
-)}
|
|
|
-
|
|
|
-join_networks() {(
|
|
|
-NODE_LEN=$(jq length nodejson.tmp)
|
|
|
-HAS_INGRESS="no"
|
|
|
-echo $NODE_LEN
|
|
|
-if [ "$NODE_LEN" -gt 0 ]; then
|
|
|
- for i in $(seq 1 $NODE_LEN); do
|
|
|
- NUM=$(($i-1))
|
|
|
- echo " joining network $(jq ".[$NUM].network" ./nodejson.tmp):"
|
|
|
- KEY_JSON=./nmctl keys create $(jq ".[$NUM].network" ./nodejson.tmp) 1
|
|
|
- KEY=$(echo $KEY_JSON | jq -r .accessstring)
|
|
|
- NAME=$(jq ".[$NUM].name" ./nodejson.tmp)
|
|
|
- netclient join -t $KEY --name=""
|
|
|
- echo " network: $(jq ".[$NUM].network" ./nodejson.tmp)"
|
|
|
- echo " name: $(jq ".[$NUM].name" ./nodejson.tmp)"
|
|
|
- echo " private ipv4: $(jq ".[$NUM].address" ./nodejson.tmp)"
|
|
|
- echo " private ipv6: $(jq ".[$NUM].address6" ./nodejson.tmp)"
|
|
|
- echo " is egress: $(jq ".[$NUM].isegressgateway" ./nodejson.tmp)"
|
|
|
- if [[ $(jq ".[$NUM].isegressgateway" ./nodejson.tmp) == "yes" ]]; then
|
|
|
- echo " egress range: $(jq ".[$NUM].egressgatewayranges" ./nodejson.tmp)"
|
|
|
- fi
|
|
|
-
|
|
|
- HOST_ID=$(yq e .host.id /etc/netclient/netclient.yml)
|
|
|
- # set as a default host
|
|
|
-
|
|
|
- # create an egress if necessary
|
|
|
- # create an ingress if necessary
|
|
|
- echo " is ingress: $(jq ".[$NUM].isingressgateway" ./nodejson.tmp)"
|
|
|
- if [[ $(jq ".[$NUM].isingressgateway" ./nodejson.tmp) == "yes" ]]; then
|
|
|
- HAS_INGRESS="yes"
|
|
|
- fi
|
|
|
- echo " is relay: $(jq ".[$NUM].isrelay" ./nodejson.tmp)"
|
|
|
- echo " is failover: $(jq ".[$NUM].failover" ./nodejson.tmp)"
|
|
|
- echo " ------------"
|
|
|
- done
|
|
|
- echo "=================="
|
|
|
-else
|
|
|
- echo "no networks to join"
|
|
|
-fi
|
|
|
-)}
|
|
|
+}
|
|
|
+
|
|
|
+join_networks() {
|
|
|
+ NODE_LEN=$(jq length nodejson.tmp)
|
|
|
+ HAS_INGRESS="no"
|
|
|
+ echo $NODE_LEN
|
|
|
+ if [ "$NODE_LEN" -gt 0 ]; then
|
|
|
+ for i in $(seq 1 $NODE_LEN); do
|
|
|
+ NUM=$(($i-1))
|
|
|
+ echo " joining network $(jq ".[$NUM].network" ./nodejson.tmp):"
|
|
|
+ KEY_JSON=./nmctl keys create $(jq ".[$NUM].network" ./nodejson.tmp) 1
|
|
|
+ KEY=$(echo $KEY_JSON | jq -r .accessstring)
|
|
|
+ NAME=$(jq ".[$NUM].name" ./nodejson.tmp)
|
|
|
+ netclient join -t $KEY --name=""
|
|
|
+ echo " network: $(jq ".[$NUM].network" ./nodejson.tmp)"
|
|
|
+ echo " name: $(jq ".[$NUM].name" ./nodejson.tmp)"
|
|
|
+ echo " private ipv4: $(jq ".[$NUM].address" ./nodejson.tmp)"
|
|
|
+ echo " private ipv6: $(jq ".[$NUM].address6" ./nodejson.tmp)"
|
|
|
+ echo " is egress: $(jq ".[$NUM].isegressgateway" ./nodejson.tmp)"
|
|
|
+ if [[ $(jq ".[$NUM].isegressgateway" ./nodejson.tmp) == "yes" ]]; then
|
|
|
+ echo " egress range: $(jq ".[$NUM].egressgatewayranges" ./nodejson.tmp)"
|
|
|
+ fi
|
|
|
+
|
|
|
+ HOST_ID=$(yq e .host.id /etc/netclient/netclient.yml)
|
|
|
+ # set as a default host
|
|
|
+
|
|
|
+ # create an egress if necessary
|
|
|
+ # create an ingress if necessary
|
|
|
+ echo " is ingress: $(jq ".[$NUM].isingressgateway" ./nodejson.tmp)"
|
|
|
+ if [[ $(jq ".[$NUM].isingressgateway" ./nodejson.tmp) == "yes" ]]; then
|
|
|
+ HAS_INGRESS="yes"
|
|
|
+ fi
|
|
|
+ echo " is relay: $(jq ".[$NUM].isrelay" ./nodejson.tmp)"
|
|
|
+ echo " is failover: $(jq ".[$NUM].failover" ./nodejson.tmp)"
|
|
|
+ echo " ------------"
|
|
|
+ done
|
|
|
+ echo "=================="
|
|
|
+ else
|
|
|
+ echo "no networks to join"
|
|
|
+ fi
|
|
|
+}
|
|
|
|
|
|
|
|
|
cat << "EOF"
|
|
@@ -387,31 +358,29 @@ The Netmaker Upgrade Script: Upgrading to v0.18.0 so you don't have to!
|
|
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
EOF
|
|
|
|
|
|
+set -e
|
|
|
+
|
|
|
if [ $(id -u) -ne 0 ]; then
|
|
|
echo "This script must be run as root"
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
|
-echo "...confirming version is correct"
|
|
|
-check_version
|
|
|
-
|
|
|
echo "...installing dependencies for script"
|
|
|
install_dependencies
|
|
|
|
|
|
-wait_seconds 3
|
|
|
-
|
|
|
-echo "...setup nmctl"
|
|
|
-setup_nmctl
|
|
|
-
|
|
|
-set -e
|
|
|
+echo "...confirming version is correct"
|
|
|
+check_version
|
|
|
|
|
|
echo "...collecting necessary server settings"
|
|
|
collect_server_settings
|
|
|
|
|
|
+echo "...setup nmctl"
|
|
|
+setup_nmctl
|
|
|
+
|
|
|
echo "...retrieving current server node settings"
|
|
|
collect_node_settings
|
|
|
|
|
|
-# DEV_TEMP
|
|
|
+echo "...backing up docker compose to docker-compose.yml.backup"
|
|
|
cp /root/docker-compose.yml /root/docker-compose.yml.backup
|
|
|
|
|
|
echo "...setting docker-compose values"
|