install.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # Check Root User
  3. # If you want to run as another user, please modify $EUID to be owned by this user
  4. if [[ "$EUID" -ne '0' ]]; then
  5. echo "$(tput setaf 1)Error: You must run this script as root!$(tput sgr0)"
  6. exit 1
  7. fi
  8. # Set the desired GitHub repository
  9. repo="go-gost/gost"
  10. base_url="https://api.github.com/repos/$repo/releases"
  11. # Function to download and install gost
  12. install_gost() {
  13. version=$1
  14. # Detect the operating system
  15. if [[ "$(uname)" == "Linux" ]]; then
  16. os="linux"
  17. elif [[ "$(uname)" == "Darwin" ]]; then
  18. os="darwin"
  19. elif [[ "$(uname)" == "MINGW"* ]]; then
  20. os="windows"
  21. else
  22. echo "Unsupported operating system."
  23. exit 1
  24. fi
  25. # Detect the CPU architecture
  26. arch=$(uname -m)
  27. case $arch in
  28. x86_64)
  29. cpu_arch="amd64"
  30. ;;
  31. armv5*)
  32. cpu_arch="armv5"
  33. ;;
  34. armv6*)
  35. cpu_arch="armv6"
  36. ;;
  37. armv7*)
  38. cpu_arch="armv7"
  39. ;;
  40. aarch64)
  41. cpu_arch="arm64"
  42. ;;
  43. i686)
  44. cpu_arch="386"
  45. ;;
  46. mips64*)
  47. cpu_arch="mips64"
  48. ;;
  49. mips*)
  50. cpu_arch="mips"
  51. ;;
  52. mipsel*)
  53. cpu_arch="mipsle"
  54. ;;
  55. *)
  56. echo "Unsupported CPU architecture."
  57. exit 1
  58. ;;
  59. esac
  60. get_download_url="$base_url/tags/$version"
  61. download_url=$(curl -s "$get_download_url" | grep -Eo "\"browser_download_url\": \".*${os}.*${cpu_arch}.*\"" | awk -F'["]' '{print $4}')
  62. # Download the binary
  63. echo "Downloading gost version $version..."
  64. curl -fsSL -o gost.tar.gz $download_url
  65. # Extract and install the binary
  66. echo "Installing gost..."
  67. tar -xzf gost.tar.gz
  68. chmod +x gost
  69. mv gost /usr/local/bin/gost
  70. echo "gost installation completed!"
  71. }
  72. # Retrieve available versions from GitHub API
  73. versions=$(curl -s "$base_url" | grep -oP 'tag_name": "\K[^"]+')
  74. # Check if --install option provided
  75. if [[ "$1" == "--install" ]]; then
  76. # Install the latest version automatically
  77. latest_version=$(echo "$versions" | head -n 1)
  78. install_gost $latest_version
  79. else
  80. # Display available versions to the user
  81. echo "Available gost versions:"
  82. select version in $versions; do
  83. if [[ -n $version ]]; then
  84. install_gost $version
  85. break
  86. else
  87. echo "Invalid choice! Please select a valid option."
  88. fi
  89. done
  90. fi