Home | History | Annotate | Download | only in shell
      1 #!/bin/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 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     23 # Use is subject to license terms.
     24 #
     25 
     26 DT_CHANGED=0
     27 
     28 LOG_FMRI=svc:/system/system-log
     29 CMSD_FMRI=svc:/network/rpc/cde-calendar-manager
     30 BIND_FMRI=svc:/network/rpc/bind
     31 XSERVER_FMRI=svc:/application/x11/x11-server
     32 SENDMAIL_FMRI=svc:/network/smtp:sendmail
     33 PRINTSERVER_FMRI=svc:/application/print/server
     34 RFC1179_FMRI=svc:/application/print/rfc1179
     35 CUPSSERVER_FMRI=svc:/application/cups/scheduler
     36 CUPSRFC1179_FMRI=svc:/application/cups/in-lpd
     37 IPPLISTENER_FMRI=svc:/application/print/ipp-listener
     38 TTDB_FMRI=svc:/network/rpc/cde-ttdbserver
     39 DTLOGIN_FMRI=svc:/application/graphical-login/cde-login
     40 WEBCONSOLE_FMRI=svc:/system/webconsole
     41 SMCWBEM_FMRI=svc:/application/management/wbem
     42 
     43 usage()
     44 {
     45 	prog=`basename $0`
     46 	echo "$prog: usage: $prog [ open | limited ]" >&2
     47 	exit 2
     48 }
     49 
     50 #
     51 # set_property fmri group property value
     52 #
     53 # sets the specified property in the specified property-group, creating
     54 # the group and or property if necessary.
     55 #
     56 set_property()
     57 {
     58 	fmri=$1
     59 	group=$2
     60 	prop=$3
     61 	val=$4
     62 
     63 	if svcprop -qp $group $fmri; then :; else
     64 		if svccfg -s $fmri addpg $group application; then :; else
     65 			echo "Failed to create property group \"$group\" \c"
     66 			echo "for $fmri."
     67 			exit 1
     68 		fi
     69 	fi
     70 
     71 	if svccfg -s $fmri setprop $group/$prop = boolean: $val; then :; else
     72 		echo "Failed to set property $group/$prop for $fmri"
     73 		exit 1
     74 	fi
     75 }
     76 
     77 set_system_log()
     78 {
     79 	svcprop -q $LOG_FMRI || return 
     80 	if [ "$1" = "local" ]; then
     81 		val=false
     82 	else
     83 		val=true
     84 	fi
     85 
     86 	set_property $LOG_FMRI config log_from_remote $val
     87 	svcadm refresh $LOG_FMRI
     88 }
     89 
     90 set_cmsd()
     91 {
     92 	svcprop -q $CMSD_FMRI:default || return
     93 	if [ "$1" = "local" ]; then
     94 		proto="ticlts"
     95 	else
     96 		proto="udp"
     97 	fi
     98 
     99 	inetadm -m $CMSD_FMRI:default proto=$proto
    100 	svcadm refresh $CMSD_FMRI:default
    101 }
    102 
    103 set_rpcbind()
    104 {
    105 	svcprop -q $BIND_FMRI || return
    106 	if [ "$1" = "local" ]; then
    107 		val=true
    108 	else
    109 		val=false
    110 	fi
    111 
    112 	set_property $BIND_FMRI config local_only $val
    113 	svcadm refresh $BIND_FMRI
    114 }
    115 
    116 set_xserver() {
    117 	svcprop -q $XSERVER_FMRI || return
    118 	if [ "$1" = "local" ]; then
    119 		val=false
    120 	else
    121 		val=true
    122 	fi
    123 
    124 	set_property $XSERVER_FMRI options tcp_listen $val
    125 	# don't need refresh since x11-server is not an actual service
    126 }
    127 
    128 set_sendmail()
    129 {
    130 	svcprop -q $SENDMAIL_FMRI || return
    131 	if [ "$1" = "local" ]; then
    132 		val=true
    133 	else
    134 		val=false
    135 	fi
    136 
    137 	set_property $SENDMAIL_FMRI config local_only $val
    138 	svcadm refresh $SENDMAIL_FMRI
    139 }
    140 
    141 set_ttdbserver()
    142 {
    143 	svcprop -q $TTDB_FMRI:tcp || return
    144 	if [ "$1" = "local" ]; then
    145 		val=ticotsord
    146 	else
    147 		val=tcp
    148 	fi
    149 	inetadm -m $TTDB_FMRI:tcp proto="$val"
    150 	svcadm refresh $TTDB_FMRI:tcp
    151 }
    152 
    153 set_dtlogin()
    154 {
    155 	svcprop -q $DTLOGIN_FMRI || return
    156 
    157 	eval args=`svcprop -p dtlogin/args $DTLOGIN_FMRI`
    158 
    159 	if echo $args | egrep -s udpPort 
    160 	then
    161 		old_port=`echo $args |
    162 		    sed 's/.*-udpPort [ ]*\([0-9][0-9]*\).*/\1/'`
    163 		new_args=`echo $args |
    164 		    sed 's/\(.*\)-udpPort [0-9][0-9]*\(.*\)/\1\2/'`
    165 	else
    166 		old_port=-1
    167 		new_args=$args
    168 	fi
    169 
    170 	if [ "$1" = "local" ]; then
    171 		args="$new_args -udpPort 0"
    172 		DT_CHANGED=1
    173 	else
    174 		# remove '-udpPort 0' argument. Leave intact if port != 0.
    175 		if [ $old_port -eq 0 ]; then
    176 			args="$new_args"
    177 			DT_CHANGED=1
    178 		fi
    179 	fi
    180 
    181 	svccfg -s $DTLOGIN_FMRI setprop dtlogin/args = "\"$args\""
    182 	svcadm refresh $DTLOGIN_FMRI
    183 }
    184 
    185 set_webconsole() {
    186 	svcprop -q $WEBCONSOLE_FMRI:console || return
    187 	if [ "$1" = "local" ]; then
    188 		val=false
    189 	else
    190 		val=true
    191 	fi
    192 
    193 	set_property $WEBCONSOLE_FMRI options tcp_listen $val
    194 	svcadm refresh $WEBCONSOLE_FMRI
    195 }
    196 
    197 set_smcwbem() {
    198 	svcprop -q $SMCWBEM_FMRI:default || return
    199 	if [ "$1" = "local" ]; then
    200 		val=false
    201 	else
    202 		val=true
    203 	fi
    204 
    205 	set_property $SMCWBEM_FMRI options tcp_listen $val
    206 	svcadm refresh $SMCWBEM_FMRI
    207 }
    208 
    209 set_printing() {
    210 	use_cups=`svcprop -C -p general/active $CUPSSERVER_FMRI:default \
    211 		  2>/dev/null`
    212 
    213 	case "$1" in
    214 	"open")
    215 		cups_options="--remote-admin --remote-printers"
    216 		cups_options="$cups_options --share-printers --remote-any"
    217 		svc_operation="enable"
    218 		;;
    219 	"local")
    220 		cups_options="--no-remote-admin --no-remote-printers"
    221 		cups_options="$cups_options --no-share-printers --no-remote-any"
    222 		svc_operation="disable"
    223 		;;
    224 	esac
    225 
    226 	case "$use_cups" in
    227 	"true")
    228 		if [ -x /usr/sbin/cupsctl ] ; then
    229 			# only run cupsctl with elevated privilege to avoid
    230 			# being prompted for a password
    231 			[ `/usr/bin/id -u` = 0 ] && 
    232 				/usr/sbin/cupsctl $cups_options
    233 		fi
    234 		svcadm $svc_operation $CUPSRFC1179_FMRI
    235 		;;
    236 	*)
    237 		if [ "`svcprop -p restarter/state $PRINTSERVER_FMRI:default`" \
    238 		     != "disabled" ] ; then
    239 			svcadm $svc_operation $RFC1179_FMRI:default
    240 			svcadm $svc_operation $IPPLISTENER_FMRI:default
    241 		fi
    242 		;;
    243 	esac
    244 }
    245 
    246 if [ $# -ne 1 ]; then
    247 	usage
    248 fi
    249 
    250 case $1 in
    251 	"open")
    252 		profile=generic_open.xml
    253 		keyword="open"
    254 		;;
    255 	"limited")
    256 		profile=generic_limited_net.xml
    257 		keyword="local"
    258 		;;
    259 	*)
    260 		usage
    261 		;;
    262 esac
    263 
    264 if [ ! -f /var/svc/profile/$profile ]; then
    265 	echo "/var/svc/profile/$profile nonexistent. Exiting."
    266 	exit 1
    267 fi
    268 
    269 #
    270 # set services
    271 #
    272 set_system_log $keyword
    273 set_cmsd $keyword
    274 set_rpcbind $keyword
    275 set_xserver $keyword
    276 set_sendmail $keyword
    277 set_ttdbserver $keyword
    278 set_dtlogin $keyword
    279 set_webconsole $keyword
    280 set_smcwbem $keyword
    281 set_printing $keyword
    282 
    283 #
    284 # put the new profile into place, and apply it
    285 #
    286 ln -sf ./$profile /var/svc/profile/generic.xml
    287 svccfg apply /var/svc/profile/generic.xml
    288 
    289 #
    290 # Create a hash entry so that manifest_import is aware of the
    291 # profile being applied and does not reapply the profile on reboot.
    292 #
    293 SVCCFG_CHECKHASH="TRUE" /lib/svc/bin/prophist hash /var/svc/profile/generic.xml
    294 if [ $profile = "generic_open.xml" ]
    295 then
    296 	# generic_open may not start inetd services on upgraded systems
    297 	svccfg apply /var/svc/profile/inetd_generic.xml
    298 fi
    299 
    300 #
    301 # Make the services aware of the new property values
    302 #
    303 if [ "`svcprop -p restarter/state $LOG_FMRI:default`" = "online" ]
    304 then
    305 	# need restart since refresh won't reread properties
    306 	echo "restarting syslogd"
    307 	svcadm restart $LOG_FMRI:default
    308 fi
    309 
    310 if [ "`svcprop -p restarter/state $SENDMAIL_FMRI`" = "online" ]
    311 then
    312 	# need restart since refresh won't pick up new command-line
    313 	echo "restarting sendmail"
    314 	svcadm restart $SENDMAIL_FMRI
    315 fi
    316 
    317 if [ "`svcprop -p restarter/state $SMCWBEM_FMRI:default`" = "online" ]
    318 then
    319 	# need restart since refresh won't pick up new command-line
    320 	echo "restarting wbem"
    321 	svcadm restart $SMCWBEM_FMRI:default
    322 fi
    323 
    324 if [ $DT_CHANGED -eq 1 ]; then
    325 	if [ "`svcprop -p restarter/state $DTLOGIN_FMRI:default`" = "online" ]
    326 	then
    327 		r="y"
    328 		if tty -s ; then
    329 			printf \
    330 			    "dtlogin needs to be restarted. Restart now? [Y] "
    331 			read r
    332 		fi
    333 		if [ "$r" = "" -o "$r" = "y" -o "$r" = "Y" ]; then
    334 			# Make sure we survive killing dtlogin...
    335 			trap "" 15
    336 			svcadm restart $DTLOGIN_FMRI 
    337 			echo "restarting dtlogin"
    338 		else
    339 			printf "dtlogin not restarted. "
    340 			printf "Restart it to put it in ${keyword}-mode.\n"
    341 		fi
    342 	fi
    343 fi
    344