#!/bin/ksh #set -x # # Many codes require specific LD_LIBRARY_PATH settings, # variables to point to specific license server nodes, # and global environmental variables to be set. Or # perhaps you want to record a log of program usage. # It is best to install such programs in directories # NOT in the user search path; and to have users NOT # set these variables in their .cshrc, .bashrc, .login, # .profile files. It is best to create a directory of # wrappers for each application and to place that # directory in the user search path. These wrappers # set up the required environment. # This avoids many problems; especially if you want to # # o easily access multiple versions of a code # o make a log entry for each program execution # # Another approach it to make a single command that # writes the setup information to standard output # for a particular program; and then use aliases # to easily "source" this information. An excellent # example of this approach is the modules(1) # utility, which includes commands to unload and # load environmental information. # export LD_LIBRARY_PATH export LM_LICENSE_FILE export PATH ##################### # function to list available wrapper commands LIST(){ echo "known commands:" [ -d /usr/local/wrapper ] && (cd /usr/local/wrapper;ls) } ##################### # process a direct call to the wrapper command instead of # one of it's links. WRAPPER(){ case "$*" in ################ generate) # # Generate all the links in the /usr/local/wrapper # directory. This is the directory to put in the # user's search path. # TIP: you can wipe out the directory to make sure # old commands are not available and regenerate # it with this option # make sure the directory exists # mkdir -p /usr/local/wrapper chmod a=xr,u+w /usr/local/wrapper # # # add the links to this script. A variant is to read # this list from a file. for NAME in \ command1 \ acroread \ fortran \ debugger \ c89 \ $NULL do [ -L "$NAME" ] || ln $0 /usr/local/wrapper/$NAME done echo 'wrapper directory contents' LIST exit ;; ################ -h|--help|-help|help) USAGE;exit;; ################ '') LIST;exit ;; ################ *) echo 'unknown wrapper option' USAGE exit ;; ################ esac } ##################### # usage USAGE(){ cat <<\EOF ________________________________________________________________________________ The wrapper(1) script allows an administrator to easily maintain a large number of wrappers around installed utilities. To display a list of commands in /usr/local/wrapper wrapper To build or rebuild the /usr/local/wrapper/ directory the adminstrator enters: wrapper generate To display this help wrapper help The adminstrator edits the wrapper script and adds a case statement block for each command to be wrapped. John S. Urban ________________________________________________________________________________ EOF } ##################### # # set CMD to a complete path and set up the # environment for the command # or execute a command and exit. # VERB=`basename "$0"` CMD=/mnt/applications/$VERB case "$VERB" in ################################################### command1) LD_LIBRARY_PATH=/mnt/applications/code1/lib:$LD_LIBRARY_PATH . /mnt/applications/code1/setup.sh CMD=/mnt/applications/code1/command1 ;; ################################################### acroread) CMD=/mnt/applications/AcROREAD4/bin/acroread ;; ################################################### fortran) if [ "$*" = '' ] then cat <<\EOF set the COMPILER variable to one of ... ifort_11 Intel ifort compiler version 11.0 ifort_10 Intel ifort compiler version 10.0 gfortran g95_092 g95 version 0.92 : : EOF exit fi COMPILER=${COMPILER:-ifort_11} case "$COMPILER" in ifort_11) LM_LICENSE_FILE=28518@license_server . /mnt/applications/intel_fc_11.0/setup.sh CMD=ifort ;; ifort_10) LM_LICENSE_FILE=28518@license_server . /mnt/applications/intel_fc_10.0/setup.sh CMD=ifort ;; g95_092|g95) CMD=/usr/local/bin/g95 ;; gfortran) CMD=/usr/bin/gfortran ;; *) echo 'unknown compiler version' exit ;; esac ;; ################################################### c89) LD_LIBRARY_PATH=/mnt/applications/code1/lib:$LD_LIBRARY_PATH CMD=/usr/share/bin/cc ;; ################################################### wrapper) WRAPPER "${@}" exit ;; ################################################### *) echo "unknown wrapper command" CMD=echo ;; ################################################### esac ################################################### # execute command $CMD "${@}" ###################################################