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