svc-gconf-multi-user-desktop revision 20777
20907N/A#!/usr/bin/ksh -p
20907N/A#
20907N/A# CDDL HEADER START
20907N/A#
20907N/A# The contents of this file are subject to the terms of the
20907N/A# Common Development and Distribution License (the "License").
20907N/A# You may not use this file except in compliance with the License.
20907N/A#
20907N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
20907N/A# or http://www.opensolaris.org/os/licensing.
20907N/A# See the License for the specific language governing permissions
20907N/A# and limitations under the License.
20907N/A#
20907N/A# When distributing Covered Code, include this CDDL HEADER in each
20907N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
20907N/A# If applicable, add the following below this CDDL HEADER, with the
20907N/A# fields enclosed by brackets "[]" replaced with your own identifying
20907N/A# information: Portions Copyright [yyyy] [name of copyright owner]
20907N/A#
20907N/A# CDDL HEADER END
20907N/A#
20907N/A# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
20907N/A# Use is subject to license terms.
20907N/A
20907N/A# Load SMF constants and functions
12724N/A. /lib/svc/share/smf_include.sh
20907N/A
20907N/AGCONF_DEFAULTS_VALUES="/usr/share/multi-user-desktop/gconf-defaults-optimizations.xml"
20907N/AGCONF_MANDATORY_VALUES="/usr/share/multi-user-desktop/gconf-mandatory-optimizations.xml"
20907N/AGCONF_DEFAULTS_DIR="/etc/gconf/gconf.xml.multi.user.desktop.defaults"
20907N/AGCONF_MANDATORY_DIR="/etc/gconf/gconf.xml.multi.user.desktop.mandatory"
20907N/A
20907N/A# The version of the GConf settings is installed by the GCONF_MANDATORY_VALUES schema
20907N/A# in the GConf path: /desktop/gnome/multi-user-desktop/version
20907N/A# When updating package associated with this script the version from the previously
20907N/A# installed GConf path may differ from this script, then the settings are removed and
20907N/A# re-applied.
12723N/AMULTI_USER_VERSION=1
20907N/A
20907N/AGCONF_TOOL="/usr/bin/gconftool-2"
20907N/AGCONF_MULTI_USER_VERSION="/desktop/gnome/multi-user-desktop/version"
20907N/A
20907N/A
20907N/Aif [[ -z "$SMF_FMRI" ]]; then
20907N/A print "This script can only be invoked by smf(5)"
20907N/A exit $SMF_EXIT_ERR_NOSMF
20907N/Afi
20907N/A
20907N/A# NAME
20907N/A# is_folder_empty
20907N/A#
20907N/A# ARGUMENTS
20907N/A# arg1 - path to the folder
20907N/A#
12723N/A# DESCRIPTION
20907N/A# Checks if folder is empty.
20907N/A#
20907N/A# Returns 0 if folder is empty, doesn't exists
20907N/A# or there is no permissions to access it.
20907N/A# 1 if it's not empty.
20907N/A#
20907N/Ais_folder_empty ()
20907N/A{
20907N/A if [ "$(/usr/bin/ls -A "$1" 2>/dev/null)" ]; then
20907N/A return 1
20907N/A else
12723N/A return 0
20907N/A fi
20907N/A}
20907N/A
20907N/A# NAME
20907N/A# are_multiuser_gconf_settings_uptodate
20907N/A#
20907N/A# ARGUMENTS
20907N/A# NONE
20907N/A#
12723N/A# DESCRIPTION
20907N/A# Checks if the GConf settings installed in the GCONF_DEFAULTS_DIR
20907N/A# and GCONF_MANDATORY_DIR are up to date.
20907N/A#
20907N/A# Returns 0 if the GConf settings are up to date, 1 otherwise.
20907N/A#
20907N/Aare_multiuser_gconf_settings_uptodate ()
12723N/A{
20907N/A RETVAL=1
20907N/A multi_user_version_gconf="$($GCONF_TOOL --get $GCONF_MULTI_USER_VERSION 2>/dev/null)"
20907N/A if [[ $multi_user_version_gconf -eq $MULTI_USER_VERSION ]]; then
20907N/A RETVAL=0
20907N/A fi
20907N/A return $RETVAL
20907N/A
20907N/A}
20907N/A
20907N/A# NAME
20907N/A# clean_up_multiuser_gconf_settings
20907N/A#
20907N/A# ARGUMENTS
20907N/A# NONE
20907N/A#
14293N/A# DESCRIPTION
20907N/A# Removes previous Multi User Desktop GConf settings
20907N/A# if necessary.
20907N/A#
20907N/Aclean_up_multiuser_gconf_settings ()
20907N/A{
20907N/A if ! are_multiuser_gconf_settings_uptodate; then
20907N/A if ! is_folder_empty "$GCONF_DEFAULTS_DIR"; then
20907N/A print "Removing old multi user desktop default settings."
20907N/A rm -rf "${GCONF_DEFAULTS_DIR}/*"
20907N/A fi
20907N/A if ! is_folder_empty "$GCONF_MANDATORY_DIR"; then
20907N/A print "Removing old multi user desktop mandatory settings."
20907N/A rm -rf "${GCONF_MANDATORY_DIR}/*"
20907N/A fi
20907N/A fi
20907N/A}
20907N/A
20907N/Acase "$1" in
12723N/A'start')
20907N/A clean_up_multiuser_gconf_settings
20907N/A
20907N/A if is_folder_empty "$GCONF_DEFAULTS_DIR"; then
20907N/A cmd_load="$GCONF_TOOL --direct --config-source xml:readwrite:${GCONF_DEFAULTS_DIR} --load=${GCONF_DEFAULTS_VALUES}"
20907N/A # Print the command so that the log contains the command used
20907N/A print $cmd_load
20907N/A $cmd_load
20907N/A if [[ $? -ne 0 ]]; then
20907N/A print "failed to invoke: \"${cmd_load}\" for service: $SMF_FMRI"
20907N/A exit $SMF_EXIT_ERR_CONFIG
20907N/A fi
20907N/A fi
20907N/A
20907N/A if is_folder_empty "$GCONF_MANDATORY_DIR"; then
20907N/A cmd_load="$GCONF_TOOL --direct --config-source xml:readwrite:${GCONF_MANDATORY_DIR} --load=${GCONF_MANDATORY_VALUES}"
20907N/A print $cmd_load
20907N/A exec $cmd_load
20907N/A if [[ $? -ne 0 ]]; then
20907N/A print "failed to invoke: \"${cmd_load}\" for service: $SMF_FMRI"
20907N/A exit $SMF_EXIT_ERR_CONFIG
20907N/A fi
20907N/A fi
20907N/A
20907N/A ;;
20907N/A
20907N/A'stop')
20907N/A clean_up_multiuser_gconf_settings
12723N/A
20907N/A if ! is_folder_empty "$GCONF_DEFAULTS_DIR"; then
20907N/A cmd_unload="$GCONF_TOOL --direct --config-source xml:readwrite:${GCONF_DEFAULTS_DIR} --unload=${GCONF_DEFAULTS_VALUES}"
20907N/A print $cmd_unload
20907N/A $cmd_unload
20907N/A if [[ $? -ne 0 ]]; then
20907N/A print "failed to invoke: \"${cmd_unload}\" for service: $SMF_FMRI"
20907N/A exit $SMF_EXIT_ERR_CONFIG
20907N/A fi
20907N/A fi
20907N/A
20907N/A if ! is_folder_empty "$GCONF_MANDATORY_DIR"; then
20907N/A cmd_unload="$GCONF_TOOL --direct --config-source xml:readwrite:${GCONF_MANDATORY_DIR} --unload=${GCONF_MANDATORY_VALUES}"
12723N/A print $cmd_unload
20907N/A exec $cmd_unload
20907N/A if [[ $? -ne 0 ]]; then
20907N/A print "failed to invoke: \"${cmd_unload}\" for service: $SMF_FMRI"
20907N/A exit $SMF_EXIT_ERR_CONFIG
20907N/A fi
20907N/A fi
20907N/A
20907N/A ;;
20907N/A
20907N/A*)
20907N/A print "Usage: $0 { start | stop }"
20907N/A exit $SMF_EXIT_ERR_CONFIG
20907N/A ;;
20907N/A
20907N/Aesac
20907N/Aexit $SMF_EXIT_OK
20907N/A