2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
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 [ "${quietOpt:-$silentOpt}" = true
] && exit 1
50 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
53 Usage: ${0##*/} [OPTION] fileName
54 ${0##*/} [OPTION] -list
56 -list list the directories to be searched
57 -mode <mode> any combination of u(user), g(group), o(other)
58 -prefix <dir> specify an alternative installation prefix
59 -quiet suppress all normal output
60 -silent suppress all stderr output
61 -version <ver> specify an alternative OpenFOAM version
62 in the form Maj.Min.Rev (eg, 1.7.0)
65 Locate user/group/shipped file with semantics similar to the
66 ~OpenFOAM/fileName expansion.
68 The options can also be specified as a single character
69 (eg, '-q' instead of '-quiet'), but must not be grouped.
72 0 when the file is found. Print resolved path to stdout.
73 1 for miscellaneous errors.
74 2 when the file is not found.
80 #-------------------------------------------------------------------------------
86 projectDir
="${binDir%/bin}"
88 # the prefix dir (same as foamInstall):
89 prefixDir
="${projectDir%/*}"
91 # the name used for the project directory
92 projectDirName
="${projectDir##*/}"
94 # version number used for debian packaging
98 # handle standard and debian naming convention
100 case "$projectDirName" in
101 OpenFOAM-
*) # standard naming convention OpenFOAM-<VERSION>
102 version
="${projectDirName##OpenFOAM-}"
105 openfoam
[0-9]*) # debian naming convention 'openfoam<VERSION>'
106 versionNum
="${projectDirName##openfoam}"
107 case "$versionNum" in
108 ??
) # convert 2 digit version number to decimal delineated
109 version
=$
(echo "$versionNum" |
sed -e 's@\(.\)\(.\)@\1.\2@')
111 ???
) # convert 3 digit version number to decimal delineated
112 version
=$
(echo "$versionNum" |
sed -e 's@\(.\)\(.\)\(.\)@\1.\2.\3@')
114 ????
) # convert 4 digit version number to decimal delineated
115 version
=$
(echo "$versionNum" |
sed -e 's@\(.\)\(.\)\(.\)\(.\)@\1.\2.\3.\4@')
117 *) # failback - use current environment setting
118 version
="$WM_PROJECT_VERSION"
124 echo "Error : unknown/unsupported naming convention"
130 # default mode is 'ugo'
132 unset listOpt quietOpt silentOpt
145 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
153 usage
"'$1' option with invalid mode '$mode'"
159 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
170 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
172 # convert x.y.z -> xyz version (if installation looked like debian)
173 if [ -n "$versionNum" ]
175 versionNum
=$
(echo "$version" |
sed -e 's@\.@@g')
184 usage
"unknown option: '$*'"
195 # echo "Installed locations:"
196 # for i in projectDir prefixDir projectDirName version versionNum
198 # eval echo "$i=\$$i"
202 # Save the essential bits of information
203 # silently remove leading ~OpenFOAM/ (used in Foam::findEtcFile)
205 fileName
="${1#~OpenFOAM/}"
207 # Define the various places to be searched:
211 userDir
="$HOME/.${WM_PROJECT:-OpenFOAM}"
212 dirList
="$dirList $userDir/$version $userDir"
218 siteDir
="${WM_PROJECT_SITE:-$prefixDir/site}"
219 dirList
="$dirList $siteDir/$version $siteDir"
224 *o
*) # other (shipped)
225 if [ -n "$versionNum" ]
228 dirList
="$dirList $prefixDir/openfoam$versionNum/etc"
231 dirList
="$dirList $prefixDir/${WM_PROJECT:-OpenFOAM}-$version/etc"
242 if [ "$listOpt" = true
]
245 # list directories, or potential file locations
246 [ "$nArgs" -le 1 ] || usage
248 # a silly combination, but -quiet does have precedence
249 [ "$quietOpt" = true
] && exit 0
253 if [ "$nArgs" -eq 1 ]
255 echo "$dir/$fileName"
264 [ "$nArgs" -eq 1 ] || usage
268 if [ -f "$dir/$fileName" ]
270 [ "$quietOpt" = true
] ||
echo "$dir/$fileName"
278 # general error, eg file not found
281 #------------------------------------------------------------------------------