download.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. OS="$(go env GOOS)"
  3. ARCH="$(go env GOARCH)"
  4. if [ "${TARGET_OS}" ]; then
  5. OS="${TARGET_OS}"
  6. fi
  7. if [ "${TARGET_ARCH}" ]; then
  8. ARCH="${TARGET_ARCH}"
  9. fi
  10. # Determine the latest version by version number ignoring alpha, beta, and rc versions.
  11. if [ "${FRP_VERSION}" = "" ] ; then
  12. FRP_VERSION="$(curl -sL https://github.com/fatedier/frp/releases | \
  13. grep -o 'releases/tag/v[0-9]*.[0-9]*.[0-9]*"' | sort -V | \
  14. tail -1 | awk -F'/' '{ print $3}')"
  15. FRP_VERSION="${FRP_VERSION%?}"
  16. FRP_VERSION="${FRP_VERSION#?}"
  17. fi
  18. if [ "${FRP_VERSION}" = "" ] ; then
  19. printf "Unable to get latest frp version. Set FRP_VERSION env var and re-run. For example: export FRP_VERSION=1.0.0"
  20. exit 1;
  21. fi
  22. SUFFIX=".tar.gz"
  23. if [ "${OS}" = "windows" ] ; then
  24. SUFFIX=".zip"
  25. fi
  26. NAME="frp_${FRP_VERSION}_${OS}_${ARCH}${SUFFIX}"
  27. DIR_NAME="frp_${FRP_VERSION}_${OS}_${ARCH}"
  28. URL="https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/${NAME}"
  29. download_and_extract() {
  30. printf "Downloading %s from %s ...\n" "$NAME" "${URL}"
  31. if ! curl -o /dev/null -sIf "${URL}"; then
  32. printf "\n%s is not found, please specify a valid FRP_VERSION\n" "${URL}"
  33. exit 1
  34. fi
  35. curl -fsLO "${URL}"
  36. filename=$NAME
  37. if [ "${OS}" = "windows" ]; then
  38. unzip "${filename}"
  39. else
  40. tar -xzf "${filename}"
  41. fi
  42. rm "${filename}"
  43. if [ "${TARGET_DIRNAME}" ]; then
  44. mv "${DIR_NAME}" "${TARGET_DIRNAME}"
  45. DIR_NAME="${TARGET_DIRNAME}"
  46. fi
  47. }
  48. download_and_extract
  49. printf ""
  50. printf "\nfrp %s Download Complete!\n" "$FRP_VERSION"
  51. printf "\n"
  52. printf "frp has been successfully downloaded into the %s folder on your system.\n" "$DIR_NAME"
  53. printf "\n"