ENH: Added utility to check completeness of installation
[freefoam.git] / data / utilities / foamUpdateCaseFileHeader.in
blob0edab5b78c1c5e8bcdbad15690be5896b06d215b
1 #!/bin/sh
2 #---------------------------------*- sh -*-------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-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 # foamUpdateCaseFileHeader
28 # Description
29 # Updates the header of application files.
30 # By default, writes current version in the header.
31 # Alternatively version can be specified with -v option.
32 # Also removes consecutive blank lines from file.
34 #------------------------------------------------------------------------------
35 foamVersion=@FOAM_VERSION@
37 usage() {
38 cat<<USAGE
40 Usage: ${0##*/} [OPTION] <file1> ... <fileN>
42 options:
43 -v VER specifies the version to be written in the header
44 -h help
46 Updates the header of application files and removes consecutive blank lines.
47 By default, writes current OpenFOAM version in the header.
48 An alternative version can be specified with the -v option.
50 USAGE
51 exit 1
55 printHeader() {
56 cat<<HEADER
57 /*------------------------------*- FOAMDict -*-------------------------------*\\
58 | ______ _ ____ __ __ |
59 | | ____| _| |_ / __ \\ /\\ | \\/ | |
60 | | |__ _ __ ___ ___ / \\| | | | / \\ | \\ / | |
61 | | __| '__/ _ \\/ _ ( (| |) ) | | |/ /\\ \\ | |\\/| | |
62 | | | | | | __/ __/\\_ _/| |__| / ____ \\| | | | |
63 | |_| |_| \\___|\\___| |_| \\____/_/ \\_\\_| |_| |
64 | |
65 | FreeFOAM: The Cross-Platform CFD Toolkit |
66 | Version: ${foamVersion} |
67 | Web: http://freefoam.sourceforge.net |
68 \\*---------------------------------------------------------------------------*/
69 FoamFile
71 version 2.0;
72 format ${1};
73 class ${2};
74 object ${3};
76 HEADER
81 # extract attribute '$1' from file '$2'
83 FoamFileAttribute() {
84 sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
89 # OPTIONS
91 opts=$(getopt hv: $*)
92 if [ $? -ne 0 ]
93 then
94 echo "Aborting due to invalid option"
95 usage
97 eval set -- '$opts'
98 while [ "$1" != "--" ]
100 case $1 in
102 foamVersion=$2
103 shift
106 usage
108 esac
109 shift
110 done
111 shift
113 [ $# -ge 1 ] || usage
116 # constant width for version
117 foamVersion=$(printf %-36s $foamVersion)
120 # MAIN
122 unset NOTE
124 for caseFile
126 if grep FoamFile $caseFile >/dev/null 2>&1
127 then
128 echo "Updating case file: $caseFile"
129 sed -n '/FoamFile/,/}/p' $caseFile > FoamFile.tmp
131 FORMAT=$(FoamFileAttribute format FoamFile.tmp)
132 CLASS=$(FoamFileAttribute class FoamFile.tmp)
133 OBJECT=$(FoamFileAttribute object FoamFile.tmp)
134 # extract NOTE?
136 printHeader $FORMAT $CLASS $OBJECT $NOTE > FoamFile.tmp
137 sed '1,/}/d' $caseFile | sed '/./,/^$/!d' >> FoamFile.tmp
139 # use cat to avoid removing/replace soft-links
140 [ -s FoamFile.tmp ] && cat FoamFile.tmp >| $caseFile
141 rm -f FoamFile.tmp 2>/dev/null
142 else
143 echo " Invalid case file: $caseFile" 1>&2
145 done
147 #------------------------------------------------------------------------------