gedit-plugins: switch to Python 2.7
[unleashed-userland.git] / components / gnome-desktop / files / gnome-about.ksh
blob1c5d1567ff78ddff9f56f6e308bae922b94316e7
1 #!/bin/ksh -ph
2 ##
3 ## This script wraps GNOME About, which is called by GNOME Session the first
4 ## time that a user logs in, and does some other iniital login tasks:
5 ## - Creates a launcher on the user's Desktop to open the Solaris Developer
6 ## Guide start page
7 ## - Launchs Firefox with the start page.
8 ## - For first logon by root launches users-admin tool
9 ##
12 # CDDL HEADER START
14 # The contents of this file are subject to the terms of the
15 # Common Development and Distribution License, Version 1.0 only
16 # (the "License"). You may not use this file except in compliance
17 # with the License.
19 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
20 # or http://www.opensolaris.org/os/licensing.
21 # See the License for the specific language governing permissions
22 # and limitations under the License.
24 # When distributing Covered Code, include this CDDL HEADER in each
25 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
26 # If applicable, add the following below this CDDL HEADER, with the
27 # fields enclosed by brackets "[]" replaced with your own identifying
28 # information: Portions Copyright [yyyy] [name of copyright owner]
30 # CDDL HEADER END
33 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
34 # Use is subject to license terms.
38 ## Figure out the base installdir
40 BASEDIR="${0%%/bin*}"
41 if [ -z "$BASEDIR" ]; then
42 # /bin tends to be a symbolic link, so follow it and do calc basedir off
43 # that.
44 DIRNAME=`dirname $0`
45 BASEDIR=`cd "$DIRNAME"; sh -c pwd`
46 BASEDIR="${BASEDIR%%/bin*}"
50 ## Create variables
52 GNOME_ABOUT_BIN="${BASEDIR}/lib/gnome-about"
53 GCONFTOOL="${BASEDIR}/bin/gconftool-2"
54 FIREFOX="${BASEDIR}/bin/firefox"
55 USERS_ADMIN="${BASEDIR}/bin/users-admin"
56 XPG4_ID="/usr/xpg4/bin/id"
57 ID="/usr/bin/id"
59 GCONF_DEVGUIDE_PROMPT_KEY="/apps/gnome-session/options/sun_extensions/viewed_dev_guide_jds_solaris"
60 SOLDEVEX_ROOT="${BASEDIR}/share/doc/soldevex/html"
61 SOLDEVEX_FILE="developer_guide.html"
62 XDG_APPLICATIONS_DIR="${BASEDIR}/share/applications"
63 SOLDEVEX_DESKTOP_FILE="devguide.desktop"
64 USER_DESKTOP_DIR="${HOME}/Desktop"
67 ## Define some utility functions
71 # Checks if it's the first time the user is running gnome-about
73 isFirstTime() {
74 typeset value=""
75 if [ -x "${GCONFTOOL}" ]; then
76 value=`${GCONFTOOL} -g "${GCONF_DEVGUIDE_PROMPT_KEY}" 2>/dev/null`
78 test "${value}" != "true"
79 return $?
82 markFirstRunDone() {
83 if [ -x "${GCONFTOOL}" ]; then
84 ${GCONFTOOL} -s -t bool "${GCONF_DEVGUIDE_PROMPT_KEY}" true 2>/dev/null
85 return 0
87 return 1
91 # Looks for the developer guide HTML file.
93 # NOTE: First checks if a localised version exists, otherwise picks the
94 # default version.
96 locateHTMLFile() {
97 typeset LANG_FILE="${SOLDEVEX_ROOT}/${LANG}/${SOLDEVEX_FILE}"
98 typeset DEFAULT_FILE="${SOLDEVEX_ROOT}/${SOLDEVEX_FILE}"
99 if [ -r "${LANG_FILE}" ]; then
100 echo "${LANG_FILE}"
101 elif [ -r "${DEFAULT_FILE}" ]; then
102 echo "${DEFAULT_FILE}"
103 else
104 echo ""
105 return 1
107 return 0
111 # Attempts to create an launcher on the user's desktop for a pointer to the
112 # Developer Guide.
114 copyDesktopFile() {
115 typeset XDG_DESKTOP_FILE="${XDG_APPLICATIONS_DIR}/${SOLDEVEX_DESKTOP_FILE}"
116 typeset USER_DESKTOP_FILE="${USER_DESKTOP_DIR}/${SOLDEVEX_DESKTOP_FILE}"
118 if [ -r "${XDG_DESKTOP_FILE}" ]; then
119 if [ ! -w "${USER_DESKTOP_DIR}" ]; then
120 mkdir "${USER_DESKTOP_DIR}" || return 1 # If fails return
122 if [ ! -e "${USER_DESKTOP_FILE}" ]; then
123 cp "${XDG_DESKTOP_FILE}" "${USER_DESKTOP_FILE}" || return 1 # If fails return
125 else
126 return 1
128 return 0
132 # Launch firefox for the given HTML File
134 launchFirefox() {
135 if [ -x "${FIREFOX}" -a -n "${1}" ]; then
136 ${FIREFOX} "${1}" & # Needs to be run in the background
141 # Launch UsersAdmin
143 launchUsersAdmin() {
144 if [ -x "${USERS_ADMIN}" ]; then
145 ${USERS_ADMIN} & # Needs to be run in the background
150 # Check if the user is NOT root.
152 isNotRootUser() {
153 typeset USER_ID
154 if [ -x "$XPG4_ID" ]; then
155 USER_ID=`${XPG4_ID} -u`
156 else
157 # Needs a little more work to get the UID.
158 USER_ID=`${ID}`
159 USER_ID=`expr "${USER_ID}" : "uid=\([0-9]*\)(.*" 2>/dev/null`
161 if [ -n "${USER_ID}" -a "${USER_ID}" -ne 0 ]; then
162 return 0
163 else
164 return 1
169 ## Main
172 if isFirstTime; then
174 # See if we have the Solaris Developers Guide somewhere.
175 HTML_FILE=`locateHTMLFile`
176 if [ $? -eq 0 ]; then
177 # Try copy the Desktop entry over to users Desktop dir.
178 copyDesktopFile
180 # Now try to launch Firefox with Dev Guide, but not for root
181 if isNotRootUser; then
182 launchFirefox "${HTML_FILE}"
183 else
184 launchUsersAdmin
188 # Now that we've finished, don't forget to remember this.
189 markFirstRunDone
192 # Finally, just run the GNOME About application, with params, if any.
193 exec ${GNOME_ABOUT_BIN} ${1+"$@"}