1*5307Sjacobs#!/bin/sh
2*5307Sjacobs#
3*5307Sjacobs# CDDL HEADER START
4*5307Sjacobs#
5*5307Sjacobs# The contents of this file are subject to the terms of the
6*5307Sjacobs# Common Development and Distribution License (the "License").
7*5307Sjacobs# You may not use this file except in compliance with the License.
8*5307Sjacobs#
9*5307Sjacobs# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*5307Sjacobs# or http://www.opensolaris.org/os/licensing.
11*5307Sjacobs# See the License for the specific language governing permissions
12*5307Sjacobs# and limitations under the License.
13*5307Sjacobs#
14*5307Sjacobs# When distributing Covered Code, include this CDDL HEADER in each
15*5307Sjacobs# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*5307Sjacobs# If applicable, add the following below this CDDL HEADER, with the
17*5307Sjacobs# fields enclosed by brackets "[]" replaced with your own identifying
18*5307Sjacobs# information: Portions Copyright [yyyy] [name of copyright owner]
19*5307Sjacobs#
20*5307Sjacobs# CDDL HEADER END
21*5307Sjacobs#
22*5307Sjacobs#
23*5307Sjacobs# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24*5307Sjacobs# Use is subject to license terms.
25*5307Sjacobs
26*5307Sjacobs#
27*5307Sjacobs# ident	"%Z%%M%	%I%	%E% SMI"
28*5307Sjacobs
29*5307Sjacobs. /lib/svc/share/smf_include.sh
30*5307Sjacobs
31*5307SjacobsMETHOD=${1}
32*5307SjacobsINSTANCE=${2}
33*5307Sjacobs
34*5307SjacobsDBUS_DESTINATION="org.freedesktop.Hal"
35*5307SjacobsMESSAGE_PREFIX="org.freedesktop.Hal.Device.NetworkDiscovery"
36*5307SjacobsOBJECT_PATH="/org/freedesktop/Hal/devices/network_attached"
37*5307SjacobsSMF_PROPERTY_GROUP="config"
38*5307SjacobsHAL_PROPERTY_GROUP="network_discovery"
39*5307SjacobsSVCS=/usr/bin/svcs
40*5307Sjacobs
41*5307Sjacobsusage() {
42*5307Sjacobs	echo "Usage: $0 { start | stop | refresh } { snmp }"
43*5307Sjacobs	exit $SMF_EXIT_ERR_FATAL
44*5307Sjacobs}
45*5307Sjacobs
46*5307Sjacobsexecute() {
47*5307Sjacobs	echo "$*"
48*5307Sjacobs	$*
49*5307Sjacobs
50*5307Sjacobs	return $?
51*5307Sjacobs}
52*5307Sjacobs
53*5307Sjacobsstart_snmp() {
54*5307Sjacobs	interval=`/bin/svcprop -p config/interval ${SMF_FMRI} 2>/dev/null`
55*5307Sjacobs	community=`/bin/svcprop -p config/community ${SMF_FMRI} 2>/dev/null`
56*5307Sjacobs	network=`/bin/svcprop -p config/network ${SMF_FMRI} 2>/dev/null`
57*5307Sjacobs	MESSAGE="${MESSAGE_PREFIX}.EnablePrinterScanningViaSNMP"
58*5307Sjacobs	MESSAGE="${MESSAGE} int32:${interval:-60}"
59*5307Sjacobs	MESSAGE="${MESSAGE} string:${community:-public}"
60*5307Sjacobs	MESSAGE="${MESSAGE} string:${network:-0.0.0.0}"
61*5307Sjacobs
62*5307Sjacobs	execute /usr/bin/dbus-send --system --print-reply \
63*5307Sjacobs		--dest=${DBUS_DESTINATION} --type=method_call ${OBJECT_PATH} \
64*5307Sjacobs		${MESSAGE}
65*5307Sjacobs	return $?
66*5307Sjacobs}
67*5307Sjacobs
68*5307Sjacobsstop_snmp() {
69*5307Sjacobs	MESSAGE="${MESSAGE_PREFIX}.DisablePrinterScanningViaSNMP"
70*5307Sjacobs
71*5307Sjacobs	execute /usr/bin/dbus-send --system --print-reply \
72*5307Sjacobs		--dest=${DBUS_DESTINATION} --type=method_call ${OBJECT_PATH} \
73*5307Sjacobs		${MESSAGE}
74*5307Sjacobs	return $?
75*5307Sjacobs}
76*5307Sjacobs
77*5307Sjacobsrefresh_snmp() {
78*5307Sjacobs	community=`/bin/svcprop -p config/community ${SMF_FMRI} 2>/dev/null`
79*5307Sjacobs	network=`/bin/svcprop -p config/network ${SMF_FMRI} 2>/dev/null`
80*5307Sjacobs	MESSAGE="${MESSAGE_PREFIX}.EnablePrinterScanningViaSNMP"
81*5307Sjacobs	MESSAGE="${MESSAGE} string:${community:-public}"
82*5307Sjacobs	MESSAGE="${MESSAGE} string:${network:-0.0.0.0}"
83*5307Sjacobs
84*5307Sjacobs	execute /usr/bin/dbus-send --system --print-reply \
85*5307Sjacobs		--dest=${DBUS_DESTINATION} --type=method_call ${OBJECT_PATH} \
86*5307Sjacobs		${MESSAGE}
87*5307Sjacobs	return $?
88*5307Sjacobs}
89*5307Sjacobs
90*5307Sjacobscase "${METHOD}" in
91*5307Sjacobs	'start')
92*5307Sjacobs		;;
93*5307Sjacobs	'stop')
94*5307Sjacobs		count=`$SVCS -o STATE hal 2>>/dev/null | grep -c "^online"`
95*5307Sjacobs		if [ $count -eq 0 ] ; then
96*5307Sjacobs			exit 0	# if HAL isn't running, there is nothing to do
97*5307Sjacobs		fi
98*5307Sjacobs		;;
99*5307Sjacobs	'refresh')
100*5307Sjacobs		;;
101*5307Sjacobs	*)
102*5307Sjacobs		usage
103*5307Sjacobs		;;
104*5307Sjacobsesac
105*5307Sjacobs
106*5307Sjacobscase "${INSTANCE}" in
107*5307Sjacobs	'snmp')
108*5307Sjacobs		;;
109*5307Sjacobs	*)
110*5307Sjacobs		usage
111*5307Sjacobs		;;
112*5307Sjacobsesac
113*5307Sjacobs
114*5307Sjacobs${METHOD}_${INSTANCE}
115*5307Sjacobsexit_code=$?
116*5307Sjacobs
117*5307Sjacobsexit $exit_code
118