2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
8 #-------------------------------------------------------------------------------
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
29 # Locate user/group/shipped file with semantics similar to the
30 # ~OpenFOAM/fileName expansion.
32 # The -mode option can be used to allow chaining from
33 # personal settings to site-wide settings.
35 # For example, within the user ~/.OpenFOAM/<VER>/prefs.sh:
37 # foamPrefs=`$WM_PROJECT_DIR/bin/foamEtcFile -m go prefs.sh` \
38 # && _foamSource $foamPrefs
42 # This script must exist in <foamInstall>/OpenFOAM-<VERSION>/bin/
43 # or <foamInstall>/openfoam<VERSION>/bin/ (for the debian version)
45 #-------------------------------------------------------------------------------
47 [ "${optQuiet:-$optSilent}" = true
] && exit 1
50 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
53 Usage: ${0##*/} [OPTION] fileName
54 ${0##*/} [OPTION] -list
56 -all return all files (otherwise stop after the first match)
57 -list list the directories to be searched
58 -mode <mode> any combination of u(user), g(group), o(other)
59 -prefix <dir> specify an alternative installation prefix
60 -quiet suppress all normal output
61 -silent suppress all stderr output
62 -version <ver> specify an alternative OpenFOAM version
63 in the form Maj.Min.Rev (eg, 1.7.0)
66 Locate user/group/shipped file with semantics similar to the
67 ~OpenFOAM/fileName expansion.
69 The options can also be specified as a single character
70 (eg, '-q' instead of '-quiet'), but must not be grouped.
73 0 when the file is found. Print resolved path to stdout.
74 1 for miscellaneous errors.
75 2 when the file is not found.
81 #-------------------------------------------------------------------------------
87 projectDir
="${binDir%/bin}"
89 # the prefix dir (same as foamInstall):
90 prefixDir
="${projectDir%/*}"
92 # the name used for the project directory
93 projectDirName
="${projectDir##*/}"
95 # version number used for debian packaging
99 # handle standard and debian naming convention
101 case "$projectDirName" in
102 OpenFOAM-
*) # standard naming convention OpenFOAM-<VERSION>
103 version
="${projectDirName##OpenFOAM-}"
106 openfoam
[0-9]*) # debian naming convention 'openfoam<VERSION>'
107 versionNum
="${projectDirName##openfoam}"
108 case "$versionNum" in
109 ??
) # convert 2 digit version number to decimal delineated
110 version
=$
(echo "$versionNum" |
sed -e 's@\(.\)\(.\)@\1.\2@')
112 ???
) # convert 3 digit version number to decimal delineated
113 version
=$
(echo "$versionNum" |
sed -e 's@\(.\)\(.\)\(.\)@\1.\2.\3@')
115 ????
) # convert 4 digit version number to decimal delineated
116 version
=$
(echo "$versionNum" |
sed -e 's@\(.\)\(.\)\(.\)\(.\)@\1.\2.\3.\4@')
118 *) # failback - use current environment setting
119 version
="$WM_PROJECT_VERSION"
125 echo "Error : unknown/unsupported naming convention"
131 # default mode is 'ugo'
133 unset optAll optList optQuiet optSilent
149 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
157 usage
"'$1' option with invalid mode '$mode'"
163 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
174 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
176 # convert x.y.z -> xyz version (if installation looked like debian)
177 if [ -n "$versionNum" ]
179 versionNum
=$
(echo "$version" |
sed -e 's@\.@@g')
188 usage
"unknown option: '$*'"
199 # echo "Installed locations:"
200 # for i in projectDir prefixDir projectDirName version versionNum
202 # eval echo "$i=\$$i"
206 # Save the essential bits of information
207 # silently remove leading ~OpenFOAM/ (used in Foam::findEtcFile)
209 fileName
="${1#~OpenFOAM/}"
211 # Define the various places to be searched:
215 userDir
="$HOME/.${WM_PROJECT:-OpenFOAM}"
216 dirList
="$dirList $userDir/$version $userDir"
222 siteDir
="${WM_PROJECT_SITE:-$prefixDir/site}"
223 dirList
="$dirList $siteDir/$version $siteDir"
228 *o
*) # other (shipped)
229 if [ -n "$versionNum" ]
232 dirList
="$dirList $prefixDir/openfoam$versionNum/etc"
235 dirList
="$dirList $prefixDir/${WM_PROJECT:-OpenFOAM}-$version/etc"
247 if [ "$optList" = true
]
250 # list directories, or potential file locations
251 [ "$nArgs" -le 1 ] || usage
253 # a silly combination, but -quiet does have precedence
254 [ "$optQuiet" = true
] && exit 0
258 if [ "$nArgs" -eq 1 ]
260 echo "$dir/$fileName"
268 [ "$nArgs" -eq 1 ] || usage
270 # general error, eg file not found
275 if [ -f "$dir/$fileName" ]
278 if [ "$optQuiet" = true
]
282 echo "$dir/$fileName"
283 [ "$optAll" = true
] ||
break
293 #------------------------------------------------------------------------------