netclient-install.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/sh
  2. if [ $(id -u) -ne 0 ]; then
  3. echo "This script must be run as root"
  4. exit 1
  5. fi
  6. echo "checking dependencies..."
  7. if [ -f /etc/debian_version ]; then
  8. install_cmd='apt-get install -y'
  9. elif [ -f /etc/alpine-release ]; then
  10. install_cmd='apk --update add'
  11. elif [ -f /etc/centos-release ]; then
  12. install_cmd='yum install -y'
  13. elif [ -f /etc/fedora-release ]; then
  14. install_cmd='dnf install -y'
  15. else
  16. install_cmd=''
  17. fi
  18. if [ -z "${install_cmd}" ]; then
  19. echo "OS unsupported for automatic dependency install"
  20. exit 1
  21. fi
  22. dependencies="wireguard"
  23. set -- $dependencies
  24. while [ -n "$1" ]; do
  25. echo $1
  26. is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed")
  27. if [ "${is_installed}" = "install ok installed" ]; then
  28. echo " " $1 is installed
  29. else
  30. echo " " $1 is not installed. Attempting install.
  31. ${install_cmd} $1
  32. sleep 5
  33. is_installed=$(dpkg-query -W --showformat='${Status}\n' $1 | grep "install ok installed")
  34. if [ "${is_installed}" = "install ok installed" ]; then
  35. echo " " $1 is installed
  36. elif [ -x "$(command -v $1)" ]; then
  37. echo " " $1 is installed
  38. else
  39. echo " " FAILED TO INSTALL $1
  40. echo " " This may break functionality.
  41. fi
  42. fi
  43. shift
  44. done
  45. set -e
  46. [ -z "$KEY" ] && KEY=nokey;
  47. [ -z "$VERSION" ] && echo "no \$VERSION provided, fallback to latest" && VERSION=latest;
  48. [ "latest" != "$VERSION" ] && [ "v" != `echo $VERSION | cut -c1` ] && VERSION="v$VERSION"
  49. [ -z "$NAME" ] && NAME="";
  50. dist=netclient
  51. echo "OS Version = $(uname)"
  52. echo "Netclient Version = $VERSION"
  53. case $(uname | tr '[:upper:]' '[:lower:]') in
  54. linux*)
  55. if [ -z "$CPU_ARCH" ]; then
  56. CPU_ARCH=$(uname -m)
  57. fi
  58. case $CPU_ARCH in
  59. amd64)
  60. dist=netclient
  61. ;;
  62. x86_64)
  63. dist=netclient
  64. ;;
  65. x86_32)
  66. dist=netclient-32
  67. ;;
  68. arm64)
  69. dist=netclient-arm64
  70. ;;
  71. aarch64)
  72. dist=netclient-arm64
  73. ;;
  74. armv7l)
  75. dist=netclient-armv7
  76. ;;
  77. arm*)
  78. dist=netclient-$CPU_ARCH
  79. ;;
  80. *)
  81. fatal "$CPU_ARCH : cpu architecture not supported"
  82. esac
  83. ;;
  84. darwin)
  85. dist=netclient-darwin
  86. ;;
  87. esac
  88. echo "Binary = $dist"
  89. url="https://github.com/gravitl/netmaker/releases/download/$VERSION/$dist"
  90. if curl --output /dev/null --silent --head --fail "$url"; then
  91. echo "Downloading $dist $VERSION"
  92. wget -nv -O netclient $url
  93. else
  94. echo "Downloading $dist latest"
  95. wget -nv -O netclient https://github.com/gravitl/netmaker/releases/download/latest/$dist
  96. fi
  97. chmod +x netclient
  98. sudo ./netclient join -t $KEY --name $NAME
  99. rm -f netclient