install-runtime.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env bash
  2. function download_file() {
  3. downloader="wget"
  4. type wget >/dev/null 2>&1 || { downloader="curl"; }
  5. if [ "$downloader" = "wget" ]; then
  6. _down_prefix="O"
  7. else
  8. _down_prefix="o"
  9. fi
  10. _down_symbol=0
  11. if [ ! -f "$2" ]; then
  12. echo $1
  13. $downloader "$1" -$_down_prefix "$2" >/dev/null 2>&1 && \
  14. echo "完成!" && _down_symbol=1
  15. else
  16. echo "已存在!" && _down_symbol=1
  17. fi
  18. if [ $_down_symbol == 0 ]; then
  19. echo "失败!请检查网络连接!"
  20. rm -rf "$2"
  21. return 1
  22. fi
  23. return 0
  24. }
  25. function test_composer_and_php() {
  26. succ=$("$(pwd)/runtime/composer" -n about | grep Manage)
  27. if [ "$succ" = "" ]; then
  28. echo "Download PHP binary and composer failed!"
  29. return 1
  30. fi
  31. return 0
  32. }
  33. if [ "$(uname -s)" != "Linux" ]; then
  34. echo "Only support Linux!!!"
  35. exit 1
  36. fi
  37. ZM_PHP_VERSION="7.4"
  38. if [ "$ZM_DOWN_PHP_VERSION" != "" ]; then
  39. ZM_PHP_VERSION="$ZM_DOWN_PHP_VERSION"
  40. echo "Using custom PHP version: $ZM_PHP_VERSION"
  41. fi
  42. mkdir "$(pwd)/runtime" >/dev/null 2>&1
  43. if [ ! -f "$(pwd)/runtime/php" ]; then
  44. download_file "https://dl.zhamao.xin/php-bin/down.php?php_ver=$ZM_PHP_VERSION&arch=$(uname -m)" "$(pwd)/runtime/php.tar.gz"
  45. if [ $? -ne 0 ]; then
  46. exit 1
  47. fi
  48. tar -xf "$(pwd)/runtime/php.tar.gz" -C "$(pwd)/runtime/"
  49. fi
  50. if [ ! -f "$(pwd)/runtime/composer" ]; then
  51. download_file "https://mirrors.aliyun.com/composer/composer.phar" "$(pwd)/runtime/composer.phar"
  52. if [ $? -ne 0 ]; then
  53. exit 1
  54. fi
  55. echo '$(dirname $0)/php $(dirname $0)/composer.phar $@' > $(pwd)/runtime/composer
  56. chmod +x $(pwd)/runtime/composer
  57. test_composer_and_php
  58. fi
  59. if [ $? -ne 0 ]; then
  60. exit 1
  61. fi
  62. echo "成功下载!" && \
  63. echo -e "PHP使用:\truntime/php -v" && \
  64. echo -e "Composer使用:\truntime/composer"