make snmpd uci aware, Signed-off-by: Frdric Moulins <ffrrrr@gmail.com>
[openwrt/svn-archive/archive.git] / libs / net-snmp / files / snmpd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
3 START=50
4
5 DEFAULT=/etc/default/snmpd
6 LIB_D=/var/lib/snmp
7 LOG_D=/var/log
8 RUN_D=/var/run
9 PID_F=$RUN_D/snmpd.pid
10 RUN_C=$RUN_D/snmpd.conf
11
12 snmpd_com2sec_add() {
13 local cfg="$1"
14 config_get secname "$cfg" secname
15 [ -n "$secname" ] || return 0
16 config_get source "$cfg" source
17 [ -n "$source" ] || return 0
18 config_get community "$cfg" community
19 [ -n "$community" ] || return 0
20 echo "com2sec $secname $source $community" >> $RUN_C
21 }
22 snmpd_group_add() {
23 local cfg="$1"
24 config_get group "$cfg" group
25 [ -n "$group" ] || return 0
26 config_get version "$cfg" version
27 [ -n "$version" ] || return 0
28 config_get secname "$cfg" secname
29 [ -n "$secname" ] || return 0
30 echo "group $group $version $secname" >> $RUN_C
31 }
32 snmpd_view_add() {
33 local cfg="$1"
34 config_get viewname "$cfg" viewname
35 [ -n "$viewname" ] || return 0
36 config_get type "$cfg" type
37 [ -n "$type" ] || return 0
38 config_get oid "$cfg" oid
39 [ -n "$oid" ] || return 0
40 # optional mask
41 config_get mask "$cfg" mask
42 echo "view $viewname $type $oid $mask" >> $RUN_C
43 }
44 snmpd_access_add() {
45 local cfg="$1"
46 config_get group "$cfg" group
47 [ -n "$group" ] || return 0
48 config_get context "$cfg" context
49 [ -n $context ] || return 0
50 [ "$context" == "none" ] && context='""'
51 config_get version "$cfg" version
52 [ -n "$version" ] || return 0
53 config_get level "$cfg" level
54 [ -n "$level" ] || return 0
55 config_get prefix "$cfg" prefix
56 [ -n "$prefix" ] || return 0
57 config_get read "$cfg" read
58 [ -n "$read" ] || return 0
59 config_get write "$cfg" write
60 [ -n "$write" ] || return 0
61 config_get notify "$cfg" notify
62 [ -n "$notify" ] || return 0
63 echo "access $group $context $version $level $prefix $read $write $notify" >> $RUN_C
64 }
65 snmpd_pass_add() {
66 local cfg="$1"
67 local pass='pass'
68
69 config_get miboid "$cfg" miboid
70 [ -n "$miboid" ] || return 0
71 config_get prog "$cfg" prog
72 [ -n "$prog" ] || return 0
73 config_get_bool persist "$cfg" persist 0
74 [ $persist -ne 0 ] && pass='pass_persist'
75 config_get priority "$cfg" priority
76 priority=${priority:+-p $priority}
77 echo "$pass $priority $miboid $prog" >> $RUN_C
78 }
79 start() {
80 [ -d $LIB_D ] || mkdir -p $LIB_D
81 [ -d $LOG_D ] || mkdir -p $LOG_D
82 [ -d $RUN_D ] || mkdir -p $RUN_D
83 [ -f $RUN_C ] && rm -f $RUN_C
84
85 config_load snmpd
86
87 config_foreach snmpd_com2sec_add com2sec
88 config_foreach snmpd_group_add group
89 config_foreach snmpd_view_add view
90 config_foreach snmpd_access_add access
91 config_foreach snmpd_pass_add pass
92
93 [ -f $DEFAULT ] && . $DEFAULT
94 $DEBUG /usr/sbin/snmpd $OPTIONS
95 }
96 stop() {
97 [ -f $PID_F ] && kill $(cat $PID_F)
98 [ -f $RUN_C ] && rm -f $RUN_C
99 }