forked from baidu/openrasp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-php5.sh
executable file
·76 lines (59 loc) · 1.94 KB
/
build-php5.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
#!/bin/bash
# 中文 PHP 扩展编译说明
# https://rasp.baidu.com/doc/hacking/compile/php.html
cd "$(dirname "$0")"
set -ex
script_base="$(readlink -f $(dirname "$0"))"
# PHP 版本和架构
php_version=$(php -r 'echo PHP_MAJOR_VERSION, ".", PHP_MINOR_VERSION;')
php_arch=$(uname -m)
php_os=
case "$(uname -s)" in
Linux)
php_os=linux
;;
Darwin)
php_os=macos
;;
*)
echo Unsupported OS: $(uname -s)
exit 1
;;
esac
# 下载 libv8
curl https://packages.baidu.com/app/openrasp/libv8-5.9-"$php_os".tar.gz -o /tmp/libv8-5.9.tar.gz
tar -xf /tmp/libv8-5.9.tar.gz -C /tmp/
# 确定编译目录
output_base="$script_base/rasp-php-$(date +%Y-%m-%d)"
output_ext="$output_base/php/${php_os}-php${php_version}-${php_arch}"
# 编译
cd agent/php5
phpize --clean
phpize
if [[ $php_os == "macos" ]]; then
./configure --with-v8=/tmp/libv8-5.9-${php_os}/ --with-gettext=/usr/local/homebrew/opt/gettext -q ${extra_config_opt}
else
curl https://packages.baidu.com/app/openrasp/static-lib.tar.bz2 -o /tmp/static-lib.tar.bz2
tar -xf /tmp/static-lib.tar.bz2 -C /tmp/
./configure --with-v8=/tmp/libv8-5.9-${php_os}/ --with-gettext --enable-openrasp-remote-manager \
--with-curl=/tmp/static-lib --with-openssl=/tmp/static-lib --with-pcre-regex=/tmp/static-lib -q ${extra_config_opt}
fi
make
# 复制扩展
mkdir -p "$output_ext"
cp modules/openrasp.so "$output_ext"/
make distclean
phpize --clean
# 复制其他文件
mkdir -p "$output_base"/{conf,assets,logs,locale,plugins}
cp ../../plugins/official/plugin.js "$output_base"/plugins/official.js
cp ../../rasp-install/php/*.php "$output_base"
cp ../../rasp-install/php/openrasp.toml "$output_base"/conf/openrasp.toml
# 生成并拷贝mo文件
./scripts/locale.sh
mv ./po/locale.tar "$output_base"/locale
cd "$output_base"/locale
tar xvf locale.tar && rm -f locale.tar
# 打包
cd "$script_base"
tar --numeric-owner --group=0 --owner=0 -cjvf "$script_base/rasp-php.tar.bz2" "$(basename "$output_base")"