mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: improve debian handling in foamEtcFile
- remove all corresponding logic from foamExec
This commit is contained in:
120
bin/foamEtcFile
120
bin/foamEtcFile
@ -52,10 +52,9 @@ options:
|
||||
-list list the directories to be searched
|
||||
-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
|
||||
-version <ver> specify an alternative OpenFOAM version
|
||||
(default: $WM_PROJECT_VERSION)
|
||||
in the form Maj.Min.Rev (eg, 1.7.0)
|
||||
-help print the usage
|
||||
|
||||
Locate user/group/shipped file with semantics similar to the
|
||||
@ -73,20 +72,64 @@ USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
#
|
||||
# This script must exist in <foamInstall>/OpenFOAM-<VERSION>/bin/
|
||||
# or <foamInstall>/openfoam<VERSION>/bin/ (for the debian version)
|
||||
#
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# the bindir:
|
||||
binDir="${0%/*}"
|
||||
|
||||
# the project dir:
|
||||
projectDir="${binDir%/bin}"
|
||||
|
||||
# the prefix dir (same as foamInstall):
|
||||
prefixDir="${projectDir%/*}"
|
||||
|
||||
# the name used for the project directory
|
||||
projectDirName="${projectDir##*/}"
|
||||
|
||||
# version number used for debian packaging
|
||||
unset versionNum
|
||||
|
||||
#
|
||||
# handle standard and debian naming convention
|
||||
#
|
||||
case "$projectDirName" in
|
||||
OpenFOAM-*) # standard naming convention OpenFOAM-<VERSION>
|
||||
version="${projectDirName##OpenFOAM-}"
|
||||
;;
|
||||
|
||||
openfoam[0-9]*) # debian naming convention 'openfoam<VERSION>'
|
||||
versionNum="${projectDirName##openfoam}"
|
||||
case "$versionNum" in
|
||||
??) # convert 2 digit version number to decimal delineated
|
||||
version=$(echo "$versionNum" | sed -e 's@\(.\)\(.\)@\1.\2@')
|
||||
;;
|
||||
???) # convert 3 digit version number to decimal delineated
|
||||
version=$(echo "$versionNum" | sed -e 's@\(.\)\(.\)\(.\)@\1.\2.\3@')
|
||||
;;
|
||||
????) # convert 4 digit version number to decimal delineated
|
||||
version=$(echo "$versionNum" | sed -e 's@\(.\)\(.\)\(.\)\(.\)@\1.\2.\3.\4@')
|
||||
;;
|
||||
*) # failback - use current environment setting
|
||||
version="$WM_PROJECT_VERSION"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Error : unknown/unsupported naming convention"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# default mode is '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"
|
||||
|
||||
# default naming convention is "OpenFOAM-<VERSION>"
|
||||
projectNamePrefix="${WM_PROJECT:-OpenFOAM}-"
|
||||
|
||||
|
||||
unset listOpt quietOpt
|
||||
|
||||
# parse options
|
||||
while [ "$#" -gt 0 ]
|
||||
do
|
||||
@ -96,7 +139,6 @@ do
|
||||
;;
|
||||
-l | -list)
|
||||
listOpt=true
|
||||
shift
|
||||
;;
|
||||
-m | -mode)
|
||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
||||
@ -110,21 +152,29 @@ do
|
||||
usage "'$1' option with invalid mode '$mode'"
|
||||
;;
|
||||
esac
|
||||
shift 2
|
||||
shift
|
||||
;;
|
||||
-p | -prefix)
|
||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
||||
prefix="$2"
|
||||
shift 2
|
||||
prefixDir="$2"
|
||||
shift
|
||||
;;
|
||||
-q | -quiet)
|
||||
quietOpt=true
|
||||
shift
|
||||
;;
|
||||
-v | -version)
|
||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
||||
version="$2"
|
||||
shift 2
|
||||
# convert x.y.z -> xyz version (if installation looked like debian)
|
||||
if [ -n "$versionNum" ]
|
||||
then
|
||||
versionNum=$(echo "$version" | sed -e 's@\.@@g')
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
usage "unknown option: '$*'"
|
||||
@ -133,23 +183,16 @@ do
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
|
||||
#
|
||||
# handle standard and debian naming convention
|
||||
#
|
||||
case "$version" in
|
||||
OpenFOAM-*) # standard naming convention OpenFOAM-<VERSION>
|
||||
projectNamePrefix="OpenFOAM-"
|
||||
version="${version##OpenFOAM-}"
|
||||
;;
|
||||
|
||||
openfoam[0-9]*) # debian naming convention 'openfoam<VERSION>'
|
||||
projectNamePrefix="openfoam"
|
||||
version="${version##openfoam}"
|
||||
;;
|
||||
esac
|
||||
# debugging:
|
||||
# echo "Installed locations:"
|
||||
# for i in projectDir prefixDir projectDirName version versionNum
|
||||
# do
|
||||
# eval echo "$i=\$$i"
|
||||
# done
|
||||
|
||||
|
||||
# Save the essential bits of information:
|
||||
@ -167,14 +210,21 @@ esac
|
||||
|
||||
case "$mode" in
|
||||
*g*) # group
|
||||
dirList="$dirList $prefix/site/$version"
|
||||
dirList="$dirList $prefix/site"
|
||||
dirList="$dirList $prefixDir/site/$version"
|
||||
dirList="$dirList $prefixDir/site"
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$mode" in
|
||||
*o*) # other (shipped)
|
||||
dirList="$dirList $prefix/$projectNamePrefix$version/etc"
|
||||
if [ -n "$versionNum" ]
|
||||
then
|
||||
# debian packaging
|
||||
dirList="$dirList $prefixDir/openfoam$versionNum/etc"
|
||||
else
|
||||
# standard packaging
|
||||
dirList="$dirList $prefixDir/${WM_PROJECT:-OpenFOAM}-$version/etc"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
set -- $dirList
|
||||
|
||||
68
bin/foamExec
68
bin/foamExec
@ -35,10 +35,8 @@
|
||||
# mpirun -np <nProcs> \
|
||||
# foamExec -v <foamVersion> <foamCommand> ... -parallel
|
||||
#
|
||||
# Note: - not consistent with foamEtcFiles - does not search 'site'
|
||||
# directories
|
||||
# - version switch -v will not work with the debian naming
|
||||
# openfoamXXX
|
||||
# SeeAlso
|
||||
# foamEtcFile
|
||||
#------------------------------------------------------------------------------
|
||||
usage() {
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
@ -48,7 +46,7 @@ Usage: ${0##*/} [OPTION] <application> ...
|
||||
|
||||
options:
|
||||
-version <ver> specify an alternative OpenFOAM version
|
||||
(default: taken from \$0 parameter)
|
||||
pass through to foamEtcFile
|
||||
-help this usage
|
||||
|
||||
* run a particular OpenFOAM version of <application>
|
||||
@ -57,54 +55,14 @@ USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
#
|
||||
# This script must exist in <foamInstall>/OpenFOAM-<VERSION>/bin/
|
||||
# or <foamInstall>/openfoam<VERSION>/bin/ (for the debian version)
|
||||
#
|
||||
# foamEtcFile is found in the same directory
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# the bindir:
|
||||
binDir="${0%/*}"
|
||||
|
||||
# the project dir:
|
||||
projectDir="${binDir%/bin}"
|
||||
export WM_PROJECT_DIR="$projectDir"
|
||||
|
||||
# the prefix dir (same as foamInstall):
|
||||
prefixDir="${projectDir%/*}"
|
||||
foamInstall="$prefixDir"
|
||||
|
||||
# the name used for the project directory
|
||||
projectDirName="${projectDir##*/}"
|
||||
|
||||
#
|
||||
# handle standard and debian naming convention
|
||||
#
|
||||
case "$projectDirName" in
|
||||
OpenFOAM-*) # standard naming convention OpenFOAM-<VERSION>
|
||||
projectNamePrefix="OpenFOAM-"
|
||||
version="${projectDirName##OpenFOAM-}"
|
||||
versionNum=$version
|
||||
;;
|
||||
|
||||
openfoam[0-9]*) # debian naming convention 'openfoam<VERSION>'
|
||||
projectNamePrefix="openfoam"
|
||||
versionNum="${projectDirName##openfoam}"
|
||||
version=$WM_PROJECT_DIR
|
||||
;;
|
||||
*)
|
||||
echo "Error : unknown/unsupported naming convention"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# debugging:
|
||||
# echo "Installed locations:"
|
||||
# for i in projectDir prefixDir foamInstall projectDirName version versionNum
|
||||
# do
|
||||
# eval echo "$i=\$$i"
|
||||
# done
|
||||
|
||||
|
||||
unset etcOpts
|
||||
# parse options
|
||||
while [ "$#" -gt 0 ]
|
||||
do
|
||||
@ -112,11 +70,10 @@ do
|
||||
-h | -help)
|
||||
usage
|
||||
;;
|
||||
-v | version)
|
||||
-v | -version)
|
||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
||||
version=$2
|
||||
versionNum=$version
|
||||
shift 2
|
||||
etcOpts="-version $2"
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
@ -129,14 +86,13 @@ do
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
[ "$#" -ge 1 ] || usage "no application specified"
|
||||
|
||||
|
||||
# find OpenFOAM settings (bashrc)
|
||||
foamDotFile="$($binDir/foamEtcFile -version $version bashrc)"
|
||||
[ $? -eq 0 ] || {
|
||||
foamDotFile="$(${0%/*}/foamEtcFile $etcOpts bashrc)" || {
|
||||
echo "Error : bashrc file could not be found for OpenFOAM-$version" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user