Commit 7f8e6e60 authored by Mark Olesen's avatar Mark Olesen
Browse files

etc/bashrc tweak to cleanse env vars, even from a different WM_PROJECT_INST_DIR

- Problem: changing between OpenFOAM versions with different
  WM_PROJECT_INST_DIR paths would leave the old paths in the env vars.

- TODO: etc/cshrc is rougned out, but needs work on the corresponding
  if-statement
parent e255f361
......@@ -36,9 +36,10 @@ export WM_PROJECT=OpenFOAM
# export WM_PROJECT_VERSION=1.5.x
: ${WM_PROJECT_VERSION:=dev}; export WM_PROJECT_VERSION
#!!User:
# either set $FOAM_INST_DIR before sourcing this file or set
################################################################################
# USER EDITABLE PART
#
# either set $FOAM_INST_DIR before sourcing this file or set
# $foamInstall below to where OpenFOAM is installed
#
# Location of FOAM installation
......@@ -47,9 +48,22 @@ foamInstall=$HOME/$WM_PROJECT
# foamInstall=~$WM_PROJECT
# foamInstall=/usr/local/$WM_PROJECT
# foamInstall=/opt/$WM_PROJECT
#
# END OF (NORMAL) USER EDITABLE PART
################################################################################
# note the location for later use (eg, in job scripts)
: ${FOAM_INST_DIR:=$foamInstall}; export FOAM_INST_DIR
# The old dirs to be cleaned from the various environment variables
# - remove anything under top-level directory.
# NB: the WM_PROJECT_INST_DIR might not be identical between versions
foamOldDirs="$FOAM_INST_DIR $HOME/$WM_PROJECT/$USER"
if [ "$WM_PROJECT_INST_DIR" != "$FOAM_INST_DIR" ]
then
foamOldDirs="$WM_PROJECT_INST_DIR $foamOldPaths"
fi
# Location of site/user files
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -169,21 +183,18 @@ USAGE
esac
# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Clean standard environment variables (PATH, LD_LIBRARY_PATH, MANPATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cleanProg=$WM_PROJECT_DIR/bin/foamCleanPath
# Remove anything under top-level foam directory
wildCards="$WM_PROJECT_INST_DIR $HOME/$WM_PROJECT/$USER"
#- Clean path/PATH
cleanPath=`$cleanProg "$PATH" "$wildCards"` && PATH="$cleanPath"
#- Clean PATH
cleanEnv=`$cleanProg "$PATH" "$foamOldDirs"` && PATH="$cleanEnv"
#- Clean LD_LIBRARY_PATH
cleanPath=`$cleanProg "$LD_LIBRARY_PATH" "$wildCards"` && LD_LIBRARY_PATH="$cleanPath"
cleanEnv=`$cleanProg "$LD_LIBRARY_PATH" "$foamOldDirs"` && LD_LIBRARY_PATH="$cleanEnv"
#- Clean MANPATH
cleanPath=`$cleanProg "$MANPATH" "$wildCards"` && MANPATH="$cleanPath"
cleanEnv=`$cleanProg "$MANPATH" "$foamCleanDirs"` && MANPATH="$cleanEnv"
export PATH LD_LIBRARY_PATH MANPATH
......@@ -212,29 +223,30 @@ _foamSource $WM_PROJECT_DIR/etc/apps/ensight/bashrc
_foamSource $WM_PROJECT_DIR/etc/apps/cint/bashrc
# Again clean environment (path, PATH, MANPATH, LD_LIBRARY_PATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#- Clean path/PATH. Only remove duplicates
cleanPath=`$cleanProg "$PATH"` && PATH="$cleanPath"
# Clean environment paths again. Only remove duplicates
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#- Clean PATH
cleanEnv=`$cleanProg "$PATH"` && PATH="$cleanEnv"
#- Clean LD_LIBRARY_PATH
cleanPath=`$cleanProg "$LD_LIBRARY_PATH"` && LD_LIBRARY_PATH="$cleanPath"
cleanEnv=`$cleanProg "$LD_LIBRARY_PATH"` && LD_LIBRARY_PATH="$cleanEnv"
#- Clean MANPATH
cleanPath=`$cleanProg "$MANPATH"` && MANPATH="$cleanPath"
cleanEnv=`$cleanProg "$MANPATH"` && MANPATH="$cleanEnv"
export PATH LD_LIBRARY_PATH MANPATH
#- Clean LD_PRELOAD
if [ "$LD_PRELOAD" != "" ]; then
cleanPath=`$cleanProg "$LD_PRELOAD"` && LD_PRELOAD="$cleanPath"
if [ "$LD_PRELOAD" != "" ]
then
cleanEnv=`$cleanProg "$LD_PRELOAD"` && LD_PRELOAD="$cleanEnv"
export LD_PRELOAD
fi
# cleanup environment:
# ~~~~~~~~~~~~~~~~~~~~
unset cleanPath cleanProg foamInstall
unset cleanEnv cleanProg foamInstall foamOldDirs
unset _foamSource
# -----------------------------------------------------------------------------
......@@ -35,7 +35,9 @@ setenv WM_PROJECT OpenFOAM
# setenv WM_PROJECT_VERSION 1.5.x
if ( ! $?WM_PROJECT_VERSION ) setenv WM_PROJECT_VERSION dev
#!!User:
################################################################################
# USER EDITABLE PART
#
# either setenv FOAM_INST_DIR before sourcing this file or set
# foamInstall below to where OpenFOAM is installed
#
......@@ -45,9 +47,17 @@ set foamInstall = $HOME/$WM_PROJECT
# set foamInstall = ~$WM_PROJECT
# set foamInstall = /usr/local/$WM_PROJECT
# set foamInstall = /opt/$WM_PROJECT
#
# END OF (NORMAL) USER EDITABLE PART
################################################################################
# note the location for later use (eg, in job scripts)
if ( ! $?FOAM_INST_DIR ) setenv FOAM_INST_DIR $foamInstall
# The old dirs to be cleaned from the various environment variables
# - remove anything under top-level directory.
# NB: the WM_PROJECT_INST_DIR might not be identical between versions
set foamOldDirs="$FOAM_INST_DIR $HOME/$WM_PROJECT/$LOGNAME"
# Location of site/user files
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -165,8 +175,8 @@ default:
endsw
# Clean standard environment variables (path, PATH, MANPATH, LD_LIBRARY_PATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Clean standard environment variables (path/PATH, LD_LIBRARY_PATH, MANPATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set cleanProg=$WM_PROJECT_DIR/bin/foamCleanPath
if (! $?LD_LIBRARY_PATH ) then
......@@ -176,21 +186,18 @@ if (! $?MANPATH) then
setenv MANPATH ''
endif
# Remove anything under top-level foam directory
set wildCards="$WM_PROJECT_INST_DIR $HOME/$WM_PROJECT/$LOGNAME"
#- Clean path/PATH
set colonPath=`echo "$path" | sed -e 's/ /:/g'`
set PATH=`$cleanProg "$colonPath" "$wildCards"`
set cleanEnv=`$cleanProg "$colonPath" "$foamOldDirs"`
if ( $status == 0 ) then
set path=`echo "$PATH" | sed -e 's/:/ /g'`
set path=`echo "$cleanEnv" | sed -e 's/:/ /g'`
endif
#- Clean LD_LIBRARY_PATH
setenv LD_LIBRARY_PATH `$cleanProg "$LD_LIBRARY_PATH" "$wildCards"`
setenv LD_LIBRARY_PATH `$cleanProg "$LD_LIBRARY_PATH" "$foamOldDirs"`
#- Clean MANPATH
setenv MANPATH `$cleanProg "$MANPATH" "$wildCards"`
setenv MANPATH `$cleanProg "$MANPATH" "$foamOldDirs"`
# Source project setup files
......@@ -205,15 +212,16 @@ _foamSource $WM_PROJECT_DIR/etc/aliases.csh
# _foamSource $WM_PROJECT_DIR/etc/apps/paraview/cshrc
_foamSource $WM_PROJECT_DIR/etc/apps/paraview3/cshrc
# _foamSource $WM_PROJECT_DIR/etc/apps/ensight/cshrc
# _foamSource $WM_PROJECT_DIR/etc/apps/cint/cshrc
# Again clean environment (path, PATH, MANPATH, LD_LIBRARY_PATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#- Clean path/PATH. Only remove duplicates
# Clean environment paths again. Only remove duplicates
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#- Clean path/PATH
set colonPath=`echo "$path" | sed -e 's/ /:/g'`
set PATH=`$cleanProg "$colonPath"`
set cleanEnv=`$cleanProg "$colonPath"`
if ( $status == 0 ) then
set path=`echo "$PATH" | sed -e 's/:/ /g'`
set path=`echo "$cleanEnv" | sed -e 's/:/ /g'`
endif
#- Clean LD_LIBRARY_PATH
......@@ -229,8 +237,7 @@ endif
# cleanup environment:
# ~~~~~~~~~~~~~~~~~~~~
unset cleanProg
unset wildCards
unset colonPath
unset cleanEnv cleanProg colonPath foamInstall foamOldDirs
unalias _foamSource
# -----------------------------------------------------------------------------
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment