Browse Source

Merge pull request #387 from gravitl/feature_v0.8.5_scripts

Feature v0.8.5 scripts
Alex 3 years ago
parent
commit
ee88a2e3a5

+ 1 - 1
compose/docker-compose.caddy.yml

@@ -3,7 +3,7 @@ version: "3.4"
 services:
   netmaker:
     container_name: netmaker
-    image: gravitl/netmaker:v0.8.4
+    image: gravitl/netmaker:v0.8.5
     volumes:
       - /etc/netclient/config:/etc/netclient/config
       - dnsconfig:/root/config/dnsconfig

+ 2 - 2
compose/docker-compose.nodns.yml

@@ -3,7 +3,7 @@ version: "3.4"
 services:
   netmaker:
     container_name: netmaker
-    image: gravitl/netmaker:v0.8.4
+    image: gravitl/netmaker:v0.8.5
     volumes:
       - /etc/netclient/config:/etc/netclient/config
       - /usr/bin/wg:/usr/bin/wg
@@ -53,4 +53,4 @@ services:
 volumes:
   caddy_data: {}
   caddy_conf: {}
-  sqldata: {}
+  sqldata: {}

+ 1 - 1
compose/docker-compose.yml

@@ -3,7 +3,7 @@ version: "3.4"
 services:
   netmaker:
     container_name: netmaker
-    image: gravitl/netmaker:v0.8.4
+    image: gravitl/netmaker:v0.8.5
     volumes:
       - /etc/netclient/config:/etc/netclient/config
       - dnsconfig:/root/config/dnsconfig

+ 1 - 1
docs/conf.py

@@ -22,7 +22,7 @@ copyright = '2021, Alex Feiszli'
 author = 'Alex Feiszli'
 
 # The full version, including alpha/beta/rc tags
-release = '0.8.4'
+release = '0.8.5'
 
 
 # -- General configuration ---------------------------------------------------

+ 1 - 1
netclient/main.go

@@ -24,7 +24,7 @@ func main() {
 	app := cli.NewApp()
 	app.Name = "Netclient CLI"
 	app.Usage = "Netmaker's netclient agent and CLI. Used to perform interactions with Netmaker server and set local WireGuard config."
-	app.Version = "v0.8.4"
+	app.Version = "v0.8.5"
 
 	hostname, err := os.Hostname()
 	if err != nil {

+ 79 - 22
scripts/netclient-install.sh

@@ -1,11 +1,54 @@
-#!/bin/bash
-set -e
+#!/bin/sh
 
-if [ "$EUID" -ne 0 ]; then
+if [ $(id -u) -ne 0 ]; then
    echo "This script must be run as root" 
    exit 1
 fi
 
+echo "checking dependencies..."
+
+if [ -f /etc/debian_version ]; then
+	install_cmd='apt-get install -y'
+elif [ -f /etc/alpine-release ]; then
+	install_cmd='apk --update add'
+elif [ -f /etc/centos-release ]; then
+	install_cmd='yum install -y'
+elif [ -f /etc/fedora-release ]; then
+	install_cmd='dnf install -y'
+else
+	install_cmd=''
+fi
+
+if [ -z "${install_cmd}" ]; then
+        echo "OS unsupported for automatic dependency install"
+	exit 1
+fi
+dependencies="wireguard resolvectl"
+set -- $dependencies
+while [ -n "$1" ]; do
+    echo $1
+	is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed")
+	if [ "${is_installed}" = "install ok installed" ]; then
+		echo "    " $1 is installed
+	else
+		echo "    " $1 is not installed. Attempting install.
+		${install_cmd} $1
+		sleep 5
+		is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed")
+          	if [ "${is_installed}" = "install ok 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
+
+set -e
+
 [ -z "$KEY" ] && KEY=nokey;
 [ -z "$VERSION" ] && echo "no \$VERSION provided, fallback to latest" && VERSION=latest;
 
@@ -14,28 +57,42 @@ dist=netclient
 echo "OS Version = $(uname)"
 echo "Netclient Version = $VERSION"
 
-if [[ "$(uname)" == "Linux"* ]]; then
-	arch=$(uname -i)
-	echo "CPU ARCH = $arch"
-	if [ "$arch" == 'x86_64' ];
-	then 
-		dist=netclient 
-	fi
-	if [ "$arch" == 'x86_32' ];
-	then
-		dist=netclient-32
-	fi
-	if [ "$arch" == 'armv*' ];
-	then
-		dist=netclient-arm64
-	fi
-elif [[ "$(uname)" == "Darwin"* ]]; then
-        dist=netclient-darwin
-fi
+case $(uname | tr '[:upper:]' '[:lower:]') in
+	linux*)
+		if [ -z "$CPU_ARCH" ]; then
+			CPU_ARCH=$(uname -m)
+		fi
+		case $CPU_ARCH in
+			amd64)
+				dist=netclient
+			;;
+			x86_64)
+				dist=netclient
+			;;
+                        x86_32)
+                                dist=netclient-32
+                        ;;
+ 			arm64)
+				dist=netclient-arm64
+			;;
+			aarch64)
+                                dist=netclient-arm64
+			;;
+			arm*)
+				dist=netclient-$CPU_ARCH
+            		;;
+			*)
+				fatal "$CPU_ARCH : cpu architecture not supported"
+    		esac
+	;;
+	darwin)
+        	dist=netclient-darwin
+	;;
+esac
 
 echo "Binary = $dist"
 
