STYLE: linearAxialAngularSpring: indentation
[OpenFOAM-2.0.x.git] / bin / foamPackBin
blob23c8ecbe28b6f5f6c0323ab499d136ec5acb46a2
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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 # foamPackBin [OPTION] <archOptions>
28 # Description
29 # Pack and compress binary version of OpenFOAM for release
31 # Script
32 # foamPackThirdPartyBin [OPTION] <archOptions>
34 # Description
35 # Pack and compress binary version of OpenFOAM ThirdParty for release
37 #------------------------------------------------------------------------------
38 toolsDir="${0%/*}/tools" # this script is located in the tools/ parent dir
40 case "${0##*/}" in
41 *ThirdParty*)
42 # for ThirdParty
43 codeBase="OpenFOAM ThirdParty"
44 packDir=ThirdParty-$WM_PROJECT_VERSION
45 listBinDirs=$toolsDir/foamListThirdPartyBinDirs
48 # regular
49 codeBase="OpenFOAM"
50 packDir=$WM_PROJECT-$WM_PROJECT_VERSION
51 listBinDirs=$toolsDir/foamListBinDirs
53 esac
56 usage() {
57 exec 1>&2
58 while [ "$#" -gt 0 ]; do echo "$1"; shift; done
59 cat <<USAGE
60 Usage: ${0##*/} [OPTION] <archOptions>
61 ${0##*/} [OPTION] -current
62 options:
63 -b, -bzip2 use bzip2 instead of gzip compression
64 -c, -current use current value of \$WM_OPTIONS
65 -o, -output <dir> specify alternative output directory
67 * Pack and compress binary version of $codeBase for release
69 The value of 'archOptions' normally corresponds to \$WM_OPTIONS
70 The current value of \$WM_OPTIONS = $WM_OPTIONS
72 USAGE
73 exit 1
77 unset archOptions outputDir
78 packExt=tgz
80 # parse options
81 while [ "$#" -gt 0 ]
83 case "$1" in
84 -h | -help)
85 usage
87 -b | -bzip2)
88 packExt=tbz
89 shift
91 -c | -current) # use $WM_OPTIONS - eg, 'linux64GccDPOpt'
92 archOptions="$WM_OPTIONS"
93 shift
95 -o | -output)
96 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
97 outputDir=${2%%/}
98 shift 2
101 usage "unknown option: '$*'"
104 break
106 esac
107 done
109 if [ -n "$archOptions" ]
110 then
111 [ $# -eq 0 ] || usage "Error: cannot specify both -current and architecture"
112 else
113 archOptions="$1"
114 [ $# -eq 1 ] || usage "Error: specify architecture"
118 #------------------------------------------------------------------------------
119 timeStamp=$(date +%Y-%m-%d)
120 packBase=${packDir}.${archOptions}_${timeStamp}
122 # add optional output directory
123 [ -d "$outputDir" ] && packBase="$outputDir/$packBase"
124 packFile=$packBase.$packExt
126 # avoid overwriting old pack file
127 if [ -f $packFile ]
128 then
129 echo "Error: $packFile already exists" 1>&2
130 exit 1
134 #------------------------------------------------------------------------------
136 # get list of directories
137 dirList=$( $listBinDirs $packDir $archOptions )
138 if [ $? -eq 0 -a -n "$dirList" ]
139 then
140 echo "Pack into $packFile" 1>&2
141 echo 1>&2
142 else
143 exit 1
146 # bzip2 or gzip compression
147 case "$packFile" in
148 *tbz)
149 tarOpt=cpjf
152 tarOpt=cpzf
154 esac
156 # Clean up on Ctrl-C
157 trap 'rm -f $packFile 2>/dev/null' INT
159 tar $tarOpt $packFile $dirList
160 if [ $? -eq 0 ]
161 then
162 echo "Finished packing file $packFile" 1>&2
163 else
164 echo "Error: failure packing $packFile" 1>&2
165 rm -f $packFile 2>/dev/null
168 #------------------------------------------------------------------------------