#!/bin/sh
##
## Simple SNMP Agent. This file only does the startup. All MIB
## implementations are done in extra files that are sourced from
## this file.
##
## Copyright (c) 1994
##
## J. Schoenwaelder
## TU Braunschweig, Germany
## Institute for Operating Systems and Computer Networks
##
## Permission to use, copy, modify, and distribute this
## software and its documentation for any purpose and without
## fee is hereby granted, provided that this copyright
## notice appears in all copies.  The University of Braunschweig
## makes no representations about the suitability of this
## software for any purpose.  It is provided "as is" without
## express or implied warranty.

# Tcl sees the next lines as an assignment to variable `kludge'.
# For sh, the two shifts cancel the effect of the set, and then we
# run scotty on this script.

set kludge { $*
    shift
    shift
    if test -x ../scotty -a -f ../scotty ; then
      exec ../scotty -nf $0 $*
    else
      exec scotty -nf $0 $*
    fi
}

##
## Report all errors to standard error including the complete backtrace.
##

proc scottyerror { msg } {
    global errorInfo
    puts stderr "$msg\n$errorInfo"
}

##
## Load all the MIB code that this agent should support.
##

proc include {name} {
    global scotty_lib
    if {[file readable $name]} {
	set file $name
    } elseif {[file readable $name.tcl]} {
	set file $name.tcl
    } elseif {[file readable $scotty_lib/$name]} {
	set file $scotty_lib/$name
    } elseif {[file readable $scotty_lib/$name.tcl]} {
	set file $scotty_lib/$name.tcl
    } else {
	puts stderr "$name not included -- file not found"
	return
    }
    uplevel #0 source $file
    puts stdout "-> $name included using file $file"
}

##
## Add all MIB definitions to include here.
##

include tubs
include mlm

##
## Startup the agent on port 1701 (the mystic default port).
##

set s [snmp session]
if {[catch {$s agent} err]} {
    puts stderr "Failed to setup SNMP agent: $err"
    exit 42
}

puts stdout "\nagent started using the following parameters:\n[$s configure]"

