netclient-install.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. dist=netclient
  50. echo "OS Version = $(uname)"
  51. echo "Netclient Version = $VERSION"
  52. case $(uname | tr '[:upper:]' '[:lower:]') in
  53. linux*)
  54. if [ -z "$CPU_ARCH" ]; then
  55. CPU_ARCH=$(uname -m)
  56. fi
  57. case $CPU_ARCH in
  58. amd64)
  59. dist=netclient
  60. ;;
  61. x86_64)
  62. dist=netclient
  63. ;;
  64. x86_32)
  65. dist=netclient-32
  66. ;;
  67. arm64)
  68. dist=netclient-arm64
  69. ;;
  70. aarch64)
  71. dist=netclient-arm64
  72. ;;
  73. armv7l)
  74. dist=netclient-armv7
  75. ;;
  76. arm*)
  77. dist=netclient-$CPU_ARCH
  78. ;;
  79. *)
  80. fatal "$CPU_ARCH : cpu architecture not supported"
  81. esac
  82. ;;
  83. darwin)
  84. dist=netclient-darwin
  85. ;;
  86. esac
  87. echo "Binary = $dist"
  88. url="https://github.com/gravitl/netmaker/releases/download/$VERSION/$dist"
  89. if curl --output /dev/null --silent --head --fail "$url"; then
  90. echo "Downloading $dist $VERSION"
  91. wget -nv -O netclient $url
  92. else
  93. echo "Downloading $dist latest"
  94. wget -nv -O netclient https://github.com/gravitl/netmaker/releases/download/latest/$dist
  95. fi
  96. chmod +x netclient
  97. sudo ./netclient join -t $KEY
  98. rm -f netclient