setup-runtime 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env bash
  2. # set error-quit, verbose, non-variable-quit
  3. set -eu
  4. # see what system used
  5. __OS__=$(uname -s)
  6. # see what arch used
  7. __ARCH__=$(uname -m)
  8. # format arch name
  9. case $__ARCH__ in
  10. arm64 | aarch64) __ARCH__=aarch64 ;;
  11. x86_64|x64) __ARCH__=x86_64 ;;
  12. *) ;;
  13. esac
  14. # format uname
  15. case $__OS__ in
  16. Darwin) __OS_FIXED__=macos ;;
  17. Linux) __OS_FIXED__=linux ;;
  18. *) echo "Current OS is not supported" && exit 1 ;;
  19. esac
  20. # set project dir
  21. __DIR__=$(cd "$(dirname "$0")" && pwd)
  22. __PROJECT__=$(cd ${__DIR__}/../ && pwd)
  23. # set download dir
  24. __PHP_RUNTIME_URL__="https://dl.zhamao.xin/static-php-cli/php-8.2.6-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
  25. __COMPOSER_URL__="https://getcomposer.org/download/latest-stable/composer.phar"
  26. # use china mirror
  27. # bash bin/setup-runtime --mirror china
  28. mirror=''
  29. while [ $# -gt 0 ]; do
  30. case "$1" in
  31. --mirror)
  32. mirror="$2"
  33. shift
  34. ;;
  35. --*)
  36. echo "Illegal option $1"
  37. ;;
  38. esac
  39. shift $(($# > 0 ? 1 : 0))
  40. done
  41. case "$mirror" in
  42. china)
  43. __PHP_RUNTIME_URL__="https://dl.zhamao.xin/static-php-cli/php-8.2.6-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
  44. __COMPOSER_URL__="https://mirrors.aliyun.com/composer/composer.phar"
  45. ;;
  46. esac
  47. test -d ${__PROJECT__}/downloads || mkdir ${__PROJECT__}/downloads
  48. # download static php binary
  49. test -f ${__PROJECT__}/downloads/runtime.tar.gz || { echo "Downloading $__PHP_RUNTIME_URL__ ..." && curl -#fSL -o ${__PROJECT__}/downloads/runtime.tar.gz "$__PHP_RUNTIME_URL__" ; }
  50. test -f ${__DIR__}/php || { tar -xf ${__PROJECT__}/downloads/runtime.tar.gz -C ${__DIR__}/ ; }
  51. chmod +x ${__DIR__}/php
  52. # download composer
  53. test -f ${__DIR__}/composer || curl -#fSL -o ${__DIR__}/composer "$__COMPOSER_URL__"
  54. chmod +x ${__DIR__}/composer
  55. # sanity check for php and composer
  56. ${__DIR__}/php -v >/dev/null || { echo "Failed to run php" && exit 1; }
  57. ${__DIR__}/php ${__DIR__}/composer --version >/dev/null || { echo "Failed to run composer" && exit 1; }
  58. echo "Setup runtime OK!"
  59. echo "runtime bin path needs to add manually by command below:"
  60. echo ""
  61. echo " export PATH=\"${__DIR__}:\$PATH\""
  62. echo ""