install.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env bash
  2. PROXY=""
  3. RPROXY="https://ghproxy.com/"
  4. MACHINE="amd64"
  5. # Font color
  6. FontBlack="\033[30m";
  7. FontRed="\033[31m";
  8. FontGreen="\033[32m";
  9. FontYellow="\033[33m";
  10. FontBlue="\033[34m";
  11. FontPurple="\033[35m";
  12. FontSkyBlue="\033[36m";
  13. FontWhite="\033[37m";
  14. FontSuffix="\033[0m";
  15. get_latest_version() {
  16. # Get latest release version number
  17. local latest_release
  18. if ! latest_release=$(curl -x "${PROXY}" -sS -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/0xJacky/nginx-ui/releases/latest"); then
  19. echo -e "${FontRed}error: Failed to get release list, please check your network.${FontSuffix}"
  20. exit 1
  21. fi
  22. RELEASE_LATEST="$(echo "$latest_release" | sed 'y/,/\n/' | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')"
  23. if [[ -z "$RELEASE_LATEST" ]]; then
  24. if echo "$latest_release" | grep -q "API rate limit exceeded"; then
  25. echo -e "${FontRed}error: github API rate limit exceeded${FontSuffix}"
  26. else
  27. echo -e "${FontRed}error: Failed to get the latest release version.${FontSuffix}"
  28. echo "Welcome bug report: https://github.com/0xJacky/nginx-ui/issues"
  29. fi
  30. exit 1
  31. fi
  32. RELEASE_LATEST="v${RELEASE_LATEST#v}"
  33. }
  34. download_nginx_ui() {
  35. local download_link
  36. download_link="${RPROXY}https://github.com/0xJacky/nginx-ui/releases/download/$RELEASE_LATEST/nginx-ui-linux-$MACHINE.tar.gz"
  37. echo "Downloading Nginx UI archive: $download_link"
  38. if ! curl -x "${PROXY}" -R -H 'Cache-Control: no-cache' -L -o "$TAR_FILE" "$download_link"; then
  39. echo 'error: Download failed! Please check your network or try again.'
  40. return 1
  41. fi
  42. return 0
  43. }
  44. decompression() {
  45. echo "$1"
  46. if ! tar -zxf "$1" -C "$TMP_DIRECTORY"; then
  47. echo -e "${FontRed}error: Nginx UI decompression failed.${FontSuffix}"
  48. "rm" -r "$TMP_DIRECTORY"
  49. echo "removed: $TMP_DIRECTORY"
  50. exit 1
  51. fi
  52. echo "info: Extract the Nginx UI package to $TMP_DIRECTORY and prepare it for installation."
  53. }
  54. install_bin() {
  55. NAME="nginx-ui"
  56. install -m 755 "${TMP_DIRECTORY}/$NAME" "/app/$NAME"
  57. }
  58. main() {
  59. # Important Variables
  60. TMP_DIRECTORY="$(mktemp -d)"
  61. TAR_FILE="${TMP_DIRECTORY}/nginx-ui-linux-$MACHINE.tar.gz"
  62. get_latest_version
  63. download_nginx_ui
  64. decompression "$TAR_FILE"
  65. install_bin
  66. }
  67. main "$@"