#!/usr/bin/env bash # Check Root User # If you want to run as another user, please modify $EUID to be owned by this user if [[ "$EUID" -ne '0' ]]; then echo "$(tput setaf 1)Error: You must run this script as root!$(tput sgr0)" exit 1 fi # Set the desired GitHub repository repo="go-gost/gost" base_url="https://api.github.com/repos/$repo/releases" # Function to download and install gost install_gost() { version=$1 # Detect the operating system if [[ "$(uname)" == "Linux" ]]; then os="linux" elif [[ "$(uname)" == "Darwin" ]]; then os="darwin" elif [[ "$(uname)" == "MINGW"* ]]; then os="windows" else echo "Unsupported operating system." exit 1 fi # Detect the CPU architecture arch=$(uname -m) case $arch in x86_64) cpu_arch="amd64" ;; armv5*) cpu_arch="armv5" ;; armv6*) cpu_arch="armv6" ;; armv7*) cpu_arch="armv7" ;; aarch64|arm64) cpu_arch="arm64" ;; i686) cpu_arch="386" ;; mips64*) cpu_arch="mips64" ;; mips*) cpu_arch="mips" ;; mipsel*) cpu_arch="mipsle" ;; riscv64) cpu_arch="riscv64" ;; *) echo "Unsupported CPU architecture." exit 1 ;; esac get_download_url="$base_url/tags/$version" download_url=$(curl -s "$get_download_url" | awk -F'"' -v re=".*${os}.*${cpu_arch}.*" '/"browser_download_url":/ && $4 ~ re { print $4 }' | head -n 1) # Download and install the binary install_path="/usr/local/bin" echo "Downloading and installing gost version $version..." curl -fsSL "$download_url" | tar -xzC "$install_path" gost chmod +x "$install_path/gost" # Remove binary from macOS quarantine when installing for first time [[ "$os" == "darwin" ]] && { xattr -d com.apple.quarantine "$install_path/gost" 2>&-; } echo "gost installation completed!" } # Retrieve available versions from GitHub API versions=$(curl -s "$base_url" | awk -F'"' '/"tag_name":/ {print $4}') # Check if --install option provided if [[ "$1" == "--install" ]]; then # Install the latest version automatically latest_version=$(echo "$versions" | head -n 1) install_gost $latest_version else # Display available versions to the user echo "Available gost versions:" select version in $versions; do if [[ -n $version ]]; then install_gost $version break else echo "Invalid choice! Please select a valid option." fi done fi