added files
[bcm963xx.git] / userapps / opensource / net-snmp / net-snmp-config.in
1 #!/bin/sh
2
3 # this shell script is designed to merely dump the configuration
4 # information about how the net-snmp package was compiled.  The
5 # information is particularily useful for applications that need to
6 # link against the net-snmp libraries and hence must know about any
7 # other libraries that must be linked in as well.
8
9 NSC_BASE_AGENT_LIBS="-lnetsnmpagent -lnetsnmpmibs -lnetsnmphelpers -lnetsnmp"
10
11 if test "x$1" = "x"; then
12   usage="yes"
13 else
14   exec_prefix=@exec_prefix@
15   prefix=@exec_prefix@
16   case $1 in
17     --debug-tokens)
18       echo "find NET-SNMP-SOURCE-DIR -name \"*.c\" -print | xargs grep DEBUGMSGT | grep \\\" | cut -f 2 -d\\\" | sort -u"
19       ;;
20     --indent-options)
21       echo "indent -orig -nbc -bap -nut -nfca `(cd NET-SNMP-INCLUDE-DIR; perl -n -e 'print "-T $1 " if (/}\s*(netsnmp_\w+)\s*;/);' */*.h)`"
22       ;;
23     --configure-options)
24       echo @CONFIGURE_OPTIONS@
25       ;;
26     --snmpd-module-list)
27       echo @MODULE_LIST@
28       ;;
29     --base-cflags)
30       echo @CFLAGS@ @CPPFLAGS@ -I@includedir@
31       ;;
32     --cflags)
33       echo @CFLAGS@ @DEVFLAGS@ @CPPFLAGS@ -I. -I@includedir@
34       ;;
35     --agent-libs)
36       # use this one == --netsnmp-agent-libs + --external-libs
37       echo @LDFLAGS@ -L@libdir@ $NSC_BASE_AGENT_LIBS @AGENTLIBS@ @WRAPLIBS@
38       ;;
39     --libs)
40       # use this one == --netsnmp-libs + --external-libs
41       echo @LDFLAGS@ -L@libdir@ -lnetsnmp @LIBS@
42       ;;
43     --external-libs)
44       echo @LDFLAGS@ @LIBS@
45       ;;
46     --external-agent-libs)
47       echo @LDFLAGS@ @AGENTLIBS@ @WRAPLIBS@
48       ;;
49     --netsnmp-libs)
50       echo -L@libdir@ -lnetsnmp
51       ;;
52     --netsnmp-agent-libs)
53       echo -L@libdir@ $NSC_BASE_AGENT_LIBS
54       ;;
55     --version)
56       echo @VERSION@
57       ;;
58     --help)
59       usage="yes"
60       ;;
61     --prefix)
62       echo @prefix@
63       ;;
64     --exec-prefix)
65       echo @exec_prefix@
66       ;;
67     --create-snmpv3-user)
68       if @PSCMD@ | egrep ' snmpd *$' > /dev/null 2>&1 ; then
69          echo "Apparently at least one snmpd demon is already running."
70          echo "You must stop them in order to use this command."
71          exit 1
72       fi
73
74       Aalgorithm="MD5"
75       Xalgorithm="DES"
76       token=rwuser
77       shift
78       arg=$1
79       shift
80       while test "x$done" = "x" -a "x$arg" != "x" ; do
81         case $arg in
82             -A)
83                 Aalgorithm=$1
84                 shift
85                 ;;
86             -X)
87                 Xalgorithm=$1
88                 shift
89                 ;;
90             -a)
91                 apassphrase=$1
92                 shift
93                 ;;
94             -x)
95                 xpassphrase=$1
96                 shift
97                 ;;
98             -ro)
99                 token="rouser"
100                 ;;
101             -*)
102                 echo "unknown suboption to --create-snmpv3-user: $arg"
103                 exit 1
104                 ;;
105             *)
106                 done=1
107                 ;;
108         esac
109         if test "x$done" = "x" ; then
110           arg=$1
111           shift
112         fi
113       done
114       
115       user=$arg
116       if test "x$user" = "x" ; then
117           prompt=yes
118           echo "Enter a SNMPv3 user name to create: "
119           read user
120       fi
121       if test "x$user" = "x" ; then
122           echo "You must specify a user name"
123           exit 1
124       fi
125
126       if test "x$apassphrase" = "x" ; then
127           prompt=yes
128           echo "Enter authentication pass-phrase: "
129           read apassphrase
130       else
131           shift
132       fi
133       if test "x$apassphrase" = "x" ; then
134           echo "You must specify an authentication pass-phrase"
135           exit 1
136       fi
137
138       if test "x$prompt" = "xyes" -a "x$xpassphrase" = "x" ; then
139           echo "Enter encryption pass-phrase: "
140           echo "  [press return to reuse the authentication pass-phrase]"
141           read xpassphrase
142       fi
143
144       outfile="@PERSISTENT_DIRECTORY@/snmpd.conf"
145       line="createUser $user $Aalgorithm \"$apassphrase\" $Xalgorithm $xpassphrase"
146       echo "adding the following line to $outfile:"
147       echo "  " $line
148       echo $line >> $outfile
149
150       outfile="@datadir@/snmp/snmpd.conf"
151       line="$token $user"
152       echo "adding the following line to $outfile:"
153       echo "  " $line
154       echo $line >> $outfile
155       ;;
156
157     --compile-subagent)
158       shift
159       outname=$1
160       shift
161       if test $1 = "--norm" ; then
162         norm=1
163         shift
164       fi
165       if test $1 = "--cflags" ; then
166         shift
167         cflags=$1
168         echo "setting extra cflags: $cflags"
169         shift
170       fi
171       if test $1 = "--ldflags" ; then
172         shift
173         ldflags=$1
174         echo "setting extra ldflags: $ldflags"
175         shift
176       fi
177       tmpfile=netsnmptmp.$$.c
178       if test -f $tmpfile; then
179         echo "Ack.  Can't create $tmpfile: already exists"
180         exit 1
181       fi
182       echo "generating the tmporary code file: $tmpfile"
183       rm -f $tmp
184       cat > $tmpfile <<EOF
185 /* generated from net-snmp-config */
186 #include <net-snmp/net-snmp-config.h>
187 #ifdef HAVE_SIGNAL_H
188 #include <signal.h>
189 #endif /* HAVE_SIGNAL_H */
190 #include <net-snmp/net-snmp-includes.h>
191 #include <net-snmp/agent/net-snmp-agent-includes.h>
192 EOF
193
194     # add include files
195     while test "$1" != ""; do
196       cfiles="$cfiles $1"
197       name=`basename $1 | sed 's/\.[co]$/.h/'`
198       if test -f $name.h; then
199         if grep "init_$name" $name; then
200           echo "  #include\"$name\"" >> $tmpfile
201         fi
202       fi
203       shift
204     done
205
206       cat >> $tmpfile <<EOF
207 static int keep_running;
208
209 RETSIGTYPE
210 stop_server(int a) {
211     keep_running = 0;
212 }
213
214 int
215 main (int argc, char **argv) {
216   /* print log errors to stderr */
217   snmp_enable_stderrlog();
218  /* we are a subagent */
219   netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
220
221   /* initialize the agent library */
222   init_agent("$outname");
223
224   /* initialize your mib code here */
225 EOF
226
227     # add init routines
228     for i in $cfiles ; do
229       name=`basename $i | sed 's/\.[co]$//'`
230       echo checking for init_$name in $i
231       if grep "init_$name" $i ; then
232         echo "  init_${name}();" >> $tmpfile
233       fi
234       shift
235     done
236
237     # finish file
238     cat >> $tmpfile <<EOF
239
240   /* ustMain will be used to read ustMain.conf files. */
241   init_snmp("$outname");
242
243   /* In case we recevie a request to stop (kill -TERM or kill -INT) */
244   keep_running = 1;
245 #ifdef SIGTERM
246   signal(SIGTERM, stop_server);
247 #endif
248 #ifdef SIGINT
249   signal(SIGINT, stop_server);
250 #endif
251
252   /* main loop here... */
253   while(keep_running) {
254     agent_check_and_process(1);
255   }
256
257   /* at shutdown time */
258   snmp_shutdown("$outname");
259   exit(0);
260 }
261
262 EOF
263       if test "$?" != 0 -o ! -f "$tmpfile" ; then
264         echo "Ack.  Can't create $tmpfile."
265         exit 1
266       fi
267       prefix=@prefix@
268       cmd="@CC@ $cflags @CFLAGS@ @DEVFLAGS@ -I. -I@includedir@ -o $outname $tmpfile $cfiles @LDFLAGS@ -L@exec_prefix@/lib -lnetsnmpagent -lnetsnmphelpers -lnetsnmpmibs -lnetsnmp @AGENTLIBS@ $ldflags"
269       echo "running: $cmd"
270       `$cmd`
271       if test "x$norm" != "x1" ; then
272         echo "removing the tmporary code file: $tmpfile"
273         rm -f $tmpfile
274       else
275         echo "leaving the tmporary code file: $tmpfile"
276       fi
277       if test -f $outname ; then
278         echo "subagent program $outname created"
279       fi
280       ;;
281
282     *)
283       echo "unknown option $1"
284       usage="yes"
285       ;;
286   esac
287 fi
288
289 if test "x$usage" = "xyes"; then
290   echo ""
291   echo "Usage:"
292   echo "  net-snmp-config [--cflags] [--agent-libs] [--libs] [--version]"
293   echo "                  ... [see below for complete flag list]"
294   echo ""
295   echo "    --version         displays the net-snmp version number"
296   echo "    --indent-options  displays the indent options from the Coding Style"
297   echo "    --debug-tokens    displays a example command line to search to source"
298   echo "                      code for a list of available debug tokens"
299   echo ""
300   echo "  SNMP Setup commands:"
301   echo ""
302   echo "    --create-snmpv3-user [-ro] [-a authpass] [-x privpass] [-X DES]"
303   echo "                         [-A MD5|SHA] [username]"
304   echo ""
305   echo "  These options produce the various compilation flags needed when"
306   echo "  building external SNMP applications:"
307   echo ""
308   echo "    --base-cflags     lists additional compilation flags needed"
309   echo "                      for external applications (excludes -I. and"
310   echo "                      extra developer warning flags, if any)"
311   echo "    --cflags          lists additional compilation flags needed"
312   echo "    --libs            lists libraries needed for building applications"
313   echo "    --agent-libs      lists libraries needed for building subagents"
314   echo ""
315   echo "    --netsnmp-libs        lists netsnmp specific libraries"
316   echo "    --external-libs       lists libraries needed by netsnmp libs"
317   echo "    --netsnmp-agent-libs  lists netsnmp specific agent libraries"
318   echo "    --external-agent-libs lists libraries needed by netsnmp libs"
319   echo ""
320   echo "  Automatted subagent building (produces an OUTPUTNAME binary file):"
321   echo "  [this feature has not been tested very well yet.  use at your risk.]"
322   echo ""
323   echo "    --compile-subagent OUTPUTNAME [--norm] [--cflags flags]"
324   echo "                                  [--ldflags flags] mibmodule1.c [...]]"
325   echo ""
326   echo "         --norm           leave the generated .c file around to read."
327   echo "         --cflags flags   extra cflags to use (e.g. -I...)."
328   echo "         --ldflags flags  extra ld flags to use (e.g. -L... -l...)."
329   echo ""
330   echo "  Details on how the net-nsmp package was compiled:"
331   echo ""
332   echo "    --configure-options   Display original configure arguments"
333   echo "    --snmpd-module-list   Display the modules compiled into the agent"
334   echo "    --prefix              Display the installation prefix"
335   echo ""
336   exit
337 fi