#!/bin/sh # # Copyright (C) 1993 by Sun Microsystems, Inc. # All rights reserved. # # This file is a product of SunSoft, Inc. and is provided for # unrestricted use provided that this legend is included on all # media and as a part of the software program in whole or part. # Users may copy, modify or distribute this file at will. # # THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING # THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR # PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. # # This file is provided with no support and without any obligation on the # part of SunSoft, Inc. to assist in its use, correction, modification or # enhancement. # # SUNSOFT AND SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT # TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS # FILE OR ANY PART THEREOF. # # IN NO EVENT WILL SUNSOFT OR SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY # LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL # DAMAGES, EVEN IF THEY HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH # DAMAGES. # # SunSoft, Inc. # 2550 Garcia Avenue # Mountain View, California 94043 # #------------------------------------------------------------------------------- # # addmenus # # Description: # A convience script to add the menus of Promotional Software Eng. # (PENG) demos residing on the local machine into a users OpenWindows # Workspace Menu. # # Requirements: # user of script is 'root' # # Files/Directories modified for each user entered: # $HOME/.openwin-menu # $HOME/.menus directory addition # $HOME/.menus/ for each demo on system # Backups for files are created as .BAK when appropriate # # Algorithm Overview: # # introduction message # make sure the user is root # obtain a list of PENG demos on system # if the list is empty # tell the user that there are no PENG demos and exit # find information on each pkg installed on the system # installation directory # .menu_file # loop until user selects exit # prompt for a login name # get input # check that login name exists # obtain home directory and group # make sure .openwin-menu file exists, if not try to create # check if .menus directory, if not create # check if .menus/demos-menu exists, if not create # loop til out of demos # add menu to .menus/demos-menu # # author: # bfreeman 07/19/93 # trap 'exit 3' 15 PATH=/usr/sbin:/usr/bin:/usr/ucb export PATH TRUE=0 FALSE=1 DIR=`dirname $0` DIR=`cd $DIR; pwd` BASE=`basename $0` # # debug # DEBUG=$FALSE # set to $TRUE for debug msgs, $FALSE to omit # debug() { if [ "$DEBUG" = "$TRUE" ]; then echo "$*" fi } # # error - print out an error message # error() { echo "" echo "\\tError: $*" echo "" } # # warning - print out a warning message # warning() { echo "" echo "\\tWarning: $*" echo "" } # # chown_chgrp # chown_chgrp() { args="$*" usr_name="`echo $args | awk '{print $1}'`" usr_group="`echo $args | awk '{print $2}'`" file="`echo $args | awk '{print $3}'`" if [ -f $file ] ; then chown $usr_name $file || { error "Unable to change owner on $file" rm $file return $FALSE } chgrp $usr_group $file || { error "Unable to change group on $file" rm $file return $FALSE } else return $FALSE fi } # chown_chgrp # # menu_file_loc # # Arguments: # list of pkg tokens to check # Return value: # mfilelist - A list of / for each # pkg installed on the system. The list will be in the same # order as the argument list. # # prodnamelist - A list of PRODNAME entries for each pkg installed on # the system. PRODNAME is used in the creation the menu entry. # # 'Error' will be inserted in the lists if the # installation directory, menu file, or PRODNAME is not # obtainable for a given argument (pkg token). # menu_file_loc() { args="$*" # input arguments err_str="Error" # error string mfilereturn="" # tmp value to hold menu file list entry prodnamereturn="" # tmp value to hold product name list entry pkgdir="" # tmp value to hold pkg's installation dir mfilelist="" # returned menu file list prodnamelist="" # returned product name list debug "menu_file_loc - Args = $args" if [ -z "$args" ]; then # list is empty echo "menu_file_loc() - Empty list" mfilelist="$err_str" fi while [ -n "$args" ] do arg=`echo $args | awk '{print $1}'` debug "menu_file_loc - Current arg = $arg" if [ -d /var/sadm/pkg/$arg ]; then debug "menu_file_loc - \\t/var/sadm/pkg/$arg found" if [ -r /var/sadm/pkg/$arg/pkginfo ]; then debug "menu_file_loc - \\t/var/sadm/pkg/$arg/pkginfo found" pkgdir=`fgrep PENG_HOME /var/sadm/pkg/$arg/pkginfo | \ sed -e 's/PENG_HOME=//g' -e 's/\"//g'` || { error "Unable to obtain $arg's installation directory" mfilereturn="$err_str" } prodnamereturn=`fgrep PRODNAME /var/sadm/pkg/$arg/pkginfo | \ sed -e 's/PRODNAME=//g' -e 's/\"//g'` || { error "Unable to obtain $arg's PRODNAME" prodnamereturn="$err_str" } if [ -n "$pkgdir" ]; then debug "menu_file_loc - \\tpkgdir = $pkgdir" # I hate having to do this here, but not all of the # packages are the same. Got to have at least one special case;-) case $arg in PENGbackg ) debug "menu_file_loc - \\t\\tBackground Package" if [ -r $pkgdir/backgrounds-menu ]; then # all ok, return pkgdir mfilereturn="$pkgdir/backgrounds-menu" else # it failed error "Can't find $arg's backgrounds-menu file" mfilereturn="$err_str" prodnamereturn="$err_str" fi ;; * ) # all the rest of the PENG pkgs debug "menu_file_loc - \\t\\tNormal Package" if [ -r $pkgdir/.menu_file ]; then # all ok, return pkgdir mfilereturn="$pkgdir/.menu_file" else # it failed error "Can't find $arg's .menu_file" mfilereturn="$err_str" prodnamereturn="$err_str" fi ;; esac else # if [ -n "$pkgdir" ]; then # couldn't get pkgdir error "Unable to determine where $arg is installed" mfilereturn="$err_str" prodnamereturn="$err_str" fi else # if [ -r /var/sadm/pkg/$arg/pkginfo ]; then # error pkginfo not readable error "$arg pkginfo file is not readable" mfilereturn="$err_str" prodnamereturn="$err_str" fi else # if [ -d /var/sadm/pkg/$arg ]; then # error pkg info not there debug "menu_file_loc - \\tpkginfo not there" mfilereturn="$err_str" prodnamereturn="$err_str" fi # add return values to lists mfilelist="$mfilelist $mfilereturn" prodnamelist="$prodnamelist $prodnamereturn" # remove the current arg from the args list args=`echo $args | sed -e 's/'$arg'//g'` done # while [ -n "$args" ] } # menu_file_loc # # get_usr_home - obtains the user's home directory # If so, usr_home will be set to the # appropriate location. # get_usr_home() { usr_name="$*" usr_home=`fgrep $usr_name /etc/passwd | sed -e 's/^'$usr_name'/HOLD/' | grep HOLD | cut -d: -f6` # if usr_home is not in local /etc/passwd try yp if [ -z "$usr_home" ]; then usr_home=`ypmatch $usr_name passwd | cut -d: -f6` # if usr_home is still not set, give up if [ -z "$usr_home" ]; then error "Unable to aquire $usr_name's home directory." usr_home="" return $FALSE else # got the home directory # does it exist? if [ ! -d "$usr_home" ] ; then error "$usr_name's home directory $usr_home does not exist." usr_home="" return $FALSE else return $TRUE fi fi else # got the usrs home directory # does it exist? if [ ! -d "$usr_home" ] ; then error "$usr_name's home directory $usr_home does not exist." usr_home="" return $FALSE else return $TRUE fi fi } # get_usr_home # # get_usr_group - obtains the user's group directory # If so, usr_group will be set to the # appropriate value. # get_usr_group() { usr_name="$*" usr_group=`fgrep $usr_name /etc/passwd | sed -e 's/^'$usr_name'/HOLD/' | grep HOLD | cut -d: -f4` # if usr_group is not in local /etc/passwd try yp if [ -z "$usr_group" ]; then usr_group=`ypmatch $usr_name passwd | cut -d: -f4` # if usr_group is still not set, give up if [ -z "$usr_group" ]; then error "Unable to aquire $usr_name's group id." usr_group="" return $FALSE else # got the group return $TRUE fi else # got the usrs group return $TRUE fi } # get_usr_group # # check_user - checks if a user is a valid user # If so, user_name, user_home, user_group # will be set to the appropriate locations. # check_user() { args="$*" user_name="" user_home="" user_group="" # Make sure user exists /usr/sadm/bin/valuid $args status=$? if [ "$status" = "$TRUE" ] ; then # user exists, get home directory user_name="$args" get_usr_home $user_name status=$? if [ "$status" = "$TRUE" ]; then # got user_home user_home="$usr_home" get_usr_group $user_name status=$? if [ "$status" = "$TRUE" ]; then # got user_group user_group="$usr_group" return $TRUE else user_name="" user_home="" user_group="" return $FALSE fi else # couldn't get user_home error "Unable to aquire $user_name's home directory." user_name="" user_home="" user_group="" return $FALSE fi else # not a valid user error "$args is not a valid user." return $FALSE fi } # check_user # # check_openwin_menu - check if .openwin-menu file exists # if one does not try to create # check_openwin_menu() { args="$*" usr_name="`echo $args | awk '{print $1}'`" usr_home="`echo $args | awk '{print $2}'`" usr_group="`echo $args | awk '{print $3}'`" # does usr_home/.openwin-menu exist? if [ ! -f $usr_home/.openwin-menu ] ; then # does not exist warning "$usr_name does not have a .openwin-menu file" echo "\\tTrying to create..." # is usr_home writable if [ ! -w $usr_home ] ; then echo "" echo "\\tError: $usr_name's home directory $usr_home is not writable." echo "" echo "\\t\\tIf $usr_home is automounted, try running this script " echo "\\t\\ton the machine where $usr_home resides." echo "" echo "\\t\\t(ie root on `uname -n` is not equal to root where $usr_home resides.)" echo "" return $FALSE else if [ -n "$OPENWINHOME" ] ; then if [ -d $OPENWINHOME/lib ] ; then if [ -f $OPENWINHOME/lib/openwin-menu ] ; then cp $OPENWINHOME/lib/openwin-menu $usr_home/.openwin-menu || { error "Unable to create $usr_home/.openwin-menu file" return $FALSE } echo "\\t\\tDone." else error "Unable to create. \$OPENWINHOME/lib/openwin-menu does not exist." return $FALSE fi # openwin-menu else error "Unable to create. \$OPENWINHOME/lib does not exist." return $FALSE fi # lib else error "Unable to create. OPENWINHOME is not set." return $FALSE fi # -n OPENWINHOME # change ownerships chown_chgrp $usr_name $usr_group $usr_home/.openwin-menu status=$? if [ "$status" = "$FALSE" ] ; then return $FALSE else return $TRUE fi fi # -w $usr_home fi } # check_openwin-menu # # check_menus_dir - check if .menus directory exists, if not creates # check_menus_dir() { args="$*" usr_name="`echo $args | awk '{print $1}'`" usr_home="`echo $args | awk '{print $2}'`" usr_group="`echo $args | awk '{print $3}'`" # does usr_home/.menus exist if [ ! -d $usr_home/.menus ] ; then # does not exist mkdir $usr_home/.menus || { echo "" echo "\\tError: Unable to create directory $usr_home/.menus" echo "\\t\\t$usr_name's home directory $usr_home is not writable." echo "" echo "\\t\\tIf $usr_home is automounted, try running this script " echo "\\t\\ton the machine where $usr_home resides." echo "" echo "\\t\\t(ie root on `uname -n` is not equal to root where $usr_home resides.)" echo "" return $FALSE } # change ownership if [ -d $usr_home/.menus ] ; then chown $usr_name $usr_home/.menus || { error "Unable to change the owner on $usr_home/.menus, removing." rmdir $usr_home/.menus return $FALSE } fi # change group if [ -f $usr_home/.menus ] ; then chgrp $usr_group $usr_home/.menus || { error "Unable to change the group on $usr_home/.menus, removing." rmdir $usr_home/.menus return $FALSE } return $TRUE fi else # exists return $TRUE fi } #check_menus_dir # # create_demos_menu - creates a template demos menu. Overwrites if one # exists. Assumes the path $usr_home/.menus exists. # create_demos_menu() { args="$*" usr_name="`echo $args | awk '{print $1}'`" usr_home="`echo $args | awk '{print $2}'`" usr_group="`echo $args | awk '{print $3}'`" echo "\\tCreating $usr_home/.menus/demos-menu..." cat > $usr_home/.menus/demos-menu <> $usr_home/.openwin-menu < $usr_home/.openwin-menu fi echo "\\t\\tDone." return $TRUE else error "$usr_home/.openwin-menu does not exist, or is not writable" return $FALSE fi # .openwin-menu } #add_demos_to_openwin_menu # # check_demos_menu - checks if .menus/demos-menu exists, if not creates # check_demos_menu() { args="$*" usr_name="`echo $args | awk '{print $1}'`" usr_home="`echo $args | awk '{print $2}'`" usr_group="`echo $args | awk '{print $3}'`" # does usr_home/.menus exist if [ -d $usr_home/.menus ] ; then if [ ! -f $usr_home/.menus/demos-menu ] ; then # no create create_demos_menu $* status=$? if [ "$status" = "$TRUE" ]; then # ok, now add to .openwin-menu add_demos_to_openwin_menu $* status=$? if [ "$status" = "$TRUE" ]; then return $TRUE else return $FALSE fi else return $FALSE fi else # demo-menu exists, save and create new... cp $usr_home/.menus/demos-menu $usr_home/.menus/demos-menu.$$ || { warning "Unable to backup $usr_home/.menus/demos-menu." } # now create a new demos-menu create_demos_menu $* status=$? if [ "$status" = "$TRUE" ]; then return $TRUE else return $FALSE fi fi # if demos-menu else # does not exist error "$usr_home/.menus directory does not exist." return $FALSE fi } # check_demos_menu # # add_menu - adds a menu to a users system # # arguments: # user's login (solaris) # user's home dir (/opt/solaris) # user's group (staff - the number that is) # package token (PENGxxxxx) # menu file location (/opt/PENGxxxxx) # product name (Demo - what shows up on the menu button) # # return values: # $TRUE on success # $FALSE on failure # add_menu() { args="$*" debug "add_menu - Args = $args" usr_name="`echo $args | awk '{print $1}'`" debug "add_menu - usr_name = $usr_name" usr_home="`echo $args | awk '{print $2}'`" debug "add_menu - usr_home = $usr_home" usr_group="`echo $args | awk '{print $3}'`" debug "add_menu - usr_group = $usr_group" pkgtok="`echo $args | awk '{print $4}'`" debug "add_menu - pkgtok = $pkgtok" mfile="`echo $args | awk '{print $5}'`" debug "add_menu - mfile = $mfile" pname="`echo $args | awk '{print $6}'`" debug "add_menu - pname = $pname" case $mfile in $err_str ) return $FALSE ;; * ) case $pkgtok in PENGbackg ) # the special case echo "\\tAdding $pname menu to $usr_home/.openwin-menu..." if [ -f $usr_home/.openwin-menu ] ; then # add to .openwin-menu cp $usr_home/.openwin-menu $usr_home/.openwin-menu.BAK-$$ || { error "Unable to backup $usr_home/.openwin-menu" return $FALSE } # change ownerships chown_chgrp $usr_name $usr_group $usr_home/.openwin-menu.BAK-$$ status=$? if [ "$status" = "$FALSE" ] ; then return $FALSE fi # is there an EXIT line in .openwin-menu status=`fgrep EXIT $usr_home/.openwin-menu.BAK-$$` if [ -z "$status" ] ; then # no EXIT found, add entry at end of file cat >> $usr_home/.openwin-menu < $usr_home/.openwin-menu fi echo "\\t\\tDone." else error "$usr_home/.openwin-menu does not exist" return $FALSE fi # if .openwin-menu ;; * ) # the norm pkghome=`dirname $mfile` debug "add_menu - pkg home directory = $pkghome" pkghome_esc=`echo $pkghome | sed 's/\\//\\\\\\//g'` # # put the menu_file in place # echo "\\tCreating $usr_home/.menus/$pname-menu file..." cat $mfile | sed 's/PENG_HOME/'$pkghome_esc'/g' > \ $usr_home/.menus/$pname-menu || { error "Unable to create $pname-menu file" return $FALSE } # change ownerships chown_chgrp $usr_name $usr_group $usr_home/.menus/$pname-menu status=$? if [ "$status" = "$FALSE" ] ; then return $FALSE fi echo "\\t\\tDone." # # add entry in demos-menu # echo "\\tAdding $pname menu to $usr_home/.menus/demos-menu..." # make backup cp $usr_home/.menus/demos-menu $usr_home/.menus/demos-menu.BAK || { error "Unable to make backup of $usr_home/.menus/demos-menu" return $FALSE } # change ownerships chown_chgrp $usr_name $usr_group $usr_home/.menus/demos-menu.BAK status=$? if [ "$status" = "$FALSE" ] ; then return $FALSE fi # do it cat $usr_home/.menus/demos-menu | grep -v "\"Demos\" END PIN" > /tmp/$$ || { error "Unable to add $pname menu to $usr_home/.menus/demos-menu" return $FALSE } cat >>/tmp/$$ <" echo "\\t\\t# $0" echo "" exit $1 fi # continue intro message echo "\\tFiles/Directories modified for each user entered:" echo "\\t \$HOME/.openwin-menu" echo "\\t \$HOME/.menus directory addition" echo "\\t \$HOME/.menus/ for each demo on system" echo "\\t Backups for files are created as .BAK when appropriate" echo "\\t" # obtain a list of PENG package on the system echo "Checking for Promotional Software Engineering demo packages..." pkglist=`pkginfo | grep PENG | sed -e '/PENGdenv/d' -e '/PENGroot/d' | cut -c13-21` # # if pkglist is empty tell user and exit # if [ -z "$pkglist" ]; then echo "" echo "\\tNo Promotional Software Engineering demos are installed on this system." echo "\\tRemember PENGdenv and PENGroot don't count. They are environments" echo "\\tand do not have any associated menus." echo "" echo "\\tExiting." echo "" exit 0 else echo "\\tDone." fi echo "" echo "The following demos were found:" echo "$pkglist" echo "" # obtain menu file location echo "Finding menu file for each package..." tmplist="$pkglist" menu_file_loc $tmplist status=$? if [ "$status" = "$FALSE" ]; then error "Unable to find menu file locations" exit 1 else menufilelist="$mfilelist" productnamelist="$prodnamelist" echo "\\tDone." fi debug "main - Package list: $pkglist\\n" debug "main - Menu file list: $menufilelist\\n" debug "main - PRODNAME list: $productnamelist\\n" # # ask for user account to add demos to # while [ $TRUE ] do response=`ckstr -p "Enter the login name for a user, 'q' to quit"` status=$? if [ $status = $TRUE ] ; then # Make sure response exists debug "main - Login name $response entered" check_user $response status=$? if [ "$status" = "$TRUE" ]; then # valid user check_openwin_menu $user_name $user_home $user_group status=$? if [ "$status" = "$TRUE" ]; then debug "main - .openwin-menu" check_menus_dir $user_name $user_home $user_group status=$? if [ "$status" = "$TRUE" ]; then debug "main - .menus directory" check_demos_menu $user_name $user_home $user_group status=$? if [ "$status" = "$TRUE" ]; then debug "main - demos-menu file" # setup the temp list, so dont destroy original tpkgs="$pkglist" tmfile="$menufilelist" tprod="$productnamelist" # loop til exhausted while [ -n "$tpkgs" ] do # get the first element off the lists pkgtok=`echo $tpkgs | awk '{print $1}'` menufile=`echo $tmfile | awk '{print $1}'` prodname=`echo $tprod | awk '{print $1}'` # try to add the sucker add_menu $usr_name $usr_home $usr_group $pkgtok $menufile $prodname status=$? if [ "$status" = "$FALSE" ]; then error "Menu installation failed for $pkgtok" fi # add_menu # remove the first element from the list tpkgs=`echo $tpkgs | sed -e "s/$pkgtok//g"` menufile_esc=`echo $menufile | sed 's/\\//\\\\\\//g'` tmfile=`echo $tmfile | sed -e "s/$menufile_esc//g"` tprod=`echo $tprod | sed -e "s/$prodname//g"` done # while [ -n "$tpkgs" ] fi # check_demos_menu fi # check_menus_dir fi # check_openwin_menu fi # check_user else # quit selected echo "" echo "Quitting..." echo "" exit 0 fi done # while [ 0 ] exit 0