netclient-install.sh 2.2 KB

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