STYLE: minor cleanup of foamEtcFile
This commit is contained in:
parent
c1ca2f4a38
commit
cc51def1fd
142
bin/foamEtcFile
142
bin/foamEtcFile
@ -4,7 +4,7 @@
|
|||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
# This file is part of OpenFOAM.
|
# This file is part of OpenFOAM.
|
||||||
@ -34,8 +34,7 @@
|
|||||||
#
|
#
|
||||||
# For example, within the user ~/.OpenFOAM/<VER>/prefs.sh:
|
# For example, within the user ~/.OpenFOAM/<VER>/prefs.sh:
|
||||||
# \code
|
# \code
|
||||||
# foamPrefs=$($WM_PROJECT_DIR/bin/foamEtcFile -m go prefs.sh) \
|
# foamFile=$(foamEtcFile -mode go prefs.sh) && . $foamFile
|
||||||
# && _foamSource $foamPrefs
|
|
||||||
# \endcode
|
# \endcode
|
||||||
#
|
#
|
||||||
# Note
|
# Note
|
||||||
@ -43,6 +42,7 @@
|
|||||||
# or $FOAM_INST_DIR/openfoam<VERSION>/bin/ (for the debian version)
|
# or $FOAM_INST_DIR/openfoam<VERSION>/bin/ (for the debian version)
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
unset optQuiet optSilent
|
||||||
usage() {
|
usage() {
|
||||||
[ "${optQuiet:-$optSilent}" = true ] && exit 1
|
[ "${optQuiet:-$optSilent}" = true ] && exit 1
|
||||||
|
|
||||||
@ -53,21 +53,19 @@ usage() {
|
|||||||
Usage: ${0##*/} [OPTION] fileName
|
Usage: ${0##*/} [OPTION] fileName
|
||||||
${0##*/} [OPTION] -list
|
${0##*/} [OPTION] -list
|
||||||
options:
|
options:
|
||||||
-all return all files (otherwise stop after the first match)
|
-a, -all return all files (otherwise stop after the first match)
|
||||||
-list list the directories to be searched
|
-l, -list list the directories to be searched
|
||||||
-mode <mode> any combination of u(user), g(group), o(other)
|
-m, -mode MODE any combination of u(user), g(group), o(other)
|
||||||
-prefix <dir> specify an alternative installation prefix
|
-p, -prefix DIR specify an alternative installation prefix
|
||||||
-quiet suppress all normal output
|
-q, -quiet suppress all normal output
|
||||||
-silent suppress all stderr output
|
-s, -silent suppress all stderr output
|
||||||
-version <ver> specify an alternative OpenFOAM version
|
-v, -version VER specify an alternative OpenFOAM version (eg, 3.0, 1612, ...)
|
||||||
in the form Maj.Min.Rev (eg, 1.7.0)
|
|
||||||
-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
|
||||||
~OpenFOAM/fileName expansion.
|
~OpenFOAM/fileName expansion.
|
||||||
|
|
||||||
The options can also be specified as a single character
|
Many options can be specified as a single character, but must not be grouped.
|
||||||
(eg, '-q' instead of '-quiet'), but must not be grouped.
|
|
||||||
|
|
||||||
Exit status
|
Exit status
|
||||||
0 when the file is found. Print resolved path to stdout.
|
0 when the file is found. Print resolved path to stdout.
|
||||||
@ -77,60 +75,56 @@ options:
|
|||||||
USAGE
|
USAGE
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
# the bin dir:
|
# The bin dir:
|
||||||
binDir="${0%/*}"
|
binDir="${0%/*}"
|
||||||
|
|
||||||
# the project dir:
|
# The project dir:
|
||||||
projectDir="${binDir%/bin}"
|
projectDir="${binDir%/bin}"
|
||||||
|
|
||||||
# the prefix dir (same as $FOAM_INST_DIR):
|
# The prefix dir (same as $FOAM_INST_DIR):
|
||||||
prefixDir="${projectDir%/*}"
|
prefixDir="${projectDir%/*}"
|
||||||
|
|
||||||
# the name used for the project directory
|
# The name used for the project directory
|
||||||
projectDirName="${projectDir##*/}"
|
projectDirName="${projectDir##*/}"
|
||||||
|
|
||||||
# version number used for debian packaging
|
# versionNum used for debian packaging
|
||||||
unset versionNum
|
unset version versionNum
|
||||||
|
|
||||||
#
|
#
|
||||||
# handle standard and debian naming convention
|
# Handle standard and debian naming conventions
|
||||||
|
# - set version (always) and versionNum (debian only)
|
||||||
#
|
#
|
||||||
case "$projectDirName" in
|
case "$projectDirName" in
|
||||||
OpenFOAM-*) # standard naming convention OpenFOAM-<VERSION>
|
OpenFOAM-*) # standard naming: OpenFOAM-<VERSION>
|
||||||
version="${projectDirName##OpenFOAM-}"
|
version="${projectDirName##OpenFOAM-}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
openfoam[0-9]* | openfoam-dev) # debian naming convention 'openfoam<VERSION>'
|
openfoam[0-9]* | openfoam-dev) # debian naming: openfoam<VERSION>
|
||||||
versionNum="${projectDirName##openfoam}"
|
versionNum="${projectDirName##openfoam}"
|
||||||
case "$versionNum" in
|
case "${#versionNum}" in
|
||||||
??) # convert 2 digit version number to decimal delineated
|
(2|3|4) # Convert digits version number to decimal delineated
|
||||||
version=$(echo "$versionNum" | sed -e 's@\(.\)\(.\)@\1.\2@')
|
version=$(echo "$versionNum" | sed -e 's@\([0-9]\)@\1.@g')
|
||||||
|
version="${version%.}"
|
||||||
;;
|
;;
|
||||||
???) # convert 3 digit version number to decimal delineated
|
|
||||||
version=$(echo "$versionNum" | sed -e 's@\(.\)\(.\)\(.\)@\1.\2.\3@')
|
(*) # Fallback - use current environment setting
|
||||||
;;
|
|
||||||
????) # 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"
|
version="$WM_PROJECT_VERSION"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo "Error : unknown/unsupported naming convention"
|
echo "${0##*/} Error : unknown/unsupported naming convention" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
# default mode is 'ugo'
|
# Default mode is always 'ugo'
|
||||||
mode=ugo
|
mode=ugo
|
||||||
unset optAll optList optQuiet optSilent
|
unset optAll optList
|
||||||
|
|
||||||
# parse options
|
# parse options
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
@ -145,23 +139,36 @@ do
|
|||||||
-l | -list)
|
-l | -list)
|
||||||
optList=true
|
optList=true
|
||||||
;;
|
;;
|
||||||
|
-mode=[ugo]*)
|
||||||
|
mode="${1#-mode=}"
|
||||||
|
;;
|
||||||
|
-prefix=/*)
|
||||||
|
prefixDir="${1#-prefix=}"
|
||||||
|
prefixDir="${prefixDir%/}"
|
||||||
|
;;
|
||||||
|
-version=*)
|
||||||
|
version="${1#-version=}"
|
||||||
|
# convert x.y.z -> xyz version (if installation looked like debian)
|
||||||
|
if [ -n "$versionNum" ]
|
||||||
|
then
|
||||||
|
versionNum=$(echo "$version" | sed -e 's@\.@@g')
|
||||||
|
fi
|
||||||
|
;;
|
||||||
-m | -mode)
|
-m | -mode)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
|
||||||
mode="$2"
|
mode="$2"
|
||||||
|
# Sanity check. Handles missing argument too.
|
||||||
# sanity check:
|
|
||||||
case "$mode" in
|
case "$mode" in
|
||||||
*u* | *g* | *o* )
|
[ugo]*)
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
usage "'$1' option with invalid mode '$mode'"
|
usage "invalid mode '$mode'"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-p | -prefix)
|
-p | -prefix)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
||||||
prefixDir="$2"
|
prefixDir="${2%/}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-q | -quiet)
|
-q | -quiet)
|
||||||
@ -185,7 +192,7 @@ do
|
|||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "unknown option: '$*'"
|
usage "unknown option: '$1'"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
@ -194,6 +201,14 @@ do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Update projectDir accordingly
|
||||||
|
if [ -n "$versionNum" ]
|
||||||
|
then
|
||||||
|
projectDir="$prefixDir/openfoam$versionNum" # debian
|
||||||
|
else
|
||||||
|
projectDir="$prefixDir/${WM_PROJECT:-OpenFOAM}-$version" # standard
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# debugging:
|
# debugging:
|
||||||
# echo "Installed locations:"
|
# echo "Installed locations:"
|
||||||
@ -210,30 +225,20 @@ fileName="${1#~OpenFOAM/}"
|
|||||||
|
|
||||||
# Define the various places to be searched:
|
# Define the various places to be searched:
|
||||||
unset dirList
|
unset dirList
|
||||||
case "$mode" in
|
case "$mode" in (*u*) # user
|
||||||
*u*) # user
|
dir="$HOME/.${WM_PROJECT:-OpenFOAM}"
|
||||||
userDir="$HOME/.${WM_PROJECT:-OpenFOAM}"
|
dirList="$dirList $dir/$version $dir"
|
||||||
dirList="$dirList $userDir/$version $userDir"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$mode" in
|
case "$mode" in (*g*) # group (site)
|
||||||
*g*) # group (site)
|
dir="${WM_PROJECT_SITE:-$prefixDir/site}"
|
||||||
siteDir="${WM_PROJECT_SITE:-$prefixDir/site}"
|
dirList="$dirList $dir/$version $dir"
|
||||||
dirList="$dirList $siteDir/$version $siteDir"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$mode" in
|
case "$mode" in (*o*) # other (shipped)
|
||||||
*o*) # other (shipped)
|
dirList="$dirList $projectDir/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
|
esac
|
||||||
set -- $dirList
|
set -- $dirList
|
||||||
@ -275,13 +280,10 @@ else
|
|||||||
if [ -f "$dir/$fileName" ]
|
if [ -f "$dir/$fileName" ]
|
||||||
then
|
then
|
||||||
exitCode=0
|
exitCode=0
|
||||||
if [ "$optQuiet" = true ]
|
[ "$optQuiet" = true ] && break
|
||||||
then
|
|
||||||
break
|
echo "$dir/$fileName"
|
||||||
else
|
[ "$optAll" = true ] || break
|
||||||
echo "$dir/$fileName"
|
|
||||||
[ "$optAll" = true ] || break
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ then
|
|||||||
# Retrieve OPENFOAM_PLUS=<digits> from $WM_DIR/rules/General/general
|
# Retrieve OPENFOAM_PLUS=<digits> from $WM_DIR/rules/General/general
|
||||||
version=$(
|
version=$(
|
||||||
sed -ne 's@^.*OPENFOAM_PLUS=\([0-9][0-9]*\).*@\1@p' \
|
sed -ne 's@^.*OPENFOAM_PLUS=\([0-9][0-9]*\).*@\1@p' \
|
||||||
$WM_DIR/rules/General/general 2>/dev/null | tail -1
|
$WM_DIR/rules/General/general 2>/dev/null
|
||||||
)
|
)
|
||||||
|
|
||||||
if [ -n "$version" ]
|
if [ -n "$version" ]
|
||||||
|
Loading…
Reference in New Issue
Block a user