Skip to content

Commit 0114b58

Browse files
committed
添加批量下载php-cli 脚本
1 parent e4ebbbe commit 0114b58

3 files changed

Lines changed: 189 additions & 4 deletions

File tree

setup-php-cli-runtime.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ fi
125125

126126
case "$MIRROR" in
127127
china)
128-
APP_DOWNLOAD_URL="https://php-cli.jingjingxyk.com/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.tar.xz"
128+
APP_DOWNLOAD_URL="https://php-cli.jingjingxyk.com/${APP_NAME}/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.tar.xz"
129129
COMPOSER_DOWNLOAD_URL="https://mirrors.tencent.com/composer/composer.phar"
130130
if [ $OS = 'windows' ]; then
131-
APP_DOWNLOAD_URL="https://php-cli.jingjingxyk.com/${APP_NAME}-${APP_VERSION}-cygwin-${ARCH}.zip"
131+
APP_DOWNLOAD_URL="https://php-cli.jingjingxyk.com/${APP_NAME}/${APP_NAME}-${APP_VERSION}-cygwin-${ARCH}.zip"
132132
fi
133133
;;
134134

setup-php-fpm-runtime.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ fi
123123

124124
case "$MIRROR" in
125125
china)
126-
APP_DOWNLOAD_URL="https://php-cli.jingjingxyk.com/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.tar.xz"
126+
APP_DOWNLOAD_URL="https://php-cli.jingjingxyk.com/${APP_NAME}/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.tar.xz"
127127
COMPOSER_DOWNLOAD_URL="https://mirrors.tencent.com/composer/composer.phar"
128128
if [ $OS = 'windows' ]; then
129-
APP_DOWNLOAD_URL="https://php-cli.jingjingxyk.com/${APP_NAME}-${APP_VERSION}-cygwin-${ARCH}.zip"
129+
APP_DOWNLOAD_URL="https://php-cli.jingjingxyk.com/${APP_NAME}/${APP_NAME}-${APP_VERSION}-cygwin-${ARCH}.zip"
130130
fi
131131
;;
132132

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#!/usr/bin/env bash
2+
3+
set -xu
4+
__DIR__=$(
5+
cd "$(dirname "$0")"
6+
pwd
7+
)
8+
__PROJECT__=$(
9+
cd ${__DIR__}/../
10+
pwd
11+
)
12+
13+
cd ${__PROJECT__}
14+
15+
OS=$(uname -s)
16+
ARCH=$(uname -m)
17+
case $OS in
18+
'Linux')
19+
OS="linux"
20+
;;
21+
'Darwin')
22+
OS="macos"
23+
;;
24+
*)
25+
case $OS in
26+
'MSYS_NT'*)
27+
OS="windows"
28+
;;
29+
'MINGW64_NT'*)
30+
OS="windows"
31+
;;
32+
*)
33+
echo '暂未配置的 OS '
34+
exit 0
35+
;;
36+
esac
37+
;;
38+
esac
39+
40+
case $ARCH in
41+
'x86_64')
42+
ARCH="x64"
43+
;;
44+
'aarch64' | 'arm64')
45+
ARCH="arm64"
46+
;;
47+
*)
48+
echo '暂未配置的 ARCH '
49+
exit 0
50+
;;
51+
esac
52+
53+
APP_VERSION='v8.1.34'
54+
APP_NAME='php-cli'
55+
VERSION='v1.15.0'
56+
X_APP_VERSIONS=""
57+
declare -A PHP_VESIONS
58+
PHP_VESIONS[0]="v8.1.34"
59+
PHP_VESIONS[1]="v8.2.30"
60+
PHP_VESIONS[2]="v8.3.30"
61+
PHP_VESIONS[3]="v8.4.19"
62+
PHP_VESIONS[4]="v8.5.4"
63+
64+
while [ $# -gt 0 ]; do
65+
case "$1" in
66+
--proxy)
67+
export HTTP_PROXY="$2"
68+
export HTTPS_PROXY="$2"
69+
NO_PROXY="127.0.0.0/8,10.0.0.0/8,100.64.0.0/10,172.16.0.0/12,192.168.0.0/16"
70+
NO_PROXY="${NO_PROXY},::1/128,fe80::/10,fd00::/8,ff00::/8"
71+
NO_PROXY="${NO_PROXY},localhost"
72+
export NO_PROXY="${NO_PROXY},.myqcloud.com,.swoole.com"
73+
;;
74+
--version)
75+
# 指定发布 TAG
76+
if [ $OS = "macos" ]; then
77+
X_VERSION=$(echo "$2" | grep -E '^v\d\.\d{1,2}\.\d{1,2}$')
78+
elif [ $OS = "linux" ]; then
79+
OS_RELEASE=$(awk -F= '/^ID=/{print $2}' /etc/os-release | tr -d '\n' | tr -d '\"')
80+
if [ "$OS_RELEASE" = 'alpine' ]; then
81+
X_VERSION=$(echo "$2" | egrep -E '^v\d\.\d{1,2}\.\d{1,2}$')
82+
else
83+
X_VERSION=$(echo "$2" | grep -P '^v\d\.\d{1,2}\.\d{1,2}$')
84+
fi
85+
86+
else
87+
X_VERSION=''
88+
fi
89+
90+
if [[ -n $X_VERSION ]]; then
91+
{
92+
VERSION=$X_VERSION
93+
}
94+
else
95+
{
96+
echo '--version vx.x.x error !'
97+
exit 0
98+
}
99+
fi
100+
;;
101+
--app-version)
102+
# 指定 PHP 版本
103+
if [ $OS = "macos" ]; then
104+
X_APP_VERSION=$(echo "$2" | grep -Eo '^v\d\.\d{1,2}\.\d{1,2}')
105+
elif [ $OS = "linux" ]; then
106+
OS_RELEASE=$(awk -F= '/^ID=/{print $2}' /etc/os-release | tr -d '\n' | tr -d '\"')
107+
if [ "$OS_RELEASE" = 'alpine' ]; then
108+
X_APP_VERSION=$(echo "$2" | egrep -Eo '^v\d\.\d{1,2}\.\d{1,2}')
109+
else
110+
X_APP_VERSION=$(echo "$2" | grep -Po '^v\d\.\d{1,2}\.\d{1,2}')
111+
fi
112+
else
113+
X_APP_VERSION=''
114+
fi
115+
116+
if [[ -n $X_APP_VERSION ]]; then
117+
{
118+
APP_VERSION=$X_APP_VERSION
119+
}
120+
else
121+
{
122+
echo '--php-version vx.x.x error !'
123+
exit 0
124+
}
125+
fi
126+
;;
127+
--*)
128+
echo "Illegal option $1"
129+
exit 0
130+
;;
131+
esac
132+
shift $(($# > 0 ? 1 : 0))
133+
done
134+
135+
mkdir -p ${__PROJECT__}/var/artifacts/${APP_NAME}/${VERSION}
136+
# shellcheck disable=SC2164
137+
cd ${__PROJECT__}/var/artifacts/${APP_NAME}/${VERSION}
138+
139+
UNIX_DOWNLOAD_APP_RUNTIME() {
140+
local OS="$1"
141+
local ARCH="$2"
142+
local APP_VERSION="$3"
143+
local APP_DOWNLOAD_URL="https://github.com/swoole/build-static-php/releases/download/${VERSION}/${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}.tar.xz"
144+
local APP_RUNTIME="${APP_NAME}-${APP_VERSION}-${OS}-${ARCH}"
145+
test -f ${APP_RUNTIME}.tar.xz || curl -fSLo ${APP_RUNTIME}.tar.xz ${APP_DOWNLOAD_URL}
146+
}
147+
148+
WINDOWS_DOWNLOAD_APP_RUNTIME() {
149+
local APP_VERSION="$1"
150+
local ARCH="x64"
151+
local APP_DOWNLOAD_URL="https://github.com/swoole/build-static-php/releases/download/${VERSION}/${APP_NAME}-${APP_VERSION}-cygwin-${ARCH}.zip"
152+
153+
local APP_RUNTIME="${APP_NAME}-${APP_VERSION}-cygwin-${ARCH}"
154+
test -f ${APP_RUNTIME}.zip || curl -fSLo ${APP_RUNTIME}.zip ${APP_DOWNLOAD_URL}
155+
156+
APP_DOWNLOAD_URL="https://github.com/swoole/build-static-php/releases/download/${VERSION}/${APP_NAME}-${APP_VERSION}-msys2-${ARCH}.zip"
157+
158+
APP_RUNTIME="${APP_NAME}-${APP_VERSION}-msys2-${ARCH}"
159+
test -f ${APP_RUNTIME}.zip || curl -fSLo ${APP_RUNTIME}.zip ${APP_DOWNLOAD_URL}
160+
}
161+
162+
UNIX_DOWNLOAD() {
163+
local APP_VERSION="$1"
164+
UNIX_DOWNLOAD_APP_RUNTIME "linux" "x64" "${APP_VERSION}"
165+
UNIX_DOWNLOAD_APP_RUNTIME "linux" "arm64" "${APP_VERSION}"
166+
UNIX_DOWNLOAD_APP_RUNTIME "macos" "x64" "${APP_VERSION}"
167+
UNIX_DOWNLOAD_APP_RUNTIME "macos" "arm64" "${APP_VERSION}"
168+
}
169+
170+
DOWNLOAD() {
171+
CACERT_DOWNLOAD_URL="https://curl.se/ca/cacert.pem"
172+
test -f cacert.pem || curl -LSo cacert.pem ${CACERT_DOWNLOAD_URL}
173+
# shellcheck disable=SC2068
174+
for i in ${!PHP_VESIONS[@]}; do
175+
echo -e "${PHP_VESIONS[$i]}"
176+
UNIX_DOWNLOAD "${PHP_VESIONS[$i]}"
177+
WINDOWS_DOWNLOAD_APP_RUNTIME "${PHP_VESIONS[$i]}"
178+
done
179+
180+
}
181+
182+
DOWNLOAD
183+
184+
mkdir -p ${__PROJECT__}/pool/${APP_NAME}
185+
cp -rf ${__PROJECT__}/var/artifacts/${APP_NAME}/${VERSION}/* ${__PROJECT__}/pool/${APP_NAME}

0 commit comments

Comments
 (0)