chpsenv.ksh
This script is used by developers who are working with various PeopleSoft environments on the Unix box such as Development, Acceptance Test etc.. The developers need a way to change their Unix environment variables so they can work in the different PeopleSoft areas without having to log out and then log back in again to reset their Unix session environment.
The main portion of the script is at the update_psoft_env () function which pipes the environment variables into sed where sed then does a search and replace and then resets the newly updated environment variable.
#!/bin/ksh
#*************************************************************************
# Script Name: chpsenv.ksh
# Creation Date: 1/29/98
# Location: /usr/local/bin
# Calling Routine: NONE
# Input Parameters: Three letter psoft environment designator (optional)
# Description: Sets and if run again resets the psoft environment
# variables
# Change Log
# Name Change
# ----------------- ------------------------------------------------------
# Paul McKinney Creation
# Paul McKinney Let Budget choose from any environment and made update
# to run psconfig.sh every time the environment changes
# Paul McKinney Added a "." to have psconfig.sh run in current
# environment (bug fix)
#
#*************************************************************************
#*************************************************************************
#* initialization
#*
#* get psoft environment last set
#*
#* if user is part of "psSYDDEV" group
#* then set variables
#*
#* if user is part of "psBUDDEV" group
#* then set variables
#*
#* if "proj_group" variable has not been set correctly
#* then exit script
#*
#*************************************************************************
initialization ()
{
ps_last_env=$ps_env
if [ $(groups|grep -c psBUD) -ne 0 ]
then
proj_group="BUDGET"
psoft_top_dir=psoftBUD
fi
if [ $(groups|grep -c psSYDDEV) -ne 0 ]
then
proj_group=ISAS
psoft_top_dir=psoftSYD
fi
if [ -z "$proj_group" ]
then
echo Group not set correctly
set --
return
fi
}
#*************************************************************************
#* get_psoft_env
#*
#* if "proj_group" is ISAS
#* then display menu for ISAS users and get response
#*
#* if "proj_group" is BUDGET
#* then display menu for ISAS users and get response
#*
#*************************************************************************
get_psoft_env ()
{
print
print "\t dev) Development"
print "\t bas) Baseline"
print "\t acc) Acceptance"
print "\t mnt) Maintenance"
print "\t dst) Distribution"
print "\t trn) Training"
print "\t tex) Texas Baseline"
print "\t ps60) Demo"
print
read ps_env?"Enter the shortcut designation: "
}
#*************************************************************************
#* validate_env
#*
#* validate selected environment is valid... if not then return 1
#*
#*************************************************************************
validate_env ()
{
case "$ps_env" in
dev|bas|acc|mnt|dst|trn|tex|ps60)
;;
*)
echo "You did not enter a valid environment choice"
return 1
;;
esac
}
#*************************************************************************
#* set_psoft_dir
#*
#* set psoft directory
#* (based project user is associated with and environment they selected)
#*
#*************************************************************************
set_psoft_dir ()
{
psoft_dir=/$psoft_top_dir/$ps_env
}
#*************************************************************************
#* set_psoft_env
#*
#*************************************************************************
set_psoft_env ()
{
COBPATH=$psoft_dir/bin
SYB_SID=PSDEV60
ISASHOME=$psoft_dir/ini
TOOLS=$psoft_dir/tools
PS_TUXDEV=/dev/null
PATH=$psoft_dir/bin:$PATH:$TOOLS
export COBPATH SYB_SID ISASHOME TOOLS PATH
if [ $(groups|grep -c psBUD) -ne 0 ]
then
ISASHOME=$psoft_dir/ini/304
fi
export ISASHOME
}
#*************************************************************************
#* update_psoft_env
#*
#* set internal field serperat to "="
#* pipe environment settings to while loop
#* while still lines to read line into variable name and variable value
#* if top level psoft directory exists in var_value
#* set internal field seperator back to Null
#* (so the following command will work correctly)
#* create command to reset psoft pathing in current environmen
#* (this is done by running the unix 'sed' utility to substitute
#* the previous pathing to the new pathing and building a
#* command string that will reset the given environment
#* variable)
#* run the command using the 'eval' command
#* (the eval command is needed to properly expand the command)
#* set the internal field seperator back to "="
#* (this is required in oder to process the next line
#*
#*************************************************************************
update_psoft_env ()
{
IFS="="
env|
while read var_name var_value
do
if [ $(echo $var_value | grep -c "$psoft_top_dir") -ne 0 ]
then
if [ $(typeset +r | grep -c "$var_name") -eq 0 ]
then
IFS=""
set_command=$var_name"="'"'$(echo $var_value|sed "s/\/$psoft_top_dir\/$ps_last_env/\/$psoft_top_dir\/$ps_env/g")'"'
eval $set_command
IFS="="
fi
fi
done
}
#*************************************************************
#* MAINLINE
#*
#* perform initialization
#*
#* if PS_HOME is empty (user's first time through)
#* if the number of parms is greater is 0 (user passed a parm)
#* get environment variable passed
#* validate environment passed
#* if invalid environment choice then exit script
#* set psoft directory
#* set psoft environment variables
#* run psconfig.sh for the selected environment
#* else the numbers of parms is 0
#* get psoft environment from user by asking them
#* validate environment passed
#* if invalid environment choice then exit script
#* set psoft directory
#* set psoft environment variables
#* run psconfig.sh for the selected environment
#* else PS_HOME is not empty (user has run script before)
#* if the number of parms is greater is 0 (user passed a parm)
#* get environment variable passed
#* validate environment passed
#* if invalid environment choice then exit script
#* set psoft directory
#* update environment variables with psoft pathing
#* else the numbers of parms is 0
#* get psoft environment from user by asking them
#* validate environment passed
#* if invalid environment choice then exit script
#* set psoft directory
#* update environment variables with psoft pathing
#*
#* reset the positional parameters back to Null
#* (the 'set --' command is needed to ensure that the
#* parameter count inicated in "$#" is set to 0)
#*
#*************************************************************
initialization
if [ -z "$PS_HOME" ]
then
if [ $# -gt 0 ]
then
ps_env=$1
validate_env
if [ $? -ne 0 ]
then
set --
return
fi
set_psoft_dir
set_psoft_env
. $psoft_dir/psconfig.sh
else
get_psoft_env
validate_env
if [ $? -ne 0 ]
then
set --
return
fi
set_psoft_dir
set_psoft_env
. $psoft_dir/psconfig.sh
fi
else
if [ $# -gt 0 ]
then
ps_env=$1
validate_env
if [ $? -ne 0 ]
then
set --
return
fi
set_psoft_dir
update_psoft_env
. $psoft_dir/psconfig.sh
else
get_psoft_env
validate_env
if [ $? -ne 0 ]
then
set --
return
fi
set_psoft_dir
update_psoft_env
. $psoft_dir/psconfig.sh
fi
fi
set --