-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild.sh
executable file
·120 lines (89 loc) · 2.69 KB
/
build.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
#!/usr/bin/env bash
set -e
SCRIPT_NAME=$(basename $0)
NGX_WASM_DIR=${NGX_WASM_DIR:-"$(
cd $(dirname $(dirname ${0}))
pwd -P
)"}
if [[ ! -f "${NGX_WASM_DIR}/util/_lib.sh" ]]; then
echo "Unable to source util/_lib.sh" >&2
exit 1
fi
source $NGX_WASM_DIR/util/_lib.sh
###############################################################################
show_help() {
cat << EOF
Build Nginx or OpenResty with ngx_wasmx_module.
Lots of build options are supported through environment variables; consult
_lib.sh or DEVELOPER.md.
Usage:
$SCRIPT_NAME <NGX> [options]
Arguments:
<NGX> Version of Nginx to build (e.g. 1.17.9) or path to an Nginx source
tree (e.g. /tmp/nginx).
Options:
-f, --force Force a fresh build (no incremental build).
-h, --help Print this message and exit.
EOF
}
###############################################################################
while (( "$#" )); do
case $1 in
-h|--help)
show_help
exit 0
;;
-f|--force)
NGX_BUILD_FORCE=1
shift
;;
*)
PARAMS="$PARAMS $1"
shift
;;
esac
done
eval set -- "$PARAMS"
NGX=$1
if [[ -d "$NGX" ]]; then
# <NGX> - source tree
NGX_DIR=$NGX
fi
if [[ -n "$NGX_BUILD_OPENRESTY" ]]; then
OPR=$NGX_BUILD_OPENRESTY
if [[ -d "$OPR" ]]; then
# NGX_BUILD_OPENRESTY - source tree
NGX_DIR=$OPR
fi
elif [[ -z "$NGX" ]]; then
invalid_usage
fi
if [[ -z "$NGX_DIR" ]]; then
if [[ -n "$OPR" ]]; then
# NGX_BUILD_OPENRESTY - version number
OPR_VER=$OPR
if [[ ! "$OPR_VER" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]$ ]]; then
invalid_usage "NGX_BUILD_OPENRESTY value must be of form 'X.Y.Z.a' (e.g. 1.17.8.2)"
fi
download $DIR_DOWNLOAD/openresty-$OPR_VER.tar.gz \
"https://openresty.org/download/openresty-$OPR_VER.tar.gz"
if [[ ! -d "$DIR_DOWNLOAD/openresty-$OPR_VER" ]]; then
tar -xf $DIR_DOWNLOAD/openresty-$OPR_VER.tar.gz -C $DIR_DOWNLOAD
fi
NGX_DIR=$DIR_DOWNLOAD/openresty-$OPR_VER
else
# <NGX> - version number
NGX_VER=$NGX
if [[ ! "$NGX_VER" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
invalid_usage "version must be of form 'X.Y.Z' (e.g. 1.17.9)"
fi
download $DIR_DOWNLOAD/nginx-$NGX_VER.tar.gz \
"https://nginx.org/download/nginx-$NGX_VER.tar.gz"
if [[ ! -d "$DIR_DOWNLOAD/nginx-$NGX_VER" ]]; then
tar -xf $DIR_DOWNLOAD/nginx-$NGX_VER.tar.gz -C $DIR_DOWNLOAD
fi
NGX_DIR=$DIR_DOWNLOAD/nginx-$NGX_VER
fi
fi
build_nginx $NGX_DIR
# vim: ft=sh ts=4 sts=4 sw=4: