-
Notifications
You must be signed in to change notification settings - Fork 33
/
install.sh
executable file
·228 lines (202 loc) · 6.89 KB
/
install.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
#!/bin/bash
. config.sh
. app/nginx_modules.sh
. app/libs.sh
. app/colors.sh
declare -A DOOPT
declare -A OPTIONS_DO=(
['--full']="Install server and clean existing repos"
['--clean']="Clean local files"
['--compile']="Compile from existing directories"
['--deps']="Only dependencies"
['--down']="Only download modules"
)
declare -A OPTIONS_TYPE=(
['--simple']="Simple web server with perfromance modules and standard configuration"
['--simple_ssl']="Simple web server but with extra SSL features"
['--steroids']="Nginx, Lua, Lua Scripts, JWT, Imagemagik, Compression"
)
###############################################
############ >ADVANCED USERS< #############
###############################################
show_yellow "Test" "system variables and paths"
if [ -z ${ROOT+x} ]; then show_red "Error" "ROOT system variable is not set! Check config.sh"; exit 1; fi
if [ -z ${CACHE+x} ]; then show_red "Error" "CACHE system variable is not set! Check config.sh"; exit 1; fi
if [ -z ${BUILD+x} ]; then show_red "Error" "BUILD system variable is not set! Check config.sh"; exit 1; fi
show_green "OK"
# Set: version and dirs
NGINX_VERSION_NO=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# run as root only
if [[ $EUID -ne 0 ]] ; then
run_error "This script must be run with root access\e[49m"
exit 1
fi
[ $# -eq 0 ] && {
show_title " What are we building? "
for i in ${!OPTIONS_DO[*]}
do
echo -e "\e[1;39m[ \e[1;46m${i}\e[49m ] ${OPTIONS_DO[${i}]}\e[0;39m"
done
show_title " How are we building? "
for i in ${!OPTIONS_TYPE[*]}
do
echo -e "\e[1;39m[ \e[1;46m${i}\e[49m ] ${OPTIONS_TYPE[${i}]}\e[0;39m"
done
echo -e "\e[1;39m----------------------------\e[0;39m"
exit 1;
}
DOOPT=${1}
DOTYPE=${2}
[ -d "$ROOT" ] || mkdir -p $ROOT
[ -d "$CACHE" ] || mkdir -p $CACHE
[ -d "$BUILD" ] || mkdir -p $BUILD
# Make everything exectuable
chmod u+x **/*.sh app/**/*.sh app/installers/*.sh app/module_deps/*.sh app/tests/*.sh fix/*.sh
function deps() {
local -A DEPS_INSTALL="build-essential autogen automake autoconf autotools-dev libreadline-dev libncurses5-dev libpcre3 libpcre3-dev libpng-dev zlib1g-dev libssl-dev openssl git perl libtool tar unzip xutils-dev"
# Install Deps
show_yellow "Check" "system dependencies"
##
git --version >/dev/null 2>&1 || {
DEPS_INSTALL="${DEPS_INSTALL} git"
}
python2.7 -V >/dev/null 2>&1 || {
DEPS_INSTALL="${DEPS_INSTALL} python2.7 python2.7-dev"
}
# Install
apt-get install -y $DEPS_INSTALL
# Install: LuaJIT, PCRE, ZLIB, OpenSSL :: mandatory
./fix/aclocal.sh
./app/installers/luajit.sh ${VERSION['luajit']}
./app/installers/pcre.sh ${VERSION['pcre']}
./app/installers/zlib.sh ${VERSION['zlib']}
./app/installers/openssl.sh ${VERSION['openssl']}
}
function download() {
# Download: nginx source
./app/installers/nginx.sh ${VERSION['nginx']} DEBUG
# Clean: modules to fetch them again from cache
rm -rf ${ROOT}nginx_modules/*
# Download: ngnx modules
for i in ${NGINX_INSTALL_MODULES[*]}
do
download_nginx_module $i
done
# Download: ngnx libs
for i in ${NGINX_LUA_MODULES[*]}
do
download_nginx_module $i
done
}
function configure() {
# Unzip: nginx
# Configure || Make: nginx modules
for i in ${NGINX_INSTALL_MODULES[*]}
do
configure_nginx_module $i
done
# Configure || Make: nginx modules
for i in ${NGINX_LUA_MODULES[*]}
do
configure_lua_modules $i
done
}
function compile() {
# Make nginx
make_nginx ${VERSION['nginx']} "$DEFAULT_CONFIGURE_PARAMS $NGINX_CONFIGURE_PARAMS"
# Config the service
post_install_nginx ${NGINX_USE_PATH}
# Create INSTALLED.md file
create_installed_file
}
# Loading functions
show_blue "Loading" "local libraries and preparing scrips"
sleep 1
###############################################################
case $DOTYPE in
"--simple")
show_blue "Install" "${OPTIONS_TYPE[${DOTYPE}]}"
sleep 1
# Define: modules to install
NGINX_INSTALL_MODULES=(
"ngx_headers_more" "ngx_encrypted_session" "ngx_devel_kit" "ngx_mod_zip"
"ngx_xss" "ngx_echo"
)
NGINX_LUA_MODULES=("lua_resty_http" "lua_resty_memcached" "lua_resty_jwt")
# Nginx: params
NGINX_CONFIGURE_PARAMS="--without-http_ssl_module"
;;
"--simple_ssl")
show_blue "Install" "${OPTIONS_TYPE[${DOTYPE}]}"
sleep 1
# Define: modules to install
NGINX_INSTALL_MODULES=(
"ngx_headers_more" "ngx_encrypted_session" "ngx_devel_kit" "ngx_mod_zip"
"ngx_xss" "ngx_echo"
)
NGINX_LUA_MODULES=("lua_resty_http" "lua_resty_memcached" "lua_resty_jwt")
# Nginx: params
NGINX_CONFIGURE_PARAMS="--with-http_ssl_module --with-http_v2_module --with-google_perftools_module"
;;
"--steroids")
show_blue "Compiling" "${OPTIONS_TYPE[${DOTYPE}]}"
sleep 1
# Define: modules to install
NGINX_INSTALL_MODULES=(
"ngx_headers_more" "ngx_encrypted_session" "ngx_devel_kit" "ngx_mod_zip"
"ngx_xss" "ngx_echo" "ngx_clojure" "ngx_memc" "ngx_lua" "ngx_pagespeed" # - not by default "ngx_mongo"
)
NGINX_LUA_MODULES=("lua_resty_http" "lua_resty_memcached" "lua_resty_jwt" "lua_resty_hmac")
NGINX_CONFIGURE_PARAMS="--with-cc-opt=-Wno-error --with-threads --with-file-aio --with-stream_ssl_module --with-http_ssl_module --with-http_v2_module --with-google_perftools_module "
;;
*)
./install.sh
show_red "Error" "$DOTYPE is unknown. Look at option list"
exit 1;
esac
###############################################################
case $DOOPT in
"--full_clean")
show_blue "Install" "${OPTIONS_DO[${DOOPT}]}"
sleep 1
clean
deps
download
configure
compile
;;
"--full")
show_blue "Install" "${OPTIONS_DO[${DOOPT}]}"
sleep 1
deps
download
configure
compile
;;
"--compile")
show_blue "Compiling" "${OPTIONS_DO[${DOOPT}]}"
sleep 1
download
configure
compile
;;
"--deps")
show_blue "Fetching" "${OPTIONS_DO[${DOOPT}]}"
sleep 1
deps
;;
"--down")
show_blue "Downloading" "${OPTIONS_DO[${DOOPT}]}"
sleep 2
download
;;
"--clean")
show_red "Deleting" "${OPTIONS_DO[${DOOPT}]}"
sleep 1
clean
;;
*)
./install.sh
show_red "Error" "$DOOPT is unknown. Look at option list"
exit 1;
esac