Home | History | Annotate | Download | only in ext-sources
      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 ## 
     10 ##
     11 #
     12 # CDDL HEADER START
     13 #
     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.
     18 #
     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.
     23 #
     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]
     29 #
     30 # CDDL HEADER END
     31 #
     32 #
     33 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
     34 # Use is subject to license terms.
     35 #
     36 
     37 ##
     38 ## Figure out the base installdir
     39 ##
     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*}"
     47 fi
     48 
     49 ##
     50 ## Create variables
     51 ##
     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"
     58 
     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" 
     65 
     66 ##
     67 ## Define some utility functions
     68 ##
     69 
     70 #
     71 # Checks if it's the first time the user is running gnome-about
     72 #
     73 isFirstTime() {
     74     typeset value=""
     75     if [ -x "${GCONFTOOL}" ]; then
     76         value=`${GCONFTOOL} -g "${GCONF_DEVGUIDE_PROMPT_KEY}" 2>/dev/null`
     77     fi
     78     test "${value}" != "true"
     79     return $?
     80 }
     81 
     82 markFirstRunDone() {
     83     if [ -x "${GCONFTOOL}" ]; then
     84         ${GCONFTOOL} -s -t bool "${GCONF_DEVGUIDE_PROMPT_KEY}" true 2>/dev/null
     85         return 0
     86     fi
     87     return 1
     88 }
     89 
     90 #
     91 # Looks for the developer guide HTML file.
     92 #
     93 # NOTE: First checks if a localised version exists, otherwise picks the
     94 # default version.
     95 #
     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
    106     fi
    107     return 0
    108 }
    109 
    110 #
    111 # Attempts to create an launcher on the user's desktop for a pointer to the
    112 # Developer Guide.
    113 #
    114 copyDesktopFile() {
    115     typeset XDG_DESKTOP_FILE="${XDG_APPLICATIONS_DIR}/${SOLDEVEX_DESKTOP_FILE}" 
    116     typeset USER_DESKTOP_FILE="${USER_DESKTOP_DIR}/${SOLDEVEX_DESKTOP_FILE}" 
    117 
    118     if [ -r "${XDG_DESKTOP_FILE}" ]; then
    119         if [ ! -w "${USER_DESKTOP_DIR}" ]; then
    120             mkdir "${USER_DESKTOP_DIR}" || return 1 # If fails return
    121         fi
    122         if [ ! -e "${USER_DESKTOP_FILE}" ]; then
    123             cp "${XDG_DESKTOP_FILE}" "${USER_DESKTOP_FILE}" || return 1 # If fails return
    124         fi
    125     else
    126         return 1
    127     fi
    128     return 0
    129 }
    130 
    131 #
    132 # Launch firefox for the given HTML File
    133 #
    134 launchFirefox() {
    135     if [ -x "${FIREFOX}" -a -n "${1}" ]; then
    136         ${FIREFOX} "${1}" &     # Needs to be run in the background
    137     fi
    138 }
    139 
    140 #
    141 # Launch UsersAdmin
    142 #
    143 launchUsersAdmin() {
    144    if [ -x "${USERS_ADMIN}" ]; then
    145        ${USERS_ADMIN} &     # Needs to be run in the background
    146    fi
    147 }
    148 
    149 #
    150 # Check if the user is NOT root.
    151 #
    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`
    160     fi
    161     if [ -n "${USER_ID}" -a "${USER_ID}" -ne 0 ]; then
    162         return 0
    163     else
    164         return 1
    165     fi
    166 }
    167 
    168 ## 
    169 ## Main
    170 ## 
    171 
    172 if isFirstTime; then
    173 
    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
    179 
    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
    185        fi 
    186     fi
    187     
    188     # Now that we've finished, don't forget to remember this.
    189     markFirstRunDone
    190 fi
    191 
    192 # Finally, just run the GNOME About application, with params, if any.
    193 exec ${GNOME_ABOUT_BIN} ${1+"$@"}
    194