home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / bin / net-snmp-config < prev    next >
Encoding:
Text File  |  2011-01-05  |  26.7 KB  |  749 lines

  1. #!/bin/sh
  2. #
  3. # $Id: net-snmp-config.in 18651 2010-05-06 06:33:37Z bvassche $
  4. #
  5. # this shell script is designed to merely dump the configuration
  6. # information about how the net-snmp package was compiled.  The
  7. # information is particularily useful for applications that need to
  8. # link against the net-snmp libraries and hence must know about any
  9. # other libraries that must be linked in as well.
  10.  
  11. check_build_dir()
  12. {
  13.       build_dir=$1
  14.  
  15.       if test "x$build_dir" = "x" ; then
  16.          echo "You must specify a build directory."
  17.          exit 1
  18.       fi
  19.       # is it the src dir?
  20.       if test -f $build_dir/net-snmp-config.in ; then
  21.          return
  22.       fi
  23.       # make sure we can find build dir
  24.       if test ! -d $build_dir/snmplib/.libs ; then
  25.          echo "$build_dir does not appear to be a build directory."
  26.          exit 1
  27.       fi
  28. }
  29.  
  30. prefix=/usr
  31. exec_prefix=/usr
  32. includedir=${prefix}/include
  33. libdir=${exec_prefix}/lib
  34. NSC_LDFLAGS=""
  35. NSC_INCLUDEDIR=${includedir}
  36. NSC_LIBDIR=-L${libdir}
  37. NSC_LIBS=""
  38. NSC_AGENTLIBS=" -Wl,-E"
  39. NSC_PREFIX=$prefix
  40. NSC_EXEC_PREFIX=$exec_prefix
  41. NSC_SRCDIR=.
  42. NSC_INCDIR=${NSC_PREFIX}/include
  43. NSC_BASE_SUBAGENT_LIBS="-lnetsnmpagent -lnetsnmphelpers -lnetsnmp"
  44. NSC_BASE_AGENT_LIBS="-lnetsnmpagent -lnetsnmphelpers -lnetsnmpmibs -lnetsnmp"
  45. NSC_SRC_LIBDIRS="agent/.libs snmplib/.libs agent/helpers/.libs"
  46. NSC_SRC_LIBDEPS="agent/.libs/libnetsnmpmibs.a agent/.libs/libnetsnmpagent.a agent/helpers/.libs/libnetsnmphelpers.a snmplib/.libs/libnetsnmp.a"
  47.  
  48. if test "x$NSC_SRCDIR" = "x." ; then
  49.    NSC_SRCDIR="NET-SNMP-SOURCE-DIR"
  50. fi
  51.  
  52. if test "x$1" = "x"; then
  53.   usage="yes"
  54. else
  55.   while test "x$done" = "x" -a "x$1" != "x" -a "x$usage" != "xyes"; do
  56.   case "$1" in
  57.     -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  58.     *) optarg= ;;
  59.   esac
  60.  
  61.   unset shifted
  62.   case $1 in
  63.     --prefix=*)
  64.       prefix=$optarg
  65.       NSC_PREFIX=${prefix}
  66.       NSC_INCLUDEDIR=${prefix}/include
  67.       NSC_LIBDIR=-L${prefix}/lib
  68.       ;;
  69.  
  70.     --exec-prefix=*)
  71.       exec_prefix=$optarg
  72.       NSC_EXEC_PREFIX=${exec_prefix}
  73.       NSC_LIBDIR=-L${exec_prefix}/lib
  74.       ;;
  75.  
  76.     --debug-tokens|--deb*|--dbg*)
  77.       echo "find $NSC_SRCDIR -name \"*.c\" -print | xargs grep DEBUGMSGT | grep \\\" | cut -f 2 -d\\\" | sort -u"
  78.       if test "x$NSC_SRCDIR" != "xNET-SNMP-SOURCE-DIR" ; then
  79.         /usr/bin/find $NSC_SRCDIR -name "*.c" -print | xargs grep DEBUGMSGT | grep \" | cut -f 2 -d\" | sort -u
  80.       fi
  81.       ;;
  82.     --indent-options|--in*)
  83.       echo "indent -orig -nbc -bap -nut -nfca `(cd $NSC_INCDIR/net-snmp; perl -n -e 'print "-T $1 " if (/}\s*(netsnmp_\w+)\s*;/);' */*.h)`"
  84.       ;;
  85.     --configure-options|--con*)
  86.       echo " '--build=i486-linux-gnu' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--localstatedir=/var' '--libexecdir=${prefix}/lib/net-snmp' '--disable-maintainer-mode' '--disable-dependency-tracking' '--prefix=/usr' '--sysconfdir=/etc' '--mandir=/usr/share/man' '--with-persistent-directory=/var/lib/snmp' '--enable-ucd-snmp-compatibility' '--enable-shared' '--with-cflags=-g -O2 -DNETSNMP_USE_INLINE' '--with-perl-modules=INSTALLDIRS=vendor' '--enable-as-needed' '--enable-ipv6' '--with-logfile=none' '--without-rpm' '--with-libwrap' '--with-openssl' '--without-dmalloc' '--without-efence' '--without-rsaref' '--with-sys-contact=root' '--with-sys-location=Unknown' '--with-mib-modules=smux ucd-snmp/dlmod ucd-snmp/diskio ucd-snmp/lmSensors  host' '--with-out-mib-modules=' '--enable-mfd-rewrites' '--with-mnttab=/etc/mtab' '--with-mibdirs=$HOME/.snmp/mibs:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp' '--with-defaults' 'build_alias=i486-linux-gnu' 'CFLAGS=-g -O2' 'LDFLAGS=' 'CPPFLAGS='"
  87.       ;;
  88.     --snmpd-module-list|--mod*)
  89. echo  ucd-snmp/dlmod ucd-snmp/diskio ucd-snmp/lmSensors smux/smux util_funcs host/hr_system host/hr_storage host/hr_device host/hr_other host/hr_proc host/hr_network host/hr_print host/hr_disk host/hr_partition host/hr_filesys host/hr_swrun host/hr_swinst snmpv3/snmpEngine snmpv3/snmpMPDStats snmpv3/usmStats snmpv3/usmConf snmpv3/usmUser mibII/system_mib mibII/sysORTable mibII/at mibII/ip mibII/snmp_mib mibII/tcp mibII/icmp mibII/udp mibII/vacm_vars mibII/setSerialNo mibII/ipv6 ucd-snmp/proc ucd-snmp/versioninfo ucd-snmp/pass ucd-snmp/pass_persist ucd-snmp/disk ucd-snmp/loadave agent/extend ucd-snmp/errormib ucd-snmp/file ucd-snmp/proxy ucd-snmp/logmatch ucd-snmp/memory ucd-snmp/vmstat notification/snmpNotifyTable notification/snmpNotifyFilterProfileTable notification-log-mib/notification_log target/snmpTargetAddrEntry target/snmpTargetParamsEntry target/target target/target_counters agent/nsTransactionTable agent/nsModuleTable agent/nsDebug agent/nsCache agent/nsLogging agent/nsVacmAccessTable agentx/master agentx/subagent disman/event/mteScalars disman/event/mteTrigger disman/event/mteTriggerTable disman/event/mteTriggerDeltaTable disman/event/mteTriggerExistenceTable disman/event/mteTriggerBooleanTable disman/event/mteTriggerThresholdTable disman/event/mteTriggerConf disman/event/mteEvent disman/event/mteEventTable disman/event/mteEventSetTable disman/event/mteEventNotificationTable disman/event/mteEventConf disman/event/mteObjects disman/event/mteObjectsTable disman/event/mteObjectsConf disman/schedule/schedCore disman/schedule/schedConf disman/schedule/schedTable utilities/override utilities/execute utilities/iquery hardware/memory/hw_mem hardware/memory/memory_linux hardware/cpu/cpu hardware/cpu/cpu_linux mibII/kernel_linux mibII/ipAddr mibII/var_route mibII/route_write mibII/tcpTable mibII/udpTable mibII/vacm_context mibII/vacm_conf ip-mib/ip_scalars header_complex snmp-notification-mib/snmpNotifyFilterTable/snmpNotifyFilterTable agentx/protocol agentx/client agentx/master_admin agentx/agentx_config if-mib/ifTable/ifTable if-mib/ifXTable/ifXTable ip-mib/ipAddressTable/ipAddressTable ip-mib/inetNetToMediaTable/inetNetToMediaTable ip-mib/inetNetToMediaTable/inetNetToMediaTable_interface ip-mib/inetNetToMediaTable/inetNetToMediaTable_data_access ip-mib/ipSystemStatsTable/ipSystemStatsTable ip-mib/ipSystemStatsTable/ipSystemStatsTable_interface ip-mib/ipSystemStatsTable/ipSystemStatsTable_data_access ip-forward-mib/ipCidrRouteTable/ipCidrRouteTable ip-forward-mib/inetCidrRouteTable/inetCidrRouteTable tcp-mib/tcpConnectionTable/tcpConnectionTable tcp-mib/tcpListenerTable/tcpListenerTable udp-mib/udpEndpointTable/udpEndpointTable snmp-notification-mib/snmpNotifyFilterTable/snmpNotifyFilterTable_interface snmp-notification-mib/snmpNotifyFilterTable/snmpNotifyFilterTable_data_access if-mib/data_access/interface if-mib/ifTable/ifTable_interface if-mib/ifTable/ifTable_data_access if-mib/ifXTable/ifXTable_interface if-mib/ifXTable/ifXTable_data_access ip-mib/ipAddressTable/ipAddressTable_interface ip-mib/ipAddressTable/ipAddressTable_data_access ip-mib/data_access/arp_common ip-mib/data_access/arp_linux ip-mib/data_access/systemstats_common ip-mib/data_access/systemstats_linux ip-mib/data_access/scalars_linux ip-forward-mib/ipCidrRouteTable/ipCidrRouteTable_interface ip-forward-mib/ipCidrRouteTable/ipCidrRouteTable_data_access ip-forward-mib/inetCidrRouteTable/inetCidrRouteTable_interface ip-forward-mib/inetCidrRouteTable/inetCidrRouteTable_data_access tcp-mib/data_access/tcpConn_common tcp-mib/data_access/tcpConn_linux tcp-mib/tcpConnectionTable/tcpConnectionTable_interface tcp-mib/tcpConnectionTable/tcpConnectionTable_data_access tcp-mib/tcpListenerTable/tcpListenerTable_interface tcp-mib/tcpListenerTable/tcpListenerTable_data_access udp-mib/udpEndpointTable/udpEndpointTable_interface udp-mib/udpEndpointTable/udpEndpointTable_data_access if-mib/data_access/interface_linux if-mib/data_access/interface_ioctl ip-mib/data_access/ipaddress_common ip-mib/data_access/ipaddress_linux ip-forward-mib/data_access/route_common ip-forward-mib/data_access/route_linux ip-forward-mib/data_access/route_ioctl udp-mib/data_access/udp_endpoint_common udp-mib/data_access/udp_endpoint_linux ip-mib/data_access/ipaddress_ioctl
  90.       ;;
  91.     --default-mibs|--mibs|--MIBS)
  92.       echo :UCD-DLMOD-MIB:UCD-DISKIO-MIB:LM-SENSORS-MIB:HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES:IP-MIB:IF-MIB:TCP-MIB:UDP-MIB:SNMPv2-MIB:RFC1213-MIB:NOTIFICATION-LOG-MIB:DISMAN-EVENT-MIB:DISMAN-SCHEDULE-MIB:UCD-SNMP-MIB:UCD-DEMO-MIB:SNMP-TARGET-MIB:NET-SNMP-AGENT-MIB:SNMP-FRAMEWORK-MIB:SNMP-MPD-MIB:SNMP-USER-BASED-SM-MIB:SNMP-VIEW-BASED-ACM-MIB:SNMP-COMMUNITY-MIB:IPV6-ICMP-MIB:IPV6-MIB:IPV6-TCP-MIB:IPV6-UDP-MIB:IP-FORWARD-MIB:NET-SNMP-PASS-MIB:NET-SNMP-EXTEND-MIB:SNMP-NOTIFICATION-MIB:SNMPv2-TM:NET-SNMP-VACM-MIB
  93.       ;;
  94.     --default-mibdirs|--mibdirs|--MIBDIRS)
  95.       echo $HOME/.snmp/mibs:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp
  96.       ;;
  97.     --env-separator)
  98.       echo ":"
  99.       ;;
  100.     --snmpconfpath|--SNMPCONFPATH)
  101.       echo "/etc/snmp:/usr/share/snmp:/usr/lib/snmp:$HOME/.snmp:/var/lib/snmp"
  102.       ;;
  103.     --persistent-directory|--persistent-dir)
  104.       echo /var/lib/snmp
  105.       ;;
  106.     --perlprog|--perl)
  107.       echo /usr/bin/perl
  108.       ;;
  109.     #################################################### compile
  110.     --base-cflags)
  111.       echo -DNETSNMP_ENABLE_IPV6 -g -O2 -DNETSNMP_USE_INLINE -Ulinux -Dlinux=linux  -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -I/usr/lib/perl/5.10/CORE   -I${NSC_INCLUDEDIR}
  112.       ;;
  113.     --base-lib-cflags)
  114.       echo -DNETSNMP_ENABLE_IPV6 -g -O2 -DNETSNMP_USE_INLINE -Ulinux -Dlinux=linux  -I${NSC_INCLUDEDIR}
  115.       ;;
  116.     --cflags|--cf*)
  117.       echo -DNETSNMP_ENABLE_IPV6 -g -O2 -DNETSNMP_USE_INLINE -Ulinux -Dlinux=linux  -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -I/usr/lib/perl/5.10/CORE    -I. -I${NSC_INCLUDEDIR}
  118.       ;;
  119.     --srcdir)
  120.       echo $NSC_SRCDIR
  121.       ;;
  122.     #################################################### linking
  123.     --libdir|--lib-dir)
  124.       echo $NSC_LIBDIR
  125.       ;;
  126.     --ldflags|--ld*)
  127.       echo $NSC_LDFLAGS
  128.       ;;
  129.     --build-lib-dirs)
  130.       shift
  131.       build_dir=$1
  132.       check_build_dir $build_dir
  133.       for dir in $NSC_SRC_LIBDIRS; do
  134.           result="$result -L$build_dir/$dir"
  135.       done
  136.       echo $result
  137.       ;;
  138.     --build-lib-deps)
  139.       shift
  140.       build_dir=$1
  141.       check_build_dir $build_dir
  142.       for dir in $NSC_SRC_LIBDEPS; do
  143.           result="$result $build_dir/$dir"
  144.       done
  145.       echo $result
  146.       ;;
  147.     --build-includes)
  148.       shift
  149.       build_dir=$1
  150.       check_build_dir $build_dir
  151.       result="-I$build_dir/include"
  152.       if test "$build_dir" != "$NSC_SRCDIR" -a "$NSC_SRCDIR" != "NET-SNMP-SOURCE-DIR"
  153.       then
  154.           result="$result -I$NSC_SRCDIR/include"
  155.       fi
  156.       echo $result
  157.       ;;
  158.     #################################################### client lib
  159.     --libs)
  160.       # use this one == --netsnmp-libs + --external-libs
  161.       echo $NSC_LDFLAGS $NSC_LIBDIR -lnetsnmp $NSC_LIBS
  162.       ;;
  163.     --netsnmp-libs)
  164.       echo $NSC_LIBDIR -lnetsnmp
  165.       ;;
  166.     --external-libs)
  167.       echo $NSC_LDFLAGS $NSC_LIBS
  168.       ;;
  169.     #################################################### agent lib
  170.     --base-agent-libs)
  171.       echo $NSC_BASE_AGENT_LIBS
  172.       ;;
  173.     --base-subagent-libs)
  174.       echo $NSC_BASE_SUBAGENT_LIBS
  175.       ;;
  176.     --agent-libs)
  177.       # use this one == --netsnmp-agent-libs + --external-libs
  178.       echo $NSC_LDFLAGS $NSC_LIBDIR $NSC_BASE_AGENT_LIBS $NSC_AGENTLIBS
  179.       ;;
  180.     --netsnmp-agent-libs)
  181.       echo $NSC_LIBDIR $NSC_BASE_AGENT_LIBS
  182.       ;;
  183.     --external-agent-libs)
  184.       echo $NSC_LDFLAGS $NSC_AGENTLIBS
  185.       ;;
  186.     ####################################################
  187.     --version|--ver*)
  188.       echo 5.4.3
  189.       ;;
  190.     --help)
  191.       usage="yes"
  192.       ;;
  193.     --prefix|--pre*)
  194.       echo $NSC_PREFIX
  195.       ;;
  196.     --exec-prefix)
  197.       echo $NSC_EXEC_PREFIX
  198.       ;;
  199.     ####################################################
  200.     --create-snmpv3-user)
  201.       if /bin/ps -e | egrep ' snmpd *$' > /dev/null 2>&1 ; then
  202.          echo "Apparently at least one snmpd demon is already running."
  203.          echo "You must stop them in order to use this command."
  204.          exit 1
  205.       fi
  206.  
  207.       Aalgorithm="MD5"
  208.       Xalgorithm="DES"
  209.       token=rwuser
  210.       shift
  211.       shifted=1
  212.       while test "x$done" = "x" -a "x$1" != "x" ; do
  213.     case $1 in
  214.         -A|-a)
  215.         shift
  216.         if test "x$1" = "x" ; then
  217.             echo "You must specify an authentication algorithm or pass phrase"
  218.             exit 1
  219.         fi
  220.             case $1 in
  221.                 MD5|SHA)
  222.             Aalgorithm=$1
  223.             shift
  224.             ;;
  225.                 md5|sha)
  226.             Aalgorithm=`echo $1 | tr a-z A-Z`
  227.             shift
  228.             ;;
  229.                 *)
  230.             apassphrase=$1
  231.             shift
  232.             ;;
  233.         esac
  234.         ;;
  235.         -X|-x)
  236.         shift
  237.         if test "x$1" = "x" ; then
  238.             echo "You must specify an encryption algorithm or pass phrase"
  239.             exit 1
  240.         fi
  241.             case $1 in
  242.                 DES|AES|AES128)
  243.             Xalgorithm=$1
  244.             shift
  245.             ;;
  246.                 des|aes|aes128)
  247.             Xalgorithm=`echo $1 | tr a-z A-Z`
  248.             shift
  249.             ;;
  250.                 *)
  251.             xpassphrase=$1
  252.             shift
  253.             ;;
  254.         esac
  255.         ;;
  256.         -ro)
  257.             token="rouser"
  258.         shift
  259.         ;;
  260.          -*)
  261.         echo "unknown suboption to --create-snmpv3-user: $1"
  262.         exit 1
  263.         ;;
  264.         *)
  265.             done=1
  266.         ;;
  267.     esac
  268.       done
  269.       
  270.       if test "x$1" = "x" ; then
  271.           prompt=yes
  272.       echo "Enter a SNMPv3 user name to create: "
  273.       read user
  274.       else
  275.           user=$1
  276.           shift
  277.       fi
  278.       if test "x$user" = "x" ; then
  279.           echo "You must specify a user name"
  280.       exit 1
  281.       fi
  282.  
  283.       if test "x$apassphrase" = "x" ; then
  284.           prompt=yes
  285.       echo "Enter authentication pass-phrase: "
  286.       read apassphrase
  287.       fi
  288.       if test "x$apassphrase" = "x" ; then
  289.           echo "You must specify an authentication pass-phrase"
  290.       exit 1
  291.       fi
  292.  
  293.       if test "x$prompt" = "xyes" -a "x$xpassphrase" = "x" ; then
  294.       echo "Enter encryption pass-phrase: "
  295.       echo "  [press return to reuse the authentication pass-phrase]"
  296.       read xpassphrase
  297.       fi
  298.  
  299.       outdir="/var/lib/snmp"
  300.       outfile="$outdir/snmpd.conf"
  301.       line="createUser $user $Aalgorithm \"$apassphrase\" $Xalgorithm $xpassphrase"
  302.       echo "adding the following line to $outfile:"
  303.       echo "  " $line
  304.       # in case it hasn't ever been started yet, start it.
  305.       if test ! -d $outdir ; then
  306.           mkdir $outdir
  307.       fi
  308.       if test ! -d $outfile ; then
  309.           touch $outfile
  310.       fi
  311.       echo $line >> $outfile
  312.  
  313.       outfile="${prefix}/share/snmp/snmpd.conf"
  314.       line="$token $user"
  315.       echo "adding the following line to $outfile:"
  316.       echo "  " $line
  317.       if test ! -d $outfile ; then
  318.           touch $outfile
  319.       fi
  320.       echo $line >> $outfile
  321.       ;;
  322.  
  323.     ####################################################
  324.     --compile-subagent)
  325.       shift
  326.       shifted=1
  327.       while test "x$done" = "x" -a "x$1" != "x" ; do
  328.     case $1 in
  329.             --norm)
  330.             norm=1
  331.             shift
  332.         ;;
  333.             --cflags)
  334.             shift
  335.             if test "x$1" = "x" ; then
  336.                 echo "You must specify the extra cflags"
  337.                 exit 1
  338.             fi
  339.             cflags=$1
  340.             echo "setting extra cflags: $cflags"
  341.             shift
  342.         ;;
  343.             --ldflags)
  344.             shift
  345.             if test "x$1" = "x" ; then
  346.                 echo "You must specify the extra ldflags"
  347.                 exit 1
  348.             fi
  349.             ldflags=$1
  350.             echo "setting extra ldflags: $ldflags"
  351.             shift
  352.         ;;
  353.          --*)
  354.         echo "unknown suboption to --compile-subagent: $1"
  355.         exit 1
  356.         ;;
  357.         *)
  358.                 if test "x$outname" = "x"; then
  359.                   outname=$1
  360.                   shift
  361.                 else
  362.               done=1
  363.                 fi
  364.         ;;
  365.     esac
  366.       done
  367.       tmpfile=netsnmptmp.$$.c
  368.       if test -f $tmpfile; then
  369.     echo "Ack.  Can't create $tmpfile: already exists"
  370.     exit 1
  371.       fi
  372.       echo "generating the tmporary code file: $tmpfile"
  373.       rm -f $tmpfile
  374.       cat > $tmpfile <<EOF
  375. /* generated from net-snmp-config */
  376. #include <net-snmp/net-snmp-config.h>
  377. #ifdef HAVE_SIGNAL
  378. #include <signal.h>
  379. #endif /* HAVE_SIGNAL */
  380. #include <net-snmp/net-snmp-includes.h>
  381. #include <net-snmp/agent/net-snmp-agent-includes.h>
  382. EOF
  383.  
  384.     # If we were only given a single filename
  385.     # (and no explicit output name)
  386.     # then use that as the base of the output name
  387.     #
  388.     # If we weren't even given that, then bomb out
  389.     if test "x$1" = "x"; then
  390.       if test "x$outname" = "x"; then
  391.         echo "No MIB module codefile specified"
  392.         rm -f $tmpfile
  393.         exit 1
  394.       else
  395.         cfiles=$outname
  396.         outname=`basename $cfiles | sed 's/\.[co]$//'`
  397.         if test -f $outname.h; then
  398.           if grep "init_$outname" $outname.h; then
  399.             echo "  #include \"$outname.h\"" >> $tmpfile
  400.           fi
  401.         fi
  402.       fi
  403.     fi
  404.  
  405.     # add include files
  406.     while test "$1" != ""; do
  407.       cfiles="$cfiles $1"
  408.       name=`basename $1 | sed 's/\.[co]$//'`
  409.       if test -f $name.h; then
  410.         if grep "init_$name" $name.h; then
  411.           echo "  #include \"$name.h\"" >> $tmpfile
  412.         fi
  413.       fi
  414.       shift
  415.     done
  416.  
  417.       cat >> $tmpfile <<EOF
  418. const char *app_name = "$outname";
  419.  
  420. extern int netsnmp_running;
  421.  
  422. #ifdef __GNUC__
  423. #define UNUSED __attribute__((unused))
  424. #else
  425. #define UNUSED
  426. #endif
  427.  
  428. RETSIGTYPE
  429. stop_server(UNUSED int a) {
  430.     netsnmp_running = 0;
  431. }
  432.  
  433. static void
  434. usage(const char *prog)
  435. {
  436.     fprintf(stderr,
  437.             "USAGE: %s [OPTIONS]\n"
  438.             "\n"
  439.             "OPTIONS:\n", prog);
  440.  
  441.     fprintf(stderr,
  442.             "  -d\t\t\tdump all traffic\n"
  443.             "  -D TOKEN[,...]\tturn on debugging output for the specified "
  444.             "TOKENs\n"
  445.             "\t\t\t   (ALL gives extremely verbose debugging output)\n"
  446.             "  -f\t\t\tDo not fork() from the calling shell.\n"
  447.             "  -h\t\t\tdisplay this help message\n"
  448.             "  -H\t\t\tdisplay a list of configuration file directives\n"
  449.             "  -L LOGOPTS\t\tToggle various defaults controlling logging:\n");
  450.     snmp_log_options_usage("\t\t\t  ", stderr);
  451. #ifndef DISABLE_MIB_LOADING
  452.     fprintf(stderr,
  453.             "  -m MIB[:...]\t\tload given list of MIBs (ALL loads "
  454.             "everything)\n"
  455.             "  -M DIR[:...]\t\tlook in given list of directories for MIBs\n");
  456. #endif /* DISABLE_MIB_LOADING */
  457. #ifndef DISABLE_MIB_LOADING
  458.     fprintf(stderr,
  459.             "  -P MIBOPTS\t\tToggle various defaults controlling mib "
  460.             "parsing:\n");
  461.     snmp_mib_toggle_options_usage("\t\t\t  ", stderr);
  462. #endif /* DISABLE_MIB_LOADING */
  463.     fprintf(stderr,
  464.             "  -v\t\t\tdisplay package version number\n"
  465.             "  -x TRANSPORT\tconnect to master agent using TRANSPORT\n");
  466.     exit(1);
  467. }
  468.  
  469. static void
  470. version(void)
  471. {
  472.     fprintf(stderr, "NET-SNMP version: %s\n", netsnmp_get_version());
  473.     exit(0);
  474. }
  475.  
  476. int
  477. main (int argc, char **argv)
  478. {
  479.   int arg;
  480.   char* cp = NULL;
  481.   int dont_fork = 0, do_help = 0;
  482.  
  483.   while ((arg = getopt(argc, argv, "dD:fhHL:"
  484. #ifndef DISABLE_MIB_LOADING
  485.                        "m:M:"
  486. #endif /* DISABLE_MIB_LOADING */
  487.                        "n:"
  488. #ifndef DISABLE_MIB_LOADING
  489.                        "P:"
  490. #endif /* DISABLE_MIB_LOADING */
  491.                        "vx:")) != EOF) {
  492.     switch (arg) {
  493.     case 'd':
  494.       netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
  495.                              NETSNMP_DS_LIB_DUMP_PACKET, 1);
  496.       break;
  497.  
  498.     case 'D':
  499.       debug_register_tokens(optarg);
  500.       snmp_set_do_debugging(1);
  501.       break;
  502.  
  503.     case 'f':
  504.       dont_fork = 1;
  505.       break;
  506.  
  507.     case 'h':
  508.       usage(argv[0]);
  509.       break;
  510.  
  511.     case 'H':
  512.       do_help = 1;
  513.       break;
  514.  
  515.     case 'L':
  516.       if (snmp_log_options(optarg, argc, argv) < 0) {
  517.         exit(1);
  518.       }
  519.       break;
  520.  
  521. #ifndef DISABLE_MIB_LOADING
  522.     case 'm':
  523.       if (optarg != NULL) {
  524.         setenv("MIBS", optarg, 1);
  525.       } else {
  526.         usage(argv[0]);
  527.       }
  528.       break;
  529.  
  530.     case 'M':
  531.       if (optarg != NULL) {
  532.         setenv("MIBDIRS", optarg, 1);
  533.       } else {
  534.         usage(argv[0]);
  535.       }
  536.       break;
  537. #endif /* DISABLE_MIB_LOADING */
  538.  
  539.     case 'n':
  540.       if (optarg != NULL) {
  541.         app_name = optarg;
  542.         netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
  543.                               NETSNMP_DS_LIB_APPTYPE, app_name);
  544.       } else {
  545.         usage(argv[0]);
  546.       }
  547.       break;
  548.  
  549. #ifndef DISABLE_MIB_LOADING
  550.     case 'P':
  551.       cp = snmp_mib_toggle_options(optarg);
  552.       if (cp != NULL) {
  553.         fprintf(stderr, "Unknown parser option to -P: %c.\n", *cp);
  554.         usage(argv[0]);
  555.       }
  556.       break;
  557. #endif /* DISABLE_MIB_LOADING */
  558.  
  559.     case 'v':
  560.       version();
  561.       break;
  562.  
  563.     case 'x':
  564.       if (optarg != NULL) {
  565.         netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
  566.                               NETSNMP_DS_AGENT_X_SOCKET, optarg);
  567.       } else {
  568.         usage(argv[0]);
  569.       }
  570.       break;
  571.  
  572.     default:
  573.       fprintf(stderr, "invalid option: -%c\n", arg);
  574.       usage(argv[0]);
  575.       break;
  576.     }
  577.   }
  578.  
  579.   if (do_help) {
  580.     netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
  581.                            NETSNMP_DS_AGENT_NO_ROOT_ACCESS, 1);
  582.   } else {
  583.     /* we are a subagent */
  584.     netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
  585.                            NETSNMP_DS_AGENT_ROLE, 1);
  586.  
  587.     if (!dont_fork) {
  588.       if (netsnmp_daemonize(1, snmp_stderrlog_status()) != 0)
  589.         exit(1);
  590.     }
  591.  
  592.     /* initialize tcpip, if necessary */
  593.     SOCK_STARTUP;
  594.   }
  595.  
  596.   /* initialize the agent library */
  597.   init_agent(app_name);
  598.  
  599.   /* initialize your mib code here */
  600. EOF
  601.  
  602.     # add init routines
  603.     for i in $cfiles ; do
  604.       name=`basename $i | sed 's/\.[co]$//'`
  605.       echo checking for init_$name in $i
  606.       if grep "init_$name" $i ; then
  607.         echo "  init_${name}();" >> $tmpfile
  608.       fi
  609.       shift
  610.     done
  611.  
  612.     # finish file
  613.     cat >> $tmpfile <<EOF
  614.  
  615.   /* $outname will be used to read $outname.conf files. */
  616.   init_snmp("$outname");
  617.  
  618.   if (do_help) {
  619.     fprintf(stderr, "Configuration directives understood:\n");
  620.     read_config_print_usage("  ");
  621.     exit(0);
  622.   }
  623.  
  624.   /* In case we received a request to stop (kill -TERM or kill -INT) */
  625.   netsnmp_running = 1;
  626. #ifdef SIGTERM
  627.   signal(SIGTERM, stop_server);
  628. #endif
  629. #ifdef SIGINT
  630.   signal(SIGINT, stop_server);
  631. #endif
  632.  
  633.   /* main loop here... */
  634.   while(netsnmp_running) {
  635.     agent_check_and_process(1);
  636.   }
  637.  
  638.   /* at shutdown time */
  639.   snmp_shutdown(app_name);
  640.   SOCK_CLEANUP;
  641.   exit(0);
  642. }
  643.  
  644. EOF
  645.       if test "$?" != 0 -o ! -f "$tmpfile" ; then
  646.         echo "Ack.  Can't create $tmpfile."
  647.     exit 1
  648.       fi
  649.       cmd="gcc $cflags -DNETSNMP_ENABLE_IPV6 -g -O2 -DNETSNMP_USE_INLINE -Ulinux -Dlinux=linux  -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -I/usr/lib/perl/5.10/CORE   -I. -I${NSC_INCLUDEDIR} -o $outname $tmpfile $cfiles $NSC_LDFLAGS $NSC_LIBDIR $NSC_BASE_AGENT_LIBS $NSC_AGENTLIBS $ldflags"
  650.       echo "running: $cmd"
  651.       `$cmd`
  652.       if test "x$norm" != "x1" ; then
  653.         echo "removing the tmporary code file: $tmpfile"
  654.         rm -f $tmpfile
  655.       else
  656.         echo "leaving the tmporary code file: $tmpfile"
  657.       fi
  658.       if test -f $outname ; then
  659.         echo "subagent program $outname created"
  660.       fi
  661.       ;;
  662.  
  663.     *)
  664.       echo "unknown option $1"
  665.       usage="yes"
  666.       ;;
  667.   esac
  668.   if [ "x$shifted" = "x" ] ; then
  669.       shift
  670.   fi
  671.   done
  672. fi
  673.  
  674. if test "x$usage" = "xyes"; then
  675.   echo ""
  676.   echo "Usage:"
  677.   echo "  net-snmp-config [--cflags] [--agent-libs] [--libs] [--version]"
  678.   echo "                  ... [see below for complete flag list]"
  679.   echo ""
  680.   echo "    --version         displays the net-snmp version number"
  681.   echo "    --indent-options  displays the indent options from the Coding Style"
  682.   echo "    --debug-tokens    displays a example command line to search to source"
  683.   echo "                      code for a list of available debug tokens"
  684.   echo ""
  685.   echo "  SNMP Setup commands:"
  686.   echo ""
  687.   echo "    --create-snmpv3-user [-ro] [-A authpass] [-X privpass]"
  688.   echo "                         [-a MD5|SHA] [-x DES|AES] [username]"
  689.   echo ""
  690.   echo "  These options produce the various compilation flags needed when"
  691.   echo "  building external SNMP applications:"
  692.   echo ""
  693.   echo "    --base-lib-cflags lists additional compilation flags needed for linking"
  694.   echo "                      against libsnmp"
  695.   echo "    --base-cflags     lists additional compilation flags needed"
  696.   echo "    --cflags          lists additional compilation flags needed"
  697.   echo "                      (includes -I. and extra developer warning flags)"
  698.   echo ""
  699.   echo "  These options produce the various link flags needed when"
  700.   echo "  building external SNMP applications:"
  701.   echo ""
  702.   echo "    --libs            lists libraries needed for building applications"
  703.   echo "    --agent-libs      lists libraries needed for building subagents"
  704.   echo ""
  705.   echo "  These options produce various link flags broken down into parts."
  706.   echo "  (Most of the time the simple options above should be used.)"
  707.   echo ""
  708.   echo "    --libdir              path to netsnmp libraries"
  709.   echo ""
  710.   echo "    --base-agent-libs     netsnmp specific agent libraries"
  711.   echo ""
  712.   echo "    --netsnmp-libs        netsnmp specific libraries (with path)"
  713.   echo "    --netsnmp-agent-libs  netsnmp specific agent libraries (with path)"
  714.   echo ""
  715.   echo "    --ldflags             link flags for external libraries"
  716.   echo "    --external-libs       external libraries needed by netsnmp libs"
  717.   echo "    --external-agent-libs external libraries needed by netsnmp agent libs"
  718.   echo ""
  719.   echo "  These options produce various link flags used when linking an"
  720.   echo "  external application against an uninstalled build directory."
  721.   echo ""
  722.   echo "    --build-includes      include path to build/source includes"
  723.   echo "    --build-lib-dirs      link path to libraries"
  724.   echo "    --build-lib-deps      path to libraries for dependency target"
  725.   echo ""
  726.   echo "  Automatted subagent building (produces an OUTPUTNAME binary file):"
  727.   echo "  [this feature has not been tested very well yet.  use at your risk.]"
  728.   echo ""
  729.   echo "    --compile-subagent OUTPUTNAME [--norm] [--cflags flags]"
  730.   echo "                                  [--ldflags flags] mibmodule1.c [...]]"
  731.   echo ""
  732.   echo "         --norm           leave the generated .c file around to read."
  733.   echo "         --cflags flags   extra cflags to use (e.g. -I...)."
  734.   echo "         --ldflags flags  extra ld flags to use (e.g. -L... -l...)."
  735.   echo ""
  736.   echo "  Details on how the net-snmp package was compiled:"
  737.   echo ""
  738.   echo "    --configure-options   display original configure arguments"
  739.   echo "    --prefix              display the installation prefix"
  740.   echo "    --snmpd-module-list   display the modules compiled into the agent"
  741.   echo "    --default-mibs        display default list of MIBs"
  742.   echo "    --default-mibdirs     display default list of MIB directories"
  743.   echo "    --snmpconfpath        display default SNMPCONFPATH"
  744.   echo "    --persistent-directory display default persistent directory"
  745.   echo "    --perlprog            display path to perl for the perl modules"
  746.   echo ""
  747.   exit
  748. fi  
  749.