Skip to content

Commit c937c8f

Browse files
authored
Update and rename build-runtime.sh to install-runtime.sh
1 parent 7833a5d commit c937c8f

File tree

2 files changed

+58
-226
lines changed

2 files changed

+58
-226
lines changed

build-runtime.sh

Lines changed: 0 additions & 226 deletions
This file was deleted.

install-runtime.sh

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

0 commit comments

Comments
 (0)