-
Notifications
You must be signed in to change notification settings - Fork 36
/
build-release-example.sh
232 lines (181 loc) · 5.28 KB
/
build-release-example.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
__DIR__=$(
cd "$(dirname "$0")"
pwd
)
__PROJECT__=${__DIR__}
if [ ! -f ${__DIR__}/prepare.php ] ; then
echo 'no found prepare.php'
exit 0
fi
cd ${__PROJECT__}
if [ ! -d ext/swoole/.git ] ; then
git submodule update --init --recursive
fi
set -x
# shellcheck disable=SC2034
OS=$(uname -s)
# shellcheck disable=SC2034
ARCH=$(uname -m)
case $OS in
'Linux')
OS="linux"
;;
'Darwin')
OS="macos"
;;
*)
echo '暂未配置的 OS '
exit 0
;;
esac
IN_DOCKER=0
WITH_PHP_COMPOSER=1
# 配置系统仓库 china mirror
MIRROR='china'
MIRROR=''
# 依赖库默认安装目录
LIBRARY_INSTALL_PREFIX=/usr/local/swoole-cli
while [ $# -gt 0 ]; do
case "$1" in
--mirror)
MIRROR="$2"
;;
--proxy)
export HTTP_PROXY="$2"
export HTTPS_PROXY="$2"
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"
NO_PROXY="${NO_PROXY},::1/128,fe80::/10,fd00::/8,ff00::/8"
NO_PROXY="${NO_PROXY},localhost"
NO_PROXY="${NO_PROXY},.aliyuncs.com,.aliyun.com"
NO_PROXY="${NO_PROXY},.tsinghua.edu.cn,.ustc.edu.cn"
NO_PROXY="${NO_PROXY},.tencent.com"
NO_PROXY="${NO_PROXY},ftpmirror.gnu.org"
NO_PROXY="${NO_PROXY},gitee.com,gitcode.com"
NO_PROXY="${NO_PROXY},.myqcloud.com,.swoole.com"
export NO_PROXY="${NO_PROXY},.npmmirror.com"
;;
--*)
echo "Illegal option $1"
;;
esac
shift $(($# > 0 ? 1 : 0))
done
if [ "$OS" = 'linux' ] ; then
if [ ! "$BASH_VERSION" ] ; then
echo "Please use bash to run this script ($0) " 1>&2
echo "fix : " 1>&2
echo "apk add bash OR sh sapi/quickstart/linux/alpine-init-minimal.sh " 1>&2
exit 1
fi
fi
# 构建环境依赖检查
CMDS_NUMS=0
CMDS=("flex" "pkg-config" "cmake" "re2c" "bison" "curl" "automake" "libtool" "clang" "xz" "zip" "unzip" "autoconf")
CMDS_LEN=${#CMDS[@]}
for cmd in "${CMDS[@]}"; do
if command -v "$cmd" >/dev/null 2>&1; then
# echo "$cmd exists"
((CMDS_NUMS++))
fi
done
if [ "$OS" = 'linux' ] ; then
if [ -f /.dockerenv ]; then
IN_DOCKER=1
if test $CMDS_LEN -ne $CMDS_NUMS ;then
{
if [ "$MIRROR" = 'china' ] ; then
sh sapi/quickstart/linux/alpine-init.sh --mirror china
else
sh sapi/quickstart/linux/alpine-init.sh
fi
}
fi
git config --global --add safe.directory ${__PROJECT__}
else
# docker inspect -f {{.State.Running}} download-box-web-server
if [ "`docker inspect -f {{.State.Running}} swoole-cli-builder`" = "true" ]; then
echo " build container is running "
else
echo " build container no running "
fi
fi
fi
if [ "$OS" = 'macos' ] ; then
if test $CMDS_LEN -ne $CMDS_NUMS ; then
{
if [ "$MIRROR" = 'china' ] ; then
bash sapi/quickstart/macos/macos-init.sh --mirror china
else
bash sapi/quickstart/macos/macos-init.sh
fi
}
fi
OWNER=$(stat -f "%Su" "${LIBRARY_INSTALL_PREFIX}")
CURRENT_USER=$(whoami)
if test "${OWNER}" != "${CURRENT_USER}" ; then
id -u ${CURRENT_USER}
echo "创建目录: ${LIBRARY_INSTALL_PREFIX} ,并修改所属者为: ${CURRENT_USER} "
sudo mkdir -p ${LIBRARY_INSTALL_PREFIX}
CURRENT_USER=$(whoami) && sudo chown -R ${CURRENT_USER}:staff ${LIBRARY_INSTALL_PREFIX}
fi
fi
if [ ! -f "${__PROJECT__}/bin/runtime/php" ] ;then
if [ "$MIRROR" = 'china' ] ; then
bash sapi/quickstart/setup-php-runtime.sh --mirror china
else
bash sapi/quickstart/setup-php-runtime.sh
fi
fi
export PATH="${__PROJECT__}/bin/runtime:$PATH"
alias php="php -d curl.cainfo=${__PROJECT__}/bin/runtime/cacert.pem -d openssl.cafile=${__PROJECT__}/bin/runtime/cacert.pem"
php -v
if [ ${WITH_PHP_COMPOSER} -eq 1 ] ; then
export COMPOSER_ALLOW_SUPERUSER=1
if [ "$MIRROR" = 'china' ]; then
composer config -g repos.packagist composer https://mirrors.tencent.com/composer/
# composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
else
composer config -g repos.packagist composer https://packagist.org
fi
# composer suggests --all
# composer dump-autoload
# composer update --optimize-autoloader
composer install --no-interaction --no-autoloader --no-scripts --prefer-dist -vv --profile # --no-dev
composer dump-autoload --optimize --profile
composer config -g --unset repos.packagist
fi
# 可用配置参数
# --with-swoole-pgsql=1
# --with-global-prefix=/usr/local/swoole-cli
# --with-dependency-graph=1
# --with-web-ui
# --skip-download=1
# --conf-path="./conf.d.extra"
# --without-docker=1
# @macos
# --with-parallel-jobs=8
# --with-download-mirror-url=https://swoole-cli.jingjingxyk.com/
# 定制构建选项
OPTIONS="${OPTIONS} +apcu +ds +xlswriter +ssh2 +uuid "
OPTIONS="${OPTIONS} --with-swoole-pgsql=1"
OPTIONS="${OPTIONS} --with-global-prefix=${LIBRARY_INSTALL_PREFIX}"
# OPTIONS="${OPTIONS} @macos"
if [ ${IN_DOCKER} -eq 1 ] ; then
{
# 容器中
php prepare.php +inotify ${OPTIONS}
} else {
# 容器外
php prepare.php --without-docker=1 ${OPTIONS}
}
fi
if [ "$OS" = 'linux' ] && [ ${IN_DOCKER} -eq 0 ] ; then
echo ' please run in container !'
exit 0
fi
bash make.sh all-library
bash make.sh config
bash make.sh build
bash make.sh archive
exit 0