-wget -O netclient https://github.com/gravitl/netmaker/releases/download/$VERSION/netclient
+wget -nv -O netclient https://github.com/gravitl/netmaker/releases/download/$VERSION/$dist
 chmod +x netclient
 sudo ./netclient join -t $KEY
 rm -f netclient

+ 109 - 0
scripts/nm-quick-server.sh

@@ -0,0 +1,109 @@
+#!/bin/bash
+echo "checking for root permissions..."
+
+if [ $EUID -ne 0 ]; then
+   echo "This script must be run as root" 
+   exit 1
+fi
+
+
+echo "checking dependencies..."
+
+declare -A osInfo;
+osInfo[/etc/debian_version]="apt-get install -y"
+osInfo[/etc/alpine-release]="apk --update add"
+osInfo[/etc/centos-release]="yum install -y"
+osInfo[/etc/fedora-release]="dnf install -y"
+
+for f in ${!osInfo[@]}
+do
+    if [[ -f $f ]];then
+        install_cmd=${osInfo[$f]}
+    fi
+done
+
+dependencies=("docker.io" "docker-compose" "wireguard")
+
+for dependency in ${dependencies[@]}; do
+    is_installed=$(dpkg-query -W --showformat='${Status}\n' ${dependency} | grep "install ok installed")
+
+    if [ "${is_installed}" == "install ok installed" ]; then
+        echo "    " ${dependency} is installed
+    else
+            echo "    " ${dependency} is not installed. Attempting install.
+            ${install_cmd} ${dependency}
+            sleep 5
+            is_installed=$(dpkg-query -W --showformat='${Status}\n' ${dependency} | grep "install ok installed")
+            if [ "${is_installed}" == "install ok installed" ]; then
+                echo "    " ${dependency} is installed
+            elif [ -x "$(command -v ${dependency})" ]; then
+                echo "    " ${dependency} is installed
+            else
+                echo "    " failed to install ${dependency}. Exiting.
+                exit 1
+            fi
+    fi
+done
+
+
+
+
+set -e
+
+echo "setting public ip values..."
+
+NETMAKER_BASE_DOMAIN=nm.$(curl -s ifconfig.me | tr . -).nip.io
+COREDNS_IP=$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p')
+SERVER_PUBLIC_IP=$(curl -s ifconfig.me)
+REPLACE_MASTER_KEY=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 30 ; echo '')
+EMAIL="[email protected]"
+
+echo "        domain: $NETMAKER_BASE_DOMAIN"
+echo "    coredns ip: $COREDNS_IP"
+echo "     public ip: $SERVER_PUBLIC_IP"
+echo "    master key: $REPLACE_MASTER_KEY"
+
+
+echo "setting caddyfile..."
+
+
+wget -O /root/Caddyfile https://raw.githubusercontent.com/gravitl/netmaker/master/docker/Caddyfile
+sed -i "s/NETMAKER_BASE_DOMAIN/$NETMAKER_BASE_DOMAIN/g" /root/Caddyfile
+sed -i "s/YOUR_EMAIL/$EMAIL/g" /root/Caddyfile
+
+
+echo "setting docker-compose..."
+
+wget -O /root/docker-compose.yml https://raw.githubusercontent.com/gravitl/netmaker/master/compose/docker-compose.caddy.yml
+sed -i "s/NETMAKER_BASE_DOMAIN/$NETMAKER_BASE_DOMAIN/g" /root/docker-compose.yml
+sed -i "s/SERVER_PUBLIC_IP/$SERVER_PUBLIC_IP/g" /root/docker-compose.yml
+sed -i "s/COREDNS_IP/$COREDNS_IP/g" /root/docker-compose.yml
+sed -i "s/REPLACE_MASTER_KEY/$REPLACE_MASTER_KEY/g" /root/docker-compose.yml
+
+echo "starting containers..."
+
+docker-compose -f /root/docker-compose.yml up -d
+
+cat << "EOF"
+
+
+    ______     ______     ______     __   __   __     ______   __                        
+   /\  ___\   /\  == \   /\  __ \   /\ \ / /  /\ \   /\__  _\ /\ \                       
+   \ \ \__ \  \ \  __<   \ \  __ \  \ \ \'/   \ \ \  \/_/\ \/ \ \ \____                  
+    \ \_____\  \ \_\ \_\  \ \_\ \_\  \ \__|    \ \_\    \ \_\  \ \_____\                 
+     \/_____/   \/_/ /_/   \/_/\/_/   \/_/      \/_/     \/_/   \/_____/                 
+                                                                                         
+ __   __     ______     ______   __    __     ______     __  __     ______     ______    
+/\ "-.\ \   /\  ___\   /\__  _\ /\ "-./  \   /\  __ \   /\ \/ /    /\  ___\   /\  == \   
+\ \ \-.  \  \ \  __\   \/_/\ \/ \ \ \-./\ \  \ \  __ \  \ \  _"-.  \ \  __\   \ \  __<   
+ \ \_\\"\_\  \ \_____\    \ \_\  \ \_\ \ \_\  \ \_\ \_\  \ \_\ \_\  \ \_____\  \ \_\ \_\ 
+  \/_/ \/_/   \/_____/     \/_/   \/_/  \/_/   \/_/\/_/   \/_/\/_/   \/_____/   \/_/ /_/ 
+                                                                                         															 
+
+EOF
+
+echo "             finished installing"
+echo " "
+echo "             visit dashboard.$NETMAKER_BASE_DOMAIN to log in"
+echo " "
+echo " "

