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/>.
26 # foamPackSource <directory> <tarFile>
29 # Pack and compress all source files from a given directory.
32 # Not normally called directly by the user
33 #------------------------------------------------------------------------------
34 tmpFile
=${TMPDIR:-/tmp}/foamPackFiles.$$
35 toolsDir
="${0%/*}/tools" # this script is located in the tools/ parent dir
39 Usage : ${0##*/} directory tarFile
41 * Pack and compress all source files from a given directory into <tarFile>
47 # canonical form (no double and no trailing dashes)
48 packDir
=$
(echo "$1" |
sed -e 's@//*@/@g' -e 's@/$@@')
51 # check for essential directories
53 echo "Error: directory $packDir does not exist" 1>&2
58 # avoid overwriting old pack file
61 echo "Error: $packFile already exists" 1>&2
65 # Clean up on termination and on Ctrl-C
66 trap 'rm -f $tmpFile 2>/dev/null; exit 0' EXIT TERM INT
69 $toolsDir/foamListSourceFiles
$packDir > $tmpFile
72 # provide some feedback
74 -------------------------------------------------------------------------------
75 Packing $packDir source files into $packFile
78 wc $tmpFile |
awk '{print "Packing",$1,"files - this could take some time ..."}' 1>&2
81 # bzip2 or gzip compression
92 trap 'rm -f $packFile $tmpFile 2>/dev/null' INT
94 tar $tarOpt $packFile --files-from $tmpFile
97 echo "Finished packing $packDir into $packFile" 1>&2
99 echo "Error: failure packing $packDir into $packFile" 1>&2
100 rm -f $packFile 2>/dev
/null
103 #------------------------------------------------------------------------------