Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / testing / TESTCONF.sh
1 #! /bin/sh -f
2
3 #
4 # Variables:  (* = exported)
5 #  *SNMP_TMPDIR:          place to put files used in testing.
6 #   SNMP_TESTDIR:         where the test scripts are kept.
7 #  *SNMP_PERSISTENT_FILE: where to store the agent's persistent information
8 #                         (XXX: this should be specific to just the agent)
9
10 #
11 # Only allow ourselves to be eval'ed once
12 #
13 if [ "x$TESTCONF_SH_EVALED" != "xyes" ]; then
14     TESTCONF_SH_EVALED=yes
15
16 #
17 # Set up an NL suppressing echo command
18 #
19 case "`echo 'x\c'`" in
20   'x\c')
21     ECHO() { echo -n $*; }
22     ;;
23   x)
24     ECHO() { echo $*\\c; }
25     ;;
26   *)
27     echo "I don't understand your echo command ..."
28     exit 1
29     ;;
30 esac
31 #
32 # how verbose should we be (0 or 1)
33 #
34 if [ "x$SNMP_VERBOSE" = "x" ]; then
35     SNMP_VERBOSE=0
36     export SNMP_VERBOSE
37 fi
38
39 if [ "x$MIBDIRS" = "x" ]; then
40     MIBDIRS=${SNMP_BASEDIR}/../mibs
41     export MIBDIRS
42 fi
43
44 # Set up the path to the programs we want to use.
45 if [ "x$SNMP_PATH" = "x" ]; then
46     PATH=../agent:../apps:../../agent:../../apps:$PATH
47     export PATH
48     SNMP_PATH=yes
49     export SNMP_PATH
50 fi
51     
52
53 # Set up temporary directory
54 if [ "x$SNMP_TMPDIR" = "x" -a "x$SNMP_HEADERONLY" != "xyes" ]; then
55     if [ "x$testnum" = "x" ] ; then
56         testnum=1
57     fi
58     SNMP_TMPDIR="/tmp/snmp-test-$testnum-$$"
59     export SNMP_TMPDIR
60     if [ -d $SNMP_TMPDIR ]; then
61         echo "$0: ERROR: $SNMP_TMPDIR already existed."
62         exit 1;
63     fi
64     mkdir $SNMP_TMPDIR
65 fi
66
67 if [ "x$SNMP_SAVE_TMPDIR" = "x" ]; then
68     SNMP_SAVE_TMPDIR="no"
69     export SNMP_SAVE_TMPDIR
70 fi
71
72 SNMP_TESTDIR="$SNMP_BASEDIR/tests"
73 SNMP_CONFIG_FILE="$SNMP_TMPDIR/snmpd.conf"
74 SNMPTRAPD_CONFIG_FILE="$SNMP_TMPDIR/snmptrapd.conf"
75 SNMP_SNMPTRAPD_LOG_FILE="$SNMP_TMPDIR/snmptrapd.log"
76 SNMP_SNMPTRAPD_PID_FILE="$SNMP_TMPDIR/snmptrapd.pid"
77 SNMP_SNMPD_PID_FILE="$SNMP_TMPDIR/snmpd.pid"
78 SNMP_SNMPD_LOG_FILE="$SNMP_TMPDIR/snmpd.log"
79 SNMP_PERSISTENT_FILE="$SNMP_TMPDIR/persistent-store.conf"
80 export SNMP_PERSISTENT_FILE
81
82 ## Setup default flags and ports iff not done
83 if [ "x$SNMP_FLAGS" = "x" ]; then
84     SNMP_FLAGS="-d"
85 fi
86
87 BASE_PORT=8765
88 MAX_RETRIES=3
89 if test -x /bin/netstat ; then
90     NETSTAT=/bin/netstat
91 elif test -x /usr/bin/netstat ; then
92     NETSTAT=/usr/bin/netstat
93 else
94     NETSTAT=""
95 fi
96 if test -x $NETSTAT ; then
97     if test -z "$RANDOM"; then
98         RANDOM=2
99     fi
100     while :
101     do
102         IN_USE=`$NETSTAT -a 2>/dev/null | grep "[\.:]$BASE_PORT "`
103         if [ $? -eq 0 ]; then
104             #echo "Port $BASE_PORT in use:"
105             #echo "->$IN_USE"
106             BASE_PORT=`expr $BASE_PORT + \( $RANDOM % 100 \)`
107         else
108             #echo "Using port $BASE_PORT"
109             break
110         fi
111         MAX_RETRIES=`expr $MAX_RETRIES - 1`
112         if [ $MAX_RETRIES -eq 0 ]; then
113             echo "ERROR: Could not find available port."
114             exit 255
115         fi
116     done
117 fi
118
119 if [ "x$SNMP_SNMPD_PORT" = "x" ]; then
120     SNMP_SNMPD_PORT=$BASE_PORT
121 fi
122
123 if [ "x$SNMP_SNMPTRAPD_PORT" = "x" ]; then
124     SNMP_SNMPTRAPD_PORT=`expr $BASE_PORT - 1`
125 fi
126 export SNMP_FLAGS SNMP_SNMPD_PORT SNMP_SNMPTRAPD_PORT
127
128 # Make sure the agent doesn't parse any config file but what we give it.  
129 # this is mainly to protect against a broken agent that doesn't
130 # properly handle combinations of -c and -C.  (since I've broke it before).
131 SNMPCONFPATH="$SNMP_TMPDIR/does-not-exist"
132 export SNMPCONFPATH
133
134 fi # Only allow ourselves to be eval'ed once