mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve foamEtcFile handling (-prefix, -version options)
- This lets foamExec use foamEtcFile as well, but debian packaging still needs some work
This commit is contained in:
@ -39,8 +39,6 @@
|
|||||||
# @endverbatim
|
# @endverbatim
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
unset listOpt quietOpt
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
[ "$quietOpt" = true ] && exit 1
|
[ "$quietOpt" = true ] && exit 1
|
||||||
|
|
||||||
@ -53,7 +51,11 @@ Usage: ${0##*/} [OPTION] fileName
|
|||||||
options:
|
options:
|
||||||
-list list the directories to be searched
|
-list list the directories to be searched
|
||||||
-mode <mode> any combination of u(user), g(group), o(other)
|
-mode <mode> any combination of u(user), g(group), o(other)
|
||||||
|
-prefix <dir> specify an alternative installation prefix
|
||||||
|
(default: $WM_PROJECT_INST_DIR)
|
||||||
-quiet suppress all normal output
|
-quiet suppress all normal output
|
||||||
|
-version <ver> specify an alternative OpenFOAM version
|
||||||
|
(default: $WM_PROJECT_VERSION)
|
||||||
-help print the usage
|
-help print the usage
|
||||||
|
|
||||||
Locate user/group/shipped file with semantics similar to the
|
Locate user/group/shipped file with semantics similar to the
|
||||||
@ -75,6 +77,13 @@ USAGE
|
|||||||
# default mode is 'ugo'
|
# default mode is 'ugo'
|
||||||
mode=ugo
|
mode=ugo
|
||||||
|
|
||||||
|
# default prefix/version correspond to the active values,
|
||||||
|
# but could also extract from the $0 value.
|
||||||
|
prefix="$WM_PROJECT_INST_DIR"
|
||||||
|
version="$WM_PROJECT_VERSION"
|
||||||
|
|
||||||
|
|
||||||
|
unset listOpt quietOpt
|
||||||
# parse options
|
# parse options
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
do
|
do
|
||||||
@ -100,10 +109,20 @@ do
|
|||||||
esac
|
esac
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
-p | -prefix)
|
||||||
|
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
||||||
|
prefix="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
-q | -quiet)
|
-q | -quiet)
|
||||||
quietOpt=true
|
quietOpt=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-v | -version)
|
||||||
|
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
||||||
|
version="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "unknown option: '$*'"
|
usage "unknown option: '$*'"
|
||||||
;;
|
;;
|
||||||
@ -121,21 +140,21 @@ fileName="$1"
|
|||||||
unset dirList
|
unset dirList
|
||||||
case "$mode" in
|
case "$mode" in
|
||||||
*u*) # user
|
*u*) # user
|
||||||
dirList="$dirList $HOME/.${WM_PROJECT:-OpenFOAM}/$WM_PROJECT_VERSION"
|
dirList="$dirList $HOME/.${WM_PROJECT:-OpenFOAM}/$version"
|
||||||
dirList="$dirList $HOME/.${WM_PROJECT:-OpenFOAM}"
|
dirList="$dirList $HOME/.${WM_PROJECT:-OpenFOAM}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$mode" in
|
case "$mode" in
|
||||||
*g*) # group
|
*g*) # group
|
||||||
dirList="$dirList $WM_PROJECT_INST_DIR/site/$WM_PROJECT_VERSION"
|
dirList="$dirList $prefix/site/$version"
|
||||||
dirList="$dirList $WM_PROJECT_INST_DIR/site"
|
dirList="$dirList $prefix/site"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$mode" in
|
case "$mode" in
|
||||||
*o*) # other
|
*o*) # other (shipped)
|
||||||
dirList="$dirList $WM_PROJECT_DIR/etc"
|
dirList="$dirList $prefix/${WM_PROJECT:-OpenFOAM}-$version/etc"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
set -- $dirList
|
set -- $dirList
|
||||||
|
|||||||
90
bin/foamExec
90
bin/foamExec
@ -43,8 +43,9 @@ usage() {
|
|||||||
Usage: ${0##*/} [OPTION] <application> ...
|
Usage: ${0##*/} [OPTION] <application> ...
|
||||||
|
|
||||||
options:
|
options:
|
||||||
-v ver specify OpenFOAM version
|
-version <ver> specify an alternative OpenFOAM version
|
||||||
-help this usage
|
(default: taken from \$0 parameter)
|
||||||
|
-help this usage
|
||||||
|
|
||||||
* run a particular OpenFOAM version of <application>
|
* run a particular OpenFOAM version of <application>
|
||||||
|
|
||||||
@ -52,17 +53,34 @@ USAGE
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This script must exist in <foamInstall>/OpenFOAM-<VERSION>/bin/
|
||||||
|
# or <foamInstall>/openfoamVERSION/bin/
|
||||||
|
#
|
||||||
|
|
||||||
# This script should exist in <foamInstall>/OpenFOAM-<VERSION>/bin/
|
# the bindir:
|
||||||
# extract the <foamInstall> and <version> elements
|
binDir="${0%/*}"
|
||||||
# using a function preserves the command args
|
|
||||||
getDefaults() {
|
# the project dir:
|
||||||
set -- $(echo $0 | sed -e 's@/OpenFOAM-\([^/]*\)/bin/[^/]*$@ \1@')
|
projectDir="${binDir%/bin}"
|
||||||
foamInstall=$1
|
export WM_PROJECT_DIR="$projectDir"
|
||||||
version=$2
|
|
||||||
}
|
# the prefix dir (same as foamInstall):
|
||||||
|
prefixDir="${projectDir%/*}"
|
||||||
|
foamInstall="$prefixDir"
|
||||||
|
|
||||||
|
# the name used for the project directory
|
||||||
|
projectDirName="${projectDir##*/}"
|
||||||
|
|
||||||
|
# version from OpenFOAM-VERSION (normal) or openfoamVERSION (debian)
|
||||||
|
version=$(echo $projectDirName | sed -e 's@^openfoam-*@@i')
|
||||||
|
|
||||||
|
# debugging:
|
||||||
|
# echo "Installed locations:"
|
||||||
|
# for i in projectDir prefixDir foamInstall projectDirName version
|
||||||
|
# do
|
||||||
|
# eval echo "$i=\$$i"
|
||||||
|
# done
|
||||||
|
|
||||||
getDefaults
|
|
||||||
|
|
||||||
# parse options
|
# parse options
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
@ -71,10 +89,10 @@ do
|
|||||||
-h | -help)
|
-h | -help)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
-v)
|
-v | version)
|
||||||
shift
|
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
||||||
version=$1
|
version=$2
|
||||||
shift
|
shift 2
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
@ -89,41 +107,21 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$#" -lt 1 ]
|
[ "$#" -ge 1 ] || usage "no application specified"
|
||||||
then
|
|
||||||
usage "no application specified"
|
|
||||||
fi
|
|
||||||
|
|
||||||
unset foamDotFile
|
|
||||||
|
|
||||||
# Check user-specific OpenFOAM bashrc file
|
|
||||||
foamDotFile="$HOME/.OpenFOAM/$version/bashrc"
|
|
||||||
if [ -f $foamDotFile ]
|
|
||||||
then
|
|
||||||
. $foamDotFile
|
|
||||||
foamDotFile=okay
|
|
||||||
else
|
|
||||||
# Use the FOAM_INST_DIR variable for locating the installed version
|
|
||||||
for FOAM_INST_DIR in $foamInstall $WM_PROJECT_INST_DIR
|
|
||||||
do
|
|
||||||
foamDotFile="$FOAM_INST_DIR/OpenFOAM-$version/etc/bashrc"
|
|
||||||
if [ -f $foamDotFile ]
|
|
||||||
then
|
|
||||||
. $foamDotFile
|
|
||||||
foamDotFile=okay
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
if [ "$foamDotFile" != okay ]
|
# find OpenFOAM settings (bashrc)
|
||||||
then
|
foamDotFile="$($binDir/foamEtcFile -version $version bashrc)"
|
||||||
|
[ $? -eq 0 ] || {
|
||||||
echo "Error : bashrc file could not be found for OpenFOAM-$version" 1>&2
|
echo "Error : bashrc file could not be found for OpenFOAM-$version" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
}
|
||||||
|
|
||||||
# Pass on the rest of the arguments
|
# preserve arguments (can otherwise get lost when sourcing the foamDotFile)
|
||||||
exec $*
|
args="$*"
|
||||||
|
. $foamDotFile
|
||||||
|
|
||||||
|
# execute
|
||||||
|
exec $args
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user