2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 2008-2010 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
41 #------------------------------------------------------------------------------
43 [ "$quietOpt" = true
] && exit 1
46 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
49 Usage: ${0##*/} [OPTION] fileName
50 ${0##*/} [OPTION] -list
52 -list list the directories to be searched
53 -mode <mode> any combination of u(user), g(group), o(other)
54 -prefix <dir> specify an alternative installation prefix
55 -quiet suppress all normal output
56 -version <ver> specify an alternative OpenFOAM version
57 in the form Maj.Min.Rev (eg, 1.7.0)
60 Locate user/group/shipped file with semantics similar to the
61 ~OpenFOAM/fileName expansion.
63 The options can also be specified as a single character
64 (eg, '-q' instead of '-quiet'), but must not be grouped.
67 0 when the file is found. Print resolved path to stdout.
68 1 for miscellaneous errors.
69 2 when the file is not found.
76 # This script must exist in <foamInstall>/OpenFOAM-<VERSION>/bin/
77 # or <foamInstall>/openfoam<VERSION>/bin/ (for the debian version)
79 #------------------------------------------------------------------------------
85 projectDir
="${binDir%/bin}"
87 # the prefix dir (same as foamInstall):
88 prefixDir
="${projectDir%/*}"
90 # the name used for the project directory
91 projectDirName
="${projectDir##*/}"
93 # version number used for debian packaging
97 # handle standard and debian naming convention
99 case "$projectDirName" in
100 OpenFOAM-
*) # standard naming convention OpenFOAM-<VERSION>
101 version
="${projectDirName##OpenFOAM-}"
104 openfoam
[0-9]*) # debian naming convention 'openfoam<VERSION>'
105 versionNum
="${projectDirName##openfoam}"
106 case "$versionNum" in
107 ??
) # convert 2 digit version number to decimal delineated
108 version
=$
(echo "$versionNum" |
sed -e 's@\(.\)\(.\)@\1.\2@')
110 ???
) # convert 3 digit version number to decimal delineated
111 version
=$
(echo "$versionNum" |
sed -e 's@\(.\)\(.\)\(.\)@\1.\2.\3@')
113 ????
) # convert 4 digit version number to decimal delineated
114 version
=$
(echo "$versionNum" |
sed -e 's@\(.\)\(.\)\(.\)\(.\)@\1.\2.\3.\4@')
116 *) # failback - use current environment setting
117 version
="$WM_PROJECT_VERSION"
123 echo "Error : unknown/unsupported naming convention"
129 # default mode is 'ugo'
131 unset listOpt quietOpt
144 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
152 usage
"'$1' option with invalid mode '$mode'"
158 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
166 [ "$#" -ge 2 ] || usage
"'$1' option requires an argument"
168 # convert x.y.z -> xyz version (if installation looked like debian)
169 if [ -n "$versionNum" ]
171 versionNum
=$
(echo "$version" |
sed -e 's@\.@@g')
180 usage
"unknown option: '$*'"
191 # echo "Installed locations:"
192 # for i in projectDir prefixDir projectDirName version versionNum
194 # eval echo "$i=\$$i"
198 # Save the essential bits of information
199 # silently remove leading ~OpenFOAM/ (used in Foam::findEtcFile)
201 fileName
="${1#~OpenFOAM/}"
203 # Define the various places to be searched:
207 dirList
="$dirList $HOME/.${WM_PROJECT:-OpenFOAM}/$version"
208 dirList
="$dirList $HOME/.${WM_PROJECT:-OpenFOAM}"
214 dirList
="$dirList $prefixDir/site/$version"
215 dirList
="$dirList $prefixDir/site"
220 *o
*) # other (shipped)
221 if [ -n "$versionNum" ]
224 dirList
="$dirList $prefixDir/openfoam$versionNum/etc"
227 dirList
="$dirList $prefixDir/${WM_PROJECT:-OpenFOAM}-$version/etc"
238 if [ "$listOpt" = true
]
241 # list directories, or potential file locations
242 [ "$nArgs" -le 1 ] || usage
244 # a silly combination, but -quiet has precedence
245 [ "$quietOpt" = true
] && exit 0
249 if [ "$nArgs" -eq 1 ]
251 echo "$dir/$fileName"
260 [ "$nArgs" -eq 1 ] || usage
264 if [ -f "$dir/$fileName" ]
266 [ "$quietOpt" = true
] ||
echo "$dir/$fileName"
274 # general error, eg file not found
277 #------------------------------------------------------------------------------