+ 57 - 13
scripts/nm-quick.sh

@@ -45,9 +45,6 @@ for dependency in ${dependencies[@]}; do
     fi
 done
 
-
-
-
 set -e
 
 echo "setting public ip values..."
@@ -55,7 +52,7 @@ echo "setting public ip values..."
 NETMAKER_BASE_DOMAIN=nm.$(curl -s ifconfig.me | tr . -).nip.io
 COREDNS_IP=$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p')
 SERVER_PUBLIC_IP=$(curl -s ifconfig.me)
-REPLACE_MASTER_KEY=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 30 ; echo '')
+MASTER_KEY=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 30 ; echo '')
 EMAIL="[email protected]"
 
 arg1=$( echo $1 | awk -F"domain=" '{print $2}')
@@ -85,24 +82,24 @@ fi
 echo "        domain: $NETMAKER_BASE_DOMAIN"
 echo "    coredns ip: $COREDNS_IP"
 echo "     public ip: $SERVER_PUBLIC_IP"
-echo "    master key: $REPLACE_MASTER_KEY"
+echo "    master key: $MASTER_KEY"
 
 
 echo "setting caddyfile..."
 
 
-wget -O /root/Caddyfile https://raw.githubusercontent.com/gravitl/netmaker/master/docker/Caddyfile
+wget -q -O /root/Caddyfile https://raw.githubusercontent.com/gravitl/netmaker/master/docker/Caddyfile
 sed -i "s/NETMAKER_BASE_DOMAIN/$NETMAKER_BASE_DOMAIN/g" /root/Caddyfile
 sed -i "s/YOUR_EMAIL/$EMAIL/g" /root/Caddyfile
 
 
 echo "setting docker-compose..."
 
-wget -O /root/docker-compose.yml https://raw.githubusercontent.com/gravitl/netmaker/master/compose/docker-compose.caddy.yml
+wget -q -O /root/docker-compose.yml https://raw.githubusercontent.com/gravitl/netmaker/master/compose/docker-compose.caddy.yml
 sed -i "s/NETMAKER_BASE_DOMAIN/$NETMAKER_BASE_DOMAIN/g" /root/docker-compose.yml
 sed -i "s/SERVER_PUBLIC_IP/$SERVER_PUBLIC_IP/g" /root/docker-compose.yml
 sed -i "s/COREDNS_IP/$COREDNS_IP/g" /root/docker-compose.yml
-sed -i "s/REPLACE_MASTER_KEY/$REPLACE_MASTER_KEY/g" /root/docker-compose.yml
+sed -i "s/REPLACE_MASTER_KEY/$MASTER_KEY/g" /root/docker-compose.yml
 
 echo "starting containers..."
 
@@ -126,8 +123,55 @@ cat << "EOF"
 
 EOF
 
-echo "             finished installing"
-echo " "
-echo "             visit dashboard.$NETMAKER_BASE_DOMAIN to log in"
-echo " "
-echo " "
+
+echo "visit dashboard.$NETMAKER_BASE_DOMAIN to log in"
+echo""
+sleep 2
+
+if [ "${NETWORK_SETUP}" == "off" ]; then
+	echo "install complete"
+	exit 0
+fi
+
+echo "creating default network (10.101.0.0/16)"
+
+curl -d '{"addressrange":"10.101.0.0/16","netid":"default"}' -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/networks
+
+sleep 2
+
+echo "creating default key"
+
+curlresponse=$(curl -s -d '{"uses":99999,"name":"defaultkey"}' -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/networks/default/keys)
+ACCESS_TOKEN=$(jq -r '.accessstring' <<< ${curlresponse})
+
+sleep 2
+
+echo "configuring netmaker server as ingress gateway"
+
+curlresponse=$(curl -s -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/nodes/default)
+SERVER_ID=$(jq -r '.[0].macaddress' <<< ${curlresponse})
+
+curl -X POST -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/nodes/default/$SERVER_ID/createingress
+
+echo "finished configuring server and network. You can now add clients."
+echo ""
+echo ""
+echo "For Linux and Mac clients, install with the following command:"
+echo "        curl -sfL https://raw.githubusercontent.com/gravitl/netmaker/develop/scripts/netclient-install.sh | sudo KEY=$ACCESS_TOKEN sh -"
+echo ""
+echo ""
+echo "For Windows clients, perform the following from powershell, as administrator:"
+echo "        1. Make sure WireGuardNT is installed - https://download.wireguard.com/windows-client/wireguard-installer.exe"
+echo "        2. Download netclient.exe - wget https://github.com/gravitl/netmaker/releases/download/latest/netclient.exe"
+echo "        3. Install Netclient - powershell.exe .\\netclient.exe join -t $ACCESS_TOKEN"
+echo "        4. Whitelist C:\ProgramData\Netclient in Windows Defender"
+echo ""
+echo ""
+echo "For Android and iOS clients, perform the following steps:"
+echo "        1. Log into UI at dashboard.$NETMAKER_BASE_DOMAIN"
+echo "        2. Navigate to \"EXTERNAL CLIENTS\" tab"
+echo "        3. Select the gateway and create clients"
+echo "        4. Scan the QR Code from WireGuard app in iOS or Android"
+echo ""
+echo ""
+echo "Netmaker setup is now complete. You are ready to begin using Netmaker."