nm-quick.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/bin/bash
  2. echo "checking for root permissions..."
  3. if [ $EUID -ne 0 ]; then
  4. echo "This script must be run as root"
  5. exit 1
  6. fi
  7. echo "checking dependencies..."
  8. declare -A osInfo;
  9. osInfo[/etc/debian_version]="apt-get install -y"
  10. osInfo[/etc/alpine-release]="apk --update add"
  11. osInfo[/etc/centos-release]="yum install -y"
  12. osInfo[/etc/fedora-release]="dnf install -y"
  13. for f in ${!osInfo[@]}
  14. do
  15. if [[ -f $f ]];then
  16. install_cmd=${osInfo[$f]}
  17. fi
  18. done
  19. dependencies=("docker.io" "docker-compose" "wireguard")
  20. for dependency in ${dependencies[@]}; do
  21. is_installed=$(dpkg-query -W --showformat='${Status}\n' ${dependency} | grep "install ok installed")
  22. if [ "${is_installed}" == "install ok installed" ]; then
  23. echo " " ${dependency} is installed
  24. else
  25. echo " " ${dependency} is not installed. Attempting install.
  26. ${install_cmd} ${dependency}
  27. sleep 5
  28. is_installed=$(dpkg-query -W --showformat='${Status}\n' ${dependency} | grep "install ok installed")
  29. if [ "${is_installed}" == "install ok installed" ]; then
  30. echo " " ${dependency} is installed
  31. elif [ -x "$(command -v ${dependency})" ]; then
  32. echo " " ${dependency} is installed
  33. else
  34. echo " " failed to install ${dependency}. Exiting.
  35. exit 1
  36. fi
  37. fi
  38. done
  39. set -e
  40. echo "setting public ip values..."
  41. NETMAKER_BASE_DOMAIN=nm.$(curl -s ifconfig.me | tr . -).nip.io
  42. COREDNS_IP=$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p')
  43. SERVER_PUBLIC_IP=$(curl -s ifconfig.me)
  44. MASTER_KEY=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 30 ; echo '')
  45. EMAIL="[email protected]"
  46. arg1=$( echo $1 | awk -F"domain=" '{print $2}')
  47. arg2=$( echo $2 | awk -F"domain=" '{print $2}')
  48. if [ -n "$arg1" ]; then
  49. echo "Parameter NETMAKER_BASE_DOMAIN is $arg1"
  50. NETMAKER_BASE_DOMAIN=$arg1
  51. elif [ -n "$arg2" ]; then
  52. echo "Parameter NETMAKER_BASE_DOMAIN is $arg2"
  53. NETMAKER_BASE_DOMAIN=$arg2
  54. fi
  55. arg1=$( echo $1 | awk -F"email=" '{print $2}')
  56. arg2=$( echo $2 | awk -F"email=" '{print $2}')
  57. if [ -n "$arg1" ]; then
  58. echo "Parameter EMAIL is $arg1"
  59. EMAIL=$arg1
  60. elif [ -n "$arg2" ]; then
  61. echo "Parameter EMAIL is $arg2"
  62. EMAIL=$arg2
  63. fi
  64. echo " domain: $NETMAKER_BASE_DOMAIN"
  65. echo " coredns ip: $COREDNS_IP"
  66. echo " public ip: $SERVER_PUBLIC_IP"
  67. echo " master key: $MASTER_KEY"
  68. echo "setting caddyfile..."
  69. wget -q -O /root/Caddyfile https://raw.githubusercontent.com/gravitl/netmaker/master/docker/Caddyfile
  70. sed -i "s/NETMAKER_BASE_DOMAIN/$NETMAKER_BASE_DOMAIN/g" /root/Caddyfile
  71. sed -i "s/YOUR_EMAIL/$EMAIL/g" /root/Caddyfile
  72. echo "setting docker-compose..."
  73. wget -q -O /root/docker-compose.yml https://raw.githubusercontent.com/gravitl/netmaker/master/compose/docker-compose.caddy.yml
  74. sed -i "s/NETMAKER_BASE_DOMAIN/$NETMAKER_BASE_DOMAIN/g" /root/docker-compose.yml
  75. sed -i "s/SERVER_PUBLIC_IP/$SERVER_PUBLIC_IP/g" /root/docker-compose.yml
  76. sed -i "s/COREDNS_IP/$COREDNS_IP/g" /root/docker-compose.yml
  77. sed -i "s/REPLACE_MASTER_KEY/$MASTER_KEY/g" /root/docker-compose.yml
  78. echo "starting containers..."
  79. docker-compose -f /root/docker-compose.yml up -d
  80. cat << "EOF"
  81. ______ ______ ______ __ __ __ ______ __
  82. /\ ___\ /\ == \ /\ __ \ /\ \ / / /\ \ /\__ _\ /\ \
  83. \ \ \__ \ \ \ __< \ \ __ \ \ \ \'/ \ \ \ \/_/\ \/ \ \ \____
  84. \ \_____\ \ \_\ \_\ \ \_\ \_\ \ \__| \ \_\ \ \_\ \ \_____\
  85. \/_____/ \/_/ /_/ \/_/\/_/ \/_/ \/_/ \/_/ \/_____/
  86. __ __ ______ ______ __ __ ______ __ __ ______ ______
  87. /\ "-.\ \ /\ ___\ /\__ _\ /\ "-./ \ /\ __ \ /\ \/ / /\ ___\ /\ == \
  88. \ \ \-. \ \ \ __\ \/_/\ \/ \ \ \-./\ \ \ \ __ \ \ \ _"-. \ \ __\ \ \ __<
  89. \ \_\\"\_\ \ \_____\ \ \_\ \ \_\ \ \_\ \ \_\ \_\ \ \_\ \_\ \ \_____\ \ \_\ \_\
  90. \/_/ \/_/ \/_____/ \/_/ \/_/ \/_/ \/_/\/_/ \/_/\/_/ \/_____/ \/_/ /_/
  91. EOF
  92. echo "visit dashboard.$NETMAKER_BASE_DOMAIN to log in"
  93. echo""
  94. sleep 2
  95. if [ "${NETWORK_SETUP}" == "off" ]; then
  96. echo "install complete"
  97. exit 0
  98. fi
  99. echo "creating default network (10.101.0.0/16)"
  100. curl -d '{"addressrange":"10.101.0.0/16","netid":"default"}' -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/networks
  101. sleep 2
  102. echo "creating default key"
  103. curlresponse=$(curl -s -d '{"uses":99999,"name":"defaultkey"}' -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/networks/default/keys)
  104. ACCESS_TOKEN=$(jq -r '.accessstring' <<< ${curlresponse})
  105. sleep 2
  106. echo "configuring netmaker server as ingress gateway"
  107. curlresponse=$(curl -s -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/nodes/default)
  108. SERVER_ID=$(jq -r '.[0].macaddress' <<< ${curlresponse})
  109. curl -X POST -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' localhost:8081/api/nodes/default/$SERVER_ID/createingress
  110. echo "finished configuring server and network. You can now add clients."
  111. echo ""
  112. echo ""
  113. echo "For Linux and Mac clients, install with the following command:"
  114. echo " curl -sfL https://raw.githubusercontent.com/gravitl/netmaker/develop/scripts/netclient-install.sh | sudo KEY=$ACCESS_TOKEN sh -"
  115. echo ""
  116. echo ""
  117. echo "For Windows clients, perform the following from powershell, as administrator:"
  118. echo " 1. Make sure WireGuardNT is installed - https://download.wireguard.com/windows-client/wireguard-installer.exe"
  119. echo " 2. Download netclient.exe - wget https://github.com/gravitl/netmaker/releases/download/latest/netclient.exe"
  120. echo " 3. Install Netclient - powershell.exe .\\netclient.exe join -t $ACCESS_TOKEN"
  121. echo " 4. Whitelist C:\ProgramData\Netclient in Windows Defender"
  122. echo ""
  123. echo ""
  124. echo "For Android and iOS clients, perform the following steps:"
  125. echo " 1. Log into UI at dashboard.$NETMAKER_BASE_DOMAIN"
  126. echo " 2. Navigate to \"EXTERNAL CLIENTS\" tab"
  127. echo " 3. Select the gateway and create clients"
  128. echo " 4. Scan the QR Code from WireGuard app in iOS or Android"
  129. echo ""
  130. echo ""
  131. echo "Netmaker setup is now complete. You are ready to begin using Netmaker."