-
Notifications
You must be signed in to change notification settings - Fork 1
/
init
executable file
·329 lines (301 loc) · 9.07 KB
/
init
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/bin/bash
BUILDDIR=`pwd`/build
INSTALLDIR=`pwd`/installed
SOURCEDIR=`pwd`/dependencies
OS_NAME=`uname -s`
case ${OS_NAME} in
Linux )
NCPUS=`grep 'processor' /proc/cpuinfo | wc -l`
;;
Darwin )
NCPUS=`sysctl -n hw.ncpu`
;;
* )
echo "Unsupported OS name ${OS_NAME}"
exit -1
esac
function print_help() {
echo "Initialize the Plumber Isolated Environment"
echo "--real[=<prefix>] Use the real environment, if prefix is missing use Plumber at /"
echo "--javascript-prebuild[=<tarball>] Enable Javascript servlet support with the prebuild tarball"
echo "--javascript[=<prefix>] Enable Javascript servlet support"
echo "--test Run test cases before we start the environment"
echo "--recompile Recompile the code"
echo "--reconfigure Reconfigure the Plumber source code"
echo "--reinstall[=<prefix>] Reinstall the Plumber environment, if prefix specified, use the given prefix"
echo "--remove Remove all the generated file"
echo "--commit=<tag> Use the given version number of Plumber"
echo "--sync Sync the Plumber code"
echo "--shell=<shell-command> Instead of using zsh, use the given shell"
echo "--cc=<C-compiler> Use the given C compiler rather than GCC"
echo "--cxx=<C++-compiler> Use the given C++ compiler rather than G++"
echo "--cflags=<flags> Append C Compiler Flags"
echo "--cxxflags=<flags> Append C++ Compiler Flags"
echo "--ldflags=<flags> Append Linker Flags"
echo "--log=<log-level> Use the given log level for Plumber logging system"
echo "--optimization=<level> Set the level of optimization (from 0 to 4)"
echo "--gproftools Compile code with Google profiling tools"
echo "--help Show this help message"
}
function argv() {
if [ $# = 2 ] && [ x"$1" = "x--string" ]; then
echo $2 | sed 's/^[^=]*=\(.*\)$/\1/g'
else
realpath $(eval "echo $(echo $1 | sed 's/^[^=]*=\(.*\)$/\1/g')")
fi
}
function strip() {
echo $1 | sed 's/^[\t ]*//g' | sed 's/[\t ]*$//g'
}
function need() {
case ${1} in
reconfigure )
reconfigure="yes"
recompile="yes"
reinstall="yes"
;;
recompile )
recompile="yes"
reinstall="yes"
;;
reinstall )
reinstall="yes"
;;
esac
}
CC=gcc
CXX=g++
LOG=3
shell=zsh
case ${OS_NAME} in
Linux )
javascript="yes"
js_prebuilt="http://plumberserver.com/downloads/plumberv8-prebuild.6.3.0.x64.release.tar.gz"
;;
Darwin)
javascript="yes"
js_prebuilt="http://plumberserver.com/downloads/plumberv8-prebuild.latest.x64.release.darwin.tar.gz"
;;
*)
javascript="no"
esac
[ ! -e ${BUILDDIR}/plumber/Makefile ] && need reconfigure
[ ! -e ${BUILDDIR}/plumber/bin/pscript ] && need recompile
[ ! -e ${INSTALLDIR}/bin/pscript ] && need reinstall
function parse_options() {
for arg in $@
do
case ${arg} in
--real )
realenv="/";;
--real=* )
realenv="$(argv ${arg})";;
--no-javascript-prebuild )
javascript="no"
need reconfigure;;
--javascript-prebuild=* )
javascript="yes"
js_prebuilt="$(argv --string ${arg})"
need reconfigure
;;
--javascript )
javascript="yes"
need reconfigure;;
--javascript=* )
javascript="external"
v8prefix="$(argv --string ${arg})"
need reconfigure;;
--reconfigure )
cmake_param=""
need reconfigure;;
--reconfigure=* )
cmake_param="$(argv --string ${arg})"
need reconfigure;;
--recompile )
need recompile;;
--reinstall )
need reinstall;;
--reinstall=* )
INSTALLDIR="$(argv ${arg})"
need reconfigure;;
--commit=* )
commit="$(argv --string ${arg})"
need recompilel;;
--test )
runtest="yes";;
--remove )
remove="yes";;
--shell=* )
shell="$(argv --string ${arg})";;
--gproftools )
LIBS=$(strip "${LIBS} -lprofiler")
CFLAGS=$(strip "${CFLAGS} -DGPROFTOOLS")
need reconfigure;;
--sync )
sync="yes"
need recompile;;
--cc=* )
CC="$(argv --string ${arg})"
need reconfigure;;
--cxx=* )
CXX="$(argv --string ${arg})"
need reconfigure;;
--cflags=* )
CFLAGS="$(strip "${CFLAGS} $(argv --string ${arg})")"
need reconfigure;;
--cxxflags=* )
CXXFLAGS="$(strip "${CXXFLAGS} $(argv --string ${arg})")"
need reconfigure;;
--ldflags=* )
LIBS="$(strip "${LIBS} $(argv --string ${arg})")"
need reconfigure;;
--log=* )
LOG="$(argv --string ${arg})"
need reconfigure;;
--optimization=[0-5] )
OPT="$(argv --string ${arg})"
need reconfigure;;
--help )
print_help
exit 0;;
* )
echo "Invalid argument ${arg}"
print_help
exit 1
esac
done
}
parse_options $@
function realenvinfo() {
echo -ne '\033[33m'
echo ""
echo "You are entering real plumber environment at ${realenv}"
echo " To quit the environment, please exit current shell"
echo ""
echo " Plumber Version `pscript --version 2>/dev/stdout | grep 'Libplumber' | awk -F': ' '{print $2}'`"
echo " Plumber Service Script Interpreter pscript at `which pscript`"
echo " Plumber Servlet Testbed pstest at `which pstest`"
echo " Protocol Management Tool protoman at `which protoman`"
echo ""
echo -ne '\033[0m'
}
if [ ! -z "${realenv}" ]
then
LD_LIBRARY_PATH=${realenv}/lib PATH=${realenv}/bin:${PATH} ENVROOT=${realenv} REPOROOT=`pwd` realenvinfo
LD_LIBRARY_PATH=${realenv}/lib PATH=${realenv}/bin:${PATH} ENVROOT=${realenv} REPOROOT=`pwd` ${shell} || exit 1
exit 0
fi
if [ ! -z "${ENVROOT}" ]
then
echo "You are already in the Isolated Plumber Environment!"
exit 1
fi
if [ "x${remove}" = "xyes" ]
then
rm -rf build installed
exit 0
fi
if [ "x${javascript}" = "xyes" ]
then
JS_PARAM="-DPLUMBER_V8_PREFIX=${INSTALLDIR} -Dbuild_language_javascript=yes"
fi
if [ "x${javascript}" = "xexternal" ]
then
JS_PARAM="-DPLUMBER_V8_PREFIX=${v8prefix} -Dbuild_language_javascript=yes"
fi
if [ ! -z "${commit}" ]
then
pushd ${SOURCEDIR}/plumber
git checkout ${commit} || exit 1
popd
fi
if [ "x${sync}" = "xyes" ]
then
pushd ${SOURCEDIR}/plumber
git pull || exit 1
popd
fi
if [ "x${reconfigure}" = "xyes" ]
then
if [ "x${javascript}" = "xyes" ]
then
if [ "x${js_prebuilt}" = "x" ]
then
mkdir -p ${BUILDDIR}/plumberv8
${SOURCEDIR}/plumberv8/buildv8 --configure-name=x64.release --output=${BUILDDIR}/plumberv8/ --prefix=${INSTALLDIR} --install || exit 1
else
if [ ! -e ${INSTALLDIR}/bin/plumber-v8-config ]
then
${SOURCEDIR}/plumberv8/buildv8 --install-only=${js_prebuilt} --prefix=${INSTALLDIR} || exit 1
fi
fi
fi
mkdir -p ${BUILDDIR}/plumber || exit 1
pushd ${BUILDDIR}/plumber
export O=${OPT}
export L=${LOG}
export CC=${CC}
export CXX=${CXX}
export LIBS=${LIBS}
export CFLAGS=${CFLAGS}
echo "-DCMAKE_INSTALL_PREFIX=${INSTALLDIR}
${cmake_param}
${JS_PARAM}
${SOURCEDIR}/plumber" | xargs cmake
popd
fi
if [ "x${recompile}" = "xyes" ]
then
pushd ${BUILDDIR}/plumber
make -j ${NCPUS}|| exit 1
popd
fi
if [ "x${runtest}" = "xyes" ]
then
pushd ${BUILDDIR}/plumber
make test || exit 1
popd
fi
if [ "x${reinstall}" = "xyes" ]
then
pushd ${BUILDDIR}/plumber
make -j ${NCPUS} install || exit 1
popd
if [ ${OS_NAME} = "Darwin" ]
then
DYLD_LIBRARY_PATH=${INSTALLDIR}/lib ${INSTALLDIR}/bin/protoman --update --yes prototypes/*.ptype || exit 1
DYLD_LIBRARY_PATH=${INSTALLDIR}/lib sh ${BUILDDIR}/plumber/install-prototype.sh || exit 1
else
LD_LIBRARY_PATH=${INSTALLDIR}/lib ${INSTALLDIR}/bin/protoman --update --yes prototypes/*.ptype || exit 1
LD_LIBRARY_PATH=${INSTALLDIR}/lib sh ${BUILDDIR}/plumber/install-prototype.sh || exit 1
fi
fi
function show_info() {
echo -ne '\033[33m'
echo ""
echo "You are enetring Isolated Plumber Envrionment"
echo ""
echo " To check if you are in the Plumber Isolated Environment, use command whereami"
echo " To quit the environment, please exit current shell"
echo ""
echo " Plumber Version `pscript --version 2>/dev/stdout | grep 'Libplumber' | awk -F': ' '{print $2}'`"
echo " Plumber Service Script Interpreter pscript at `which pscript`"
echo " Plumber Servlet Testbed pstest at `which pstest`"
echo " Protocol Management Tool protoman at `which protoman`"
echo ""
echo -ne '\033[0m'
}
cat > ${INSTALLDIR}/bin/whereami <<EOF
#!/bin/sh
echo "You are under Plumber Isolated Environment at $(pwd), to leave the environment, please exit current shell."
EOF
chmod +x ${INSTALLDIR}/bin/whereami
mkdir -p ${INSTALLDIR}/var/run/plumber
if [ ${OS_NAME} = "Darwin" ]
then
DYLD_LIBRARY_PATH=${INSTALLDIR}/lib PATH=${INSTALLDIR}/bin:${PATH} ENVROOT=${INSTALLDIR} REPOROOT=`pwd` show_info
DYLD_LIBRARY_PATH=${INSTALLDIR}/lib PATH=${INSTALLDIR}/bin:${PATH} ENVROOT=${INSTALLDIR} REPOROOT=`pwd` ${shell} || exit 1
else
LD_LIBRARY_PATH=${INSTALLDIR}/lib PATH=${INSTALLDIR}/bin:${PATH} ENVROOT=${INSTALLDIR} REPOROOT=`pwd` show_info
LD_LIBRARY_PATH=${INSTALLDIR}/lib PATH=${INSTALLDIR}/bin:${PATH} ENVROOT=${INSTALLDIR} REPOROOT=`pwd` ${shell} || exit 1
fi