-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_module.sh
executable file
·49 lines (31 loc) · 1.05 KB
/
build_module.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
#!/bin/bash
set -e
NGINX_VERSION=$(nginx -v 2>&1 | sed -n 's/.*\/\([0-9.]*\).*/\1/p')
MODULE_DIR=$1
if [ -z "$1" ]
then
echo "building module failed: no modules provided!"
exit 1
fi
MODULE_NAME=$(grep 'ngx_addon_name' "$MODULE_DIR/config" | sed -n 's/ngx_addon_name=\(.*\)/\1/p')
NGINX_DIR="nginx-$NGINX_VERSION"
NGINX_MODULES_DIR=$(nginx -V 2>&1 | sed -n 's/.*--modules-path=\([a-z\/]*\).*/\1/p')
echo "module name: $MODULE_NAME"
if [ ! -d "$NGINX_DIR" ];
then
wget "https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz"
tar -xzvf "${NGINX_DIR}.tar.gz" && rm "${NGINX_DIR}.tar.gz"
fi
cd "$NGINX_DIR"
./configure --with-compat --add-dynamic-module="../${MODULE_DIR}/" --with-debug
make modules && \
cp "objs/${MODULE_NAME}.so" "$NGINX_MODULES_DIR"
echo "module copied"
echo "Leaving nginx-$NGINX_VERSION"
cd ..
if ! grep -Rq ''"$MODULE_NAME"'.so' /etc/nginx/nginx.conf; then
sed -i '1iload_module modules/'"${MODULE_NAME}"'.so;' /etc/nginx/nginx.conf;
echo "module $MODULE_NAME loaded";
fi
echo "check nginx config"
nginx -t