diff --git a/.gitignore b/.gitignore index 3e7d7e33..0b6f4793 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,8 @@ composer.lock # php cs fixer cache file .php-cs-fixer.cache + +# exclude self-runtime +/bin/* +!/bin/spc +!/bin/setup-runtime diff --git a/bin/setup-runtime b/bin/setup-runtime new file mode 100755 index 00000000..54c89455 --- /dev/null +++ b/bin/setup-runtime @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +# set error-quit, verbose, non-variable-quit +set -eu +# see what system used +__OS__=$(uname -s) +# see what arch used +__ARCH__=$(uname -m) +# format arch name +case $__ARCH__ in +arm64 | aarch64) __ARCH__=arm64 ;; +x86_64|x64) __ARCH__=x64 ;; +*) ;; +esac + +# format uname +case $__OS__ in +Darwin) __OS_FIXED__=macos ;; +Linux) __OS_FIXED__=linux ;; +*) echo "Current OS is not supported" && exit 1 ;; +esac + +# set project dir +__DIR__=$(cd "$(dirname "$0")" && pwd) +__PROJECT__=$(cd ${__DIR__}/../ && pwd) + +# set download dir +__PHP_RUNTIME_URL__="https://github.com/swoole/swoole-src/releases/download/v5.0.1/swoole-cli-v5.0.1-${__OS_FIXED__}-${__ARCH__}.tar.xz" +__COMPOSER_URL__="https://getcomposer.org/download/latest-stable/composer.phar" + +# download static-php binary (currently using swoole-cli temporarily) +test -d ${__PROJECT__}/downloads || mkdir ${__PROJECT__}/downloads +# download static php binary +test -f ${__PROJECT__}/downloads/runtime.tar.xz || curl -#fSL -o ${__PROJECT__}/downloads/runtime.tar.xz "$__PHP_RUNTIME_URL__" +test -f ${__DIR__}/php || { tar -xf ${__PROJECT__}/downloads/runtime.tar.xz -C ${__DIR__}/ && mv ${__DIR__}/swoole-cli ${__DIR__}/php && rm ${__DIR__}/LICENSE ; } # (TODO: temporarily use swoole-cli as php) +chmod +x ${__DIR__}/php +# download composer +test -f ${__DIR__}/composer || curl -#fSL -o ${__DIR__}/composer "$__COMPOSER_URL__" +chmod +x ${__DIR__}/composer +# sanity check for php and composer +${__DIR__}/php -v >/dev/null || { echo "Failed to run php" && exit 1; } +${__DIR__}/php ${__DIR__}/composer --version >/dev/null || { echo "Failed to run composer" && exit 1; } + +echo "Setup runtime OK!" +echo "runtime bin path needs to add manually by command below:" +echo "" +echo " export PATH=\"${__DIR__}:\$PATH\"" +echo "" diff --git a/quickstart/linux/x86_64/prepare-php-runtime-linux-x86_64.sh b/quickstart/linux/x86_64/prepare-php-runtime-linux-x86_64.sh deleted file mode 100644 index 05b1a350..00000000 --- a/quickstart/linux/x86_64/prepare-php-runtime-linux-x86_64.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -set -exu -__DIR__=$( - cd "$(dirname "$0")" - pwd -) -__PROJECT__=$( - cd ${__DIR__}/../../../ - pwd -) -cd ${__PROJECT__} -mkdir -p var -cd ${__PROJECT__}/var - -test -f swoole-cli-v5.0.2-linux-x64.tar.xz || wget -O swoole-cli-v5.0.2-linux-x64.tar.xz https://github.com/swoole/swoole-src/releases/download/v5.0.2/swoole-cli-v5.0.2-linux-x64.tar.xz -test -f swoole-cli-v5.0.2-linux-x64.tar || xz -d -k swoole-cli-v5.0.2-linux-x64.tar.xz -test -f swoole-cli || tar -xvf swoole-cli-v5.0.2-linux-x64.tar -chmod a+x swoole-cli - -test -f composer.phar || wget -O composer.phar https://getcomposer.org/download/2.5.5/composer.phar -chmod a+x composer.phar - -cp -f swoole-cli /usr/local/bin/ -cp -f composer.phar /usr/local/bin/ - -ln -sf /usr/local/bin//swoole-cli /usr/local/bin//php -ln -sf /usr/local/bin//composer.phar /usr/local/bin//composer - diff --git a/quickstart/macOS/x86_64/prepare-php-runtime-macos-x86_64.sh b/quickstart/macOS/x86_64/prepare-php-runtime-macos-x86_64.sh deleted file mode 100644 index df3884fb..00000000 --- a/quickstart/macOS/x86_64/prepare-php-runtime-macos-x86_64.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -set -exu -__DIR__=$( - cd "$(dirname "$0")" - pwd -) -__PROJECT__=$( - cd ${__DIR__}/../../../ - pwd -) -cd ${__PROJECT__} - - -mkdir -p ${__PROJECT__}/bin/runtime -mkdir -p ${__PROJECT__}/var - -cd ${__PROJECT__}/var - - - -test -f swoole-cli-v5.0.1-macos-x64.tar.xz || wget -O swoole-cli-v5.0.1-macos-x64.tar.xz https://github.com/swoole/swoole-src/releases/download/v5.0.1/swoole-cli-v5.0.1-macos-x64.tar.xz -test -f swoole-cli-v5.0.1-macos-x64.tar || xz -d -k swoole-cli-v5.0.1-macos-x64.tar.xz -test -f swoole-cli || tar -xvf swoole-cli-v5.0.1-macos-x64.tar -chmod a+x swoole-cli - -test -f composer.phar || wget -O composer.phar https://getcomposer.org/download/2.5.5/composer.phar -chmod a+x composer.phar - -mv ${__PROJECT__}/var/swoole-cli ${__PROJECT__}/bin/runtime/php -mv ${__PROJECT__}/var/composer.phar ${__PROJECT__}/bin/runtime/composer - -export PATH=${__PROJECT__}/bin/runtime:$PATH \ No newline at end of file