#!/sbin/sh # # Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. # . /lib/svc/share/smf_include.sh # # Establish PATH for non-built in commands # export PATH=/usr/bin:/usr/sbin # SMF properties associated with unconfig PROP_UNCONFIG_EXEC="unconfigure/exec" PROP_CONFIG_UNCONFIG_GRPS="sysconfig/unconfig_groups" PROP_CONFIG_CONFIG="sysconfig/configure" PROP_CONFIG_SHUTDOWN="sysconfig/shutdown" PROP_CONFIG_UNCONFIG="sysconfig/unconfigure" PROP_CONFIG_DESTRUCTIVE="sysconfig/destructive_unconfig" PROP_CONFIG_INCLUDE_SITE="sysconfig/include_site" PROP_CONFIG_RECONFIG="sysconfig/reconfigurable" PROP_RESTARTER_LOGFILE="restarter/logfile" PROP_SYSCONFIG_GROUP="sysconfig/group" # default value for unconfigured properties SMF_UNCONFIGURED_VALUE="" SHUTDOWN="/usr/sbin/shutdown" SVCADM="/usr/sbin/svcadm" SVCCFG="/usr/sbin/svccfg" SVCPROP="/usr/bin/svcprop" SED="/usr/bin/sed" SERVICE="svc:/milestone/unconfig" CONFIG_SERVICE="svc:/milestone/config:default" # smf profile to enable the SCI tool upon reboot CONFIG_XML_SRC=/usr/share/auto_install/sc_profiles/enable_sci.xml # # Binary tested for determining if we are in ROZR zone booted in ready-only # mode. # ROZR_TEST_BINARY="/sbin/sh" ROZR_ERR_MSG="\nDetected ROZR zone booted in read-only mode. System \ Configuration not permitted.\nPlease refer to mwac(5) man page \ for additional information.\n" # Path to valid_groups.py for comparison to sysconfig/unconfig_groups VALID_GROUPS=/usr/lib/python2.7/vendor-packages/solaris_install/sysconfig/valid_groups.py # # get_smf_prop() # # Description: # Retrieve value of SMF property. # For 'astring' type of property, take care of removing quoting # backslashes, # since according to svcprop(1) man page, shell metacharacters # (';', '&', '(', ')', '|', '^', '<', '>', newline, space, tab, # backslash, # '"', single-quote, '`') are quoted by backslashes (\). # # Parameters: # $1 - SMF property name # # Returns: # 0 - property was configured in SC manifest # 1 - property was not configured in SC manifest # get_smf_prop() { typeset prop_name="$1" typeset service_name="$2" typeset prop_value typeset prop_type # retrieve property. prop_value=$($SVCPROP -p "$prop_name" "$service_name") if (( $? != 0 )); then print -u2 "Failed to obtain value of <$prop_name> property" \ "which is suspicious, defaulting to" \ "<$SMF_UNCONFIGURED_VALUE>." print -u1 $SMF_UNCONFIGURED_VALUE return 1 fi # for 'astring' type, remove backslashes from quoted metacharacters prop_type=$($SVCPROP -p "$prop_name" -t "$service_name" | nawk '{ print $2 }') if [[ "$prop_type" == "astring" ]] ; then prop_value=$(print $prop_value | $SED -e 's/\\//g') if (( $? != 0 )) ; then print -u2 "Failed when trying to remove '\' from" \ "<$prop_name> property, defaulting to" \ "<$SMF_UNCONFIGURED_VALUE>." print -u1 $SMF_UNCONFIGURED_VALUE return 1 fi # # Since according to svcprop(1) man page empty ASCII string # value is presented as a pair of double quotes (""), we need # to check for this combination and replace it with an empty # string. # [[ "$prop_value" == '""' ]] && prop_value="" fi print -u1 "$prop_value" return 0 } exec_unconfigure_method(){ typeset reconfig=false typeset destruct=false groupings=$(get_smf_prop $PROP_CONFIG_UNCONFIG_GRPS $SERVICE) # If grouping is not provided, fatal error. if [[ -z "$groupings" ]]; then # clear all administrative customizations for this service $SVCCFG -s $SERVICE delcust $SVCCFG -s $SERVICE refresh exit $SMF_EXIT_ERR_FATAL fi # # Initialize UNCONFIG_DESTRUCTIVE environment variable passed # to unconfigure methods. It is set to true if destructive # unconfiguration is requried, otherwise it is set to false. # destruct=$(get_smf_prop $PROP_CONFIG_DESTRUCTIVE $SERVICE) if [[ $? == 0 && "$destruct" == "true" ]]; then UNCONFIG_DESTRUCTIVE=true else UNCONFIG_DESTRUCTIVE=false fi export UNCONFIG_DESTRUCTIVE do_config=$(get_smf_prop $PROP_CONFIG_CONFIG $CONFIG_SERVICE) for group in $groupings; do # extract all the services belonging to this group svc_list=$($SVCPROP -p $PROP_SYSCONFIG_GROUP \* 2>/dev/null \ | grep $group | nawk -F "/:properties" '{print $1'}) for u_svc in $svc_list; do exec_method=$(get_smf_prop $PROP_UNCONFIG_EXEC $u_svc) if [[ -z "$exec_method" ]]; then # the service does not have an # exec_method, so continue continue fi if $do_config ; then reconfig=$(get_smf_prop $PROP_CONFIG_RECONFIG $u_svc) if [ $? -eq 0 ]; then if $reconfig ; then continue fi fi fi # Get the logfile for the svc svc_logfile=$(get_smf_prop $PROP_RESTARTER_LOGFILE $u_svc) # Run the unconfigure method for the service if [ $? -ne 0 ] ; then SMF_FMRI=$u_svc $exec_method else SMF_FMRI=$u_svc $exec_method >> $svc_logfile 2>&1 fi if [ $? -ne 0 ]; then msg="Unconfiguration failed for $u_svc" echo $msg | smf_console fi done done } unconfigure_services() { # Find the services with an unconfigure method exec_unconfigure_method # Save status of shutdown property before we clean up # configuration. shutdown=$(get_smf_prop $PROP_CONFIG_SHUTDOWN $SERVICE) # clear all administrative customizations for this service $SVCCFG -s $SERVICE delcust $SVCCFG -s $SERVICE refresh if $shutdown; then print -u1 "Shutting down system" $SHUTDOWN -y -g 30 -i 5 fi } case "$1" in 'start') # extract possible values from the service before delcust is called do_unconfig=$(get_smf_prop $PROP_CONFIG_UNCONFIG $SERVICE) do_config=$(get_smf_prop $PROP_CONFIG_CONFIG $CONFIG_SERVICE) include_site=$(get_smf_prop $PROP_CONFIG_INCLUDE_SITE $SERVICE) groupings=$(get_smf_prop $PROP_CONFIG_UNCONFIG_GRPS $SERVICE) if $do_unconfig; then # Unconfiguration not permitted in ROZR zone booted in # read-only mode. if [[ ! -w "$ROZR_TEST_BINARY" ]] ; then # clear all administrative customizations for # this service $SVCCFG -s $SERVICE delcust $SVCCFG -s $SERVICE refresh print -u1 "$ROZR_ERR_MSG" | smf_console exit $SMF_EXIT_ERR_FATAL fi # check to see if we need to clean the repository if $include_site; then # call cleanup to make sure the repository knows about # any removed profiles $SVCCFG cleanup -a fi unconfigure_services if $do_config; then $SVCADM milestone all # Sleep 3 seconds to allow graph to settle and prevent # svc.startd from prematurely invoking sulogin sleep 3 else /usr/bin/python2.7 $VALID_GROUPS "${groupings}" if [ $? -eq 0 ]; then # the groupings match 'system' for this zone. # Apply the default enable_sci.xml profile # from a non-standard location to bring in the # customizations at the admin layer $SVCCFG apply $CONFIG_XML_SRC $SVCCFG -s $CONFIG_SERVICE refresh fi print -u1 " " | smf_console print -u1 "System is unconfigured." | smf_console print -u1 "Login as root user at the prompt for" \ "system maintenance." | smf_console print -u1 "To configure the system, " \ "reboot." | smf_console print -u1 " " | smf_console fi fi ;; *) echo "Usage: $0 { start }" exit $SMF_EXIT_ERR_FATAL ;; esac exit $SMF_EXIT_OK