-
Notifications
You must be signed in to change notification settings - Fork 20
/
install-nginx.sh
executable file
·77 lines (63 loc) · 1.74 KB
/
install-nginx.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
#!/bin/bash
CONFIGURE_PARAMS="--with-debug --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module"
WORKDIR="nginx"
# is user root? are params passed?
[ $# -eq 0 ] && { echo "Usage: $0 <version>"; exit; }
if [[ $EUID -ne 0 ]] ; then
echo "Error: This script must be run with root access to install nginx."
exit 1
fi
# etc
CPU_CORES=`getconf _NPROCESSORS_ONLN`
NGINX_VERSION="nginx-${1}"
if [ -d "${WORKDIR}" ] ; then
rm -Rf ${WORKDIR}
fi
mkdir -p ${WORKDIR}
# download source
echo -n "Downloading: ${NGINX_VERSION} ... "
wget -q http://nginx.org/download/${NGINX_VERSION}.tar.gz -O ${WORKDIR}/nginx.tar.gz
if [ ! -s "${WORKDIR}/nginx.tar.gz" ] ; then
rm -Rf ${WORKDIR}
echo -e "[\e[0;31mFAILED\e[0m]"
exit 1
fi
echo -e "[\e[0;32mDONE\e[0m]"
# extract
echo -n "Extracting: ${NGINX_VERSION} ... "
tar zxf ${WORKDIR}/nginx.tar.gz -C ${WORKDIR}/
echo -e "[\e[0;32mDONE\e[0m]"
# copy modules/patches
if [ -d "modules" ] ; then
cp -R modules ${WORKDIR}/${NGINX_VERSION}
fi
if [ -d "patches" ] ; then
cp -R patches ${WORKDIR}/${NGINX_VERSION}
fi
# enter directory
cd ${WORKDIR}/${NGINX_VERSION}
# install extra stuff
function install_extra() {
if [ -d ${1} ] ; then
for file in ${1}/* ; do
if [ ${1} == "modules" ] ; then
MODULE=$file
CONFIGURE_PARAMS="${CONFIGURE_PARAMS} --add-module=${MODULE}"
fi
if [ ${1} == "patches" ] ; then
echo "Applying Patch: $(basename $file)"
patch -p1 < $file
fi
done
fi
}
install_extra "modules"
install_extra "patches"
# configure
echo "Configuring... ${CONFIGURE_PARAMS}"
./configure ${CONFIGURE_PARAMS}
echo "Compiling..."
make -j${CPU_CORES}
echo "Installing..."
make install
echo "Finished!"