ThirdParty packages: Add comment in README file. Contributed by Darrin Stephens
[OpenFOAM-1.6-ext.git] / bin / foamEtcFile
blob3413aa1d0bb9bce114945f8402827a81c782a817
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
7 # \\/ M anipulation |
8 #------------------------------------------------------------------------------
9 # License
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
20 # for more details.
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/>.
25 # Script
26 # foamEtcFile
28 # Description
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:
36 # @verbatim
37 # foamPrefs=`$WM_PROJECT_DIR/bin/foamEtcFile -m go prefs.sh` \
38 # && _foamSource $foamPrefs
39 # @endverbatim
41 #------------------------------------------------------------------------------
42 usage() {
43 [ "$quietOpt" = true ] && exit 1
45 exec 1>&2
46 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
47 cat<<USAGE
49 Usage: ${0##*/} [OPTION] fileName
50 ${0##*/} [OPTION] -list
51 options:
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)
58 -help print the usage
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.
66 Exit status
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.
71 USAGE
72 exit 1
76 # This script must exist in <foamInstall>/OpenFOAM-<VERSION>/bin/
77 # or <foamInstall>/openfoam<VERSION>/bin/ (for the debian version)
79 #------------------------------------------------------------------------------
81 # the bindir:
82 binDir="${0%/*}"
84 # the project dir:
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
94 unset versionNum
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"
119 esac
123 echo "Error : unknown/unsupported naming convention"
124 exit 1
126 esac
129 # default mode is 'ugo'
130 mode=ugo
131 unset listOpt quietOpt
133 # parse options
134 while [ "$#" -gt 0 ]
136 case "$1" in
137 -h | -help)
138 usage
140 -l | -list)
141 listOpt=true
143 -m | -mode)
144 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
145 mode="$2"
147 # sanity check:
148 case "$mode" in
149 *u* | *g* | *o* )
152 usage "'$1' option with invalid mode '$mode'"
154 esac
155 shift
157 -p | -prefix)
158 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
159 prefixDir="$2"
160 shift
162 -q | -quiet)
163 quietOpt=true
165 -v | -version)
166 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
167 version="$2"
168 # convert x.y.z -> xyz version (if installation looked like debian)
169 if [ -n "$versionNum" ]
170 then
171 versionNum=$(echo "$version" | sed -e 's@\.@@g')
173 shift
176 shift
177 break
180 usage "unknown option: '$*'"
183 break
185 esac
186 shift
187 done
190 # debugging:
191 # echo "Installed locations:"
192 # for i in projectDir prefixDir projectDirName version versionNum
193 # do
194 # eval echo "$i=\$$i"
195 # done
198 # Save the essential bits of information
199 # silently remove leading ~OpenFOAM/ (used in Foam::findEtcFile)
200 nArgs=$#
201 fileName="${1#~OpenFOAM/}"
203 # Define the various places to be searched:
204 unset dirList
205 case "$mode" in
206 *u*) # user
207 dirList="$dirList $HOME/.${WM_PROJECT:-OpenFOAM}/$version"
208 dirList="$dirList $HOME/.${WM_PROJECT:-OpenFOAM}"
210 esac
212 case "$mode" in
213 *g*) # group
214 dirList="$dirList $prefixDir/site/$version"
215 dirList="$dirList $prefixDir/site"
217 esac
219 case "$mode" in
220 *o*) # other (shipped)
221 if [ -n "$versionNum" ]
222 then
223 # debian packaging
224 dirList="$dirList $prefixDir/openfoam$versionNum/etc"
225 else
226 # standard packaging
227 dirList="$dirList $prefixDir/${WM_PROJECT:-OpenFOAM}-$version/etc"
230 esac
231 set -- $dirList
235 # The main routine
238 if [ "$listOpt" = true ]
239 then
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
247 for dir
249 if [ "$nArgs" -eq 1 ]
250 then
251 echo "$dir/$fileName"
252 else
253 echo "$dir"
255 done
256 exit 0
258 else
260 [ "$nArgs" -eq 1 ] || usage
262 for dir
264 if [ -f "$dir/$fileName" ]
265 then
266 [ "$quietOpt" = true ] || echo "$dir/$fileName"
267 exit 0
269 done
274 # general error, eg file not found
275 exit 2
277 #------------------------------------------------------------------------------