fix outgoing QOS prios
[tomato.git] / release / src / router / snmp / dist / nsb-functions
blob1feafa23661a3bc4db8c64cf42d1f8d5ca64529e
1 #!/bin/bash
2 #----------------------------------------------------------------------
3 # $Id: nsb-functions,v 1.1.2.1 2004/06/20 21:54:35 nikki Exp $
4 # Author: Robert Story <rstory@freesnmp.com>
6 #----------------------------------------------------------------------
8 # Utility vars
10 NSB_BUILD_DIR=${NSB_BUILD_DIR:=""}
11 NSB_SRC_DIR=${NSB_SRC_DIR:=""}
12 NSB_INSTALL_DIR=${NSB_INSTALL_DIR:=""}
13 NSB_QUIET=0
14 NSB_PROMPT=0
15 NSB_CLEAN=1
16 NSB_CONFIG_ALL=0
17 NSB_SKIP_CONFIG=0
18 NSB_SKIP_BUILD=0
19 NSB_SKIP_TEST=0
20 NSB_SKIP_INSTALL=0
21 NSB_DIST_TRANSPORTS="UDP TCP Unix"
22 NSB_EXTRA_TRANSPORTS="Callback UDPIPv6 TCPIPv6 IPX"
23 NSB_DIST_MODULES="host disman/event-mib smux"
24 NSB_EXTRA_MODULES="examples examples/example testhandler smux Rmon disman/event-mib"
25 NSB_EXTRA_CONFIG=${NSB_EXTRA_CONFIG:=""}
26 NSB_VIEW=cat
27 NSB_SCP=`which scp`
28 NSB_PERL=
29 #NSB_PERL=--enable-embedded-perl
30 NSB_FLOW=
31 DATE=`date +%y%m%d_%H%M`
33 #----------------------------------------------------------------------
35 # Utility functions
38 nsb-abort()
40 echo
41 echo "ABORTING: $@" >&2
42 exit 255
45 nsb-info()
47 if [ $NSB_QUIET -ne 1 ]; then
48 echo $@
52 nsb-prompt()
54 if [ "x$1" = "x-f" ]; then
55 shift 1
56 tmp_nsb_prompt=1
57 else
58 tmp_nsb_prompt=$NSB_PROMPT
60 if [ $tmp_nsb_prompt -eq 1 ]; then
61 echo $@
62 read nsb_prompt_dummy
63 else
64 echo "$@ (PROMPT SKIPPED)"
68 nsb-flow()
70 NSB_FLOW=$NSB_FLOW:$@
71 echo "Running $@" >&2
74 #----------------------------------------------------------------------
76 nsb-config-dist()
78 nsb-flow config-dist
79 if [ $# -lt 1 ]; then
80 nsb-abort "usage: nsb-config-dist src_dir"
82 ngc_src=$1
83 if [ ! -d $ngc_src ]; then
84 nsb-abort "$ngc_src does not exist!"
86 if [ ! -d $ngc_src/agent/mibgroup ]; then
87 nsb-abort "agent/mibgroup directory in $ngc_src does not exist!"
91 # some modules might be release specific, so make sure they
92 # exist before we send them off to configure
94 NSB_FINAL_MODULES=
95 for ncd_x in $NSB_DIST_MODULES
97 if [ -a $ngc_src/agent/mibgroup/$ncd_x.h ]; then
98 NSB_FINAL_MODULES="$NSB_FINAL_MODULES $ncd_x"
100 done
103 # NOTE: for some reason, bash does not expand variables
104 # inside of single quotes, so use double quotes
106 echo $ngc_src/configure --with-sys-location=Unknown \
107 --disable-developer $NSB_EXTRA_CONFIG \
108 --with-sys-contact='System Administrator' \
109 --with-defaults --with-mib-modules="$NSB_FINAL_MODULES"
110 $ngc_src/configure --with-sys-location=Unknown \
111 --disable-developer $NSB_EXTRA_CONFIG \
112 --with-sys-contact='System Administrator' \
113 --with-defaults --with-mib-modules="$NSB_FINAL_MODULES"
114 # I'd like to add ' | tee nsb-config.$DATE' to save output, but then
115 # I'd lose the rc from configure, which I need... sigh
116 ngc_rc=$?
117 if [ $ngc_rc -ne 0 ];then
118 nsb-abort "Error during configure dist (rc=$ngc_rc)"
122 nsb-config-all()
124 nsb-flow config-all
125 if [ $# -lt 1 ]; then
126 nsb-abort "usage: nsb-config-with src_dir"
128 ngc_src=$1
129 if [ ! -d $ngc_src ]; then
130 nsb-abort "$ngc_src does not exist!"
132 if [ ! -d $ngc_src/agent/mibgroup ]; then
133 nsb-abort "agent/mibgroup directory in $ngc_src does not exist!"
137 # System specific additions
139 case `uname -s` in
141 Linux)
142 NSB_EXTRA_TRANSPORTS="UDPIPv6 TCPIPv6 IPX"
145 Darwin)
149 NSB_EXTRA_TRANSPORTS="UDPIPv6 TCPIPv6"
151 esac
154 # some modules might be release specific, so make sure they
155 # exist before we send them off to configure
157 NSB_FINAL_MODULES=
158 for ncd_x in $NSB_DIST_MODULES $NSB_EXTRA_MODULES
160 if [ -a $ngc_src/agent/mibgroup/$ncd_x.h ]; then
161 NSB_FINAL_MODULES="$NSB_FINAL_MODULES $ncd_x"
163 done
166 # configure
168 # NOTE: for some reason, bash does not expand variables
169 # inside of single quotes, so use double quotes
171 echo $ngc_src/configure --with-defaults \
172 --disable-developer $NSB_EXTRA_CONFIG \
173 "--with-mib-modules=$NSB_FINAL_MODULES" \
174 "--with-transports=$NSB_DIST_TRANSPORTS $NSB_EXTRA_TRANSPORTS" \
175 $NSB_PERL --enable-shared --with-libwrap
176 $ngc_src/configure --with-defaults \
177 --disable-developer $NSB_EXTRA_CONFIG \
178 "--with-mib-modules=$NSB_FINAL_MODULES" \
179 "--with-transports=$NSB_DIST_TRANSPORTS $NSB_EXTRA_TRANSPORTS" \
180 $NSB_PERL --enable-shared --with-libwrap
181 # I'd like to add ' | tee nsb-config.$DATE' to save output, but then
182 # I'd lose the rc from configure, which I need... sigh
183 ngc_rc=$?
184 if [ $ngc_rc -ne 0 ];then
185 nsb-abort "Error during configure all (rc=$ngc_rc)"
189 nsb-sysname()
191 echo `uname -mrs | tr ' /' '__'`
194 nsb-zip()
196 if [ $# -ne 3 ]; then
197 nsb-abort "usage: $0 release build_directory dest_dir"
200 release=$1
201 build_dir=$2
202 dest_dir=$3
204 platform=`nsb-sysname`
205 build=$build_dir/$platform
207 if [ ! -d $build ]; then
208 nsb-abort "$build directory does not exist!"
211 if [ ! -d $build/usr ]; then
212 nsb-abort "install directory $build/usr directory does not exist!"
215 cd $build
217 rm -f $dest_dir/$release-$platform.tar
218 nsb-info "tar cf $dest_dir/$release-$platform.tar usr"
219 tar cf $dest_dir/$release-$platform.tar usr
221 nsb-info "gzip --best $dest_dir/$release-$platform.tar"
222 gzip --best $dest_dir/$release-$platform.tar
224 if [ $NSB_QUIET -ne 1 ]; then
225 ls -lt $dest_dir
229 nsb-upload()
231 nsb-flow upload
232 build_dir=$1
233 target=$2
234 dir=$PWD
235 cd $build_dir
236 $NSB_SCP config.log configure-summary nsb-make-all.* \
237 $target
238 cd $dir
241 nsb-make()
243 nsb-flow make $1
244 target=$1
245 shift 1
246 parms=$@
248 if [ -z $NSB_MAKE ];then
249 #nsb-info "Searching for GNU make (set NSB_MAKE to skip this step)"
250 for p in `echo $PATH | tr ':' ' '`
252 #echo $p
253 if [ -x $p/make ];then
254 dummy=`$p/make --version 2>&1 | grep GNU`
255 if [ $? -eq 0 ];then
256 #nsb-info "using $p/make ($dummy)"
257 NSB_MAKE=$p/make
258 break
261 if [ -x $p/gmake ];then
262 dummy=`$p/gmake --version 2>&1 | grep GNU`
263 if [ $? -eq 0 ];then
264 #nsb-info "using $p/gmake ($dummy)"
265 NSB_MAKE=$p/gmake
266 break
269 done
270 if [ -z $NSB_MAKE ];then
271 nsb-abort "GNU make not found. Set NSB_MAKE to your make executable."
275 nsb_make_OUTPUT=nsb-make-$target.$DATE
276 nsb-info "Making $target... (log is $nsb_make_OUTPUT)"
278 if [ "x$target" = "xall" ]; then
279 $NSB_MAKE NOAUTODEPS=y touchit 2>&1 | tee $nsb_make_OUTPUT
281 $NSB_MAKE NOAUTODEPS=y start-flag $target $parms end-flag 2>&1 | tee -a $nsb_make_OUTPUT
282 # checking $? would only get us the rc from tee, which is useless
284 nsb-info "Checking for errors..."
285 egrep "[Ee]rror|FAIL|[Ww]arn|No |exists|\*\*\*" $nsb_make_OUTPUT \
286 > nsb-make-$target-allerrs.$DATE
287 # allow for a few exceptions
288 egrep -v "[Ww]arn|error(mib|\.3)" nsb-make-$target-allerrs.$DATE \
289 > nsb-make-$target-errs.$DATE
290 if [ -s nsb-make-$target-errs.$DATE ]; then
291 nsb-prompt "press enter to view errors"
292 grep ':' $nsb_make_OUTPUT >&2
293 # cat nsb-make-$target-allerrs.$DATE >&2
294 nsb-abort "Error(s) during make $target"
297 if [ -f build-in-progress-flag ];then
298 nsb-abort "make $target incomplete"
302 nsb-default-paths()
304 if [ -z "$NSB_SRC_DIR" ]; then
305 NSB_SRC_DIR=$HOME/src/net-snmp-$VERSION
307 if [ -z "$NSB_BUILD_DIR" ]; then
308 NSB_BUILD_DIR=$HOME/build
310 if [ -z "$NSB_INSTALL_DIR" ]; then
311 NSB_INSTALL_DIR=$NSB_BUILD_DIR/usr/local
315 nsb-build()
317 if [ $# -lt 5 ]; then
318 nsb-abort "usage: $0 release src_dir build_directory dest_dir config_all_flag ($@)"
321 nsb_config_all=0
322 release=$1
323 src_dir=$2
324 build_dir=$3
325 dest_dir=$4
326 nsb_config_all=$5
327 shift 5
329 nsb-flow build in $build_dir
332 if [ ! -d $src_dir ]; then
333 nsb-abort "$src_dir does not exist!"
336 if [ ! -d $build_dir ]; then
337 mkdir $build_dir
338 if [ ! -d $build_dir ]; then
339 nsb-abort "$build_dir directory does not exist!"
343 nsb-info "Changing directories to $build_dir"
344 cd $build_dir
346 if [ $NSB_CLEAN -gt 0 ]; then
347 nsb-info "Cleaning up..."
348 if [ $NSB_CLEAN -eq 2 ];then
349 if [ "x$PWD" = "/" ]; then
350 nsb-abort "Not running rm -fR from /"
352 nsb-info "rm -fR * .[a-zA-Z]* 2>&1 > /dev/null"
353 rm -fR * .[a-zA-Z]* 2>&1 > /dev/null
354 else
355 nsb-info "rm -fR nsb-* $dest_dir 2>&1 > /dev/null"
356 rm -fR nsb-* $dest_dir 2>&1 > /dev/null
357 if [ -f Makefile ]; then
358 nsb-make NOAUTODEPS=y distclean
359 nsb_build_rc=$?
360 if [ $nsb_build_rc -ne 0 ]; then
361 nsb-abort "Error during make distclean (rc=$nsb_build_rc)"
367 if [ $NSB_SKIP_CONFIG -ne 1 ]; then
368 nsb-info "Configuring... (log is nsb-config.$DATE)"
369 if [ $nsb_config_all -eq 0 ]; then
370 nsb-config-dist $src_dir
371 else
372 nsb-config-all $src_dir
374 nsb-prompt "press enter to continue"
377 if [ $NSB_SKIP_BUILD -eq 1 ]; then
378 nsb-info "Skipping 'make all'"
379 else
380 nsb-make all
383 if [ $NSB_SKIP_TEST -eq 1 ]; then
384 nsb-info "Skipping 'make test'"
385 else
386 nsb-prompt "No errors found, press enter to run tests"
387 nsb-make test
390 if [ $NSB_SKIP_INSTALL -eq 1 ]; then
391 nsb-info "Skipping 'make install'"
392 else
393 nsb-prompt "No errors found, press enter to install"
394 nsb-make install prefix=$dest_dir exec_prefix=$dest_dir
397 return 0