ENH: Rewrite of foamPackSource for FreeFOAM
[freefoam.git] / data / utilities / foamPackSource
blobfe895a18b713c162691b99a5b3cb48b9b9ac62e1
1 #!/bin/sh
2 #-------------------------------------------------------------------------------
3 # ______ _ ____ __ __
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2009 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
15 # License
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software; you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation; either version 2 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 # for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM; if not, write to the Free Software Foundation,
30 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 # Script
33 # foamPackSource [-h|--help]
34 # [-c|--create-tag [-t|--tag-key <keyId>] [-m|--tag-msg <msg>]]
35 # [-s|--sign-key <keyId>] <version> <outputDir>
37 # Description
38 # Creates a source tar-ball for a given <version> in <outputDir>.
40 # The <version> argument requires that a git tree-ish object with the name
41 # v<version> exists (i.e. a tag named e.g. v0.1.0). If no such tag exists,
42 # you can specify -c and the current HEAD will be tagged as v<version>. The
43 # output is named <outputDir>/freefoam-<version>.tar.bz2 and a detached
44 # signature is created using the users default GPG-key in
45 # <outputDir>/freefoam-<version>.tar.bz2.sig (can be overriden using -s).
46 # Further the md5 and sha1 digests are computed and placed in
47 # <outputDir>/freefoam-<version>.tar.bz2.md5 and
48 # <outputDir>/freefoam-<version>.tar.bz2.sha1, respectively.
50 # -h
51 # --help Print a help message
52 # -c
53 # --create-tag Create a tag named v<version>. By default it is signed
54 # by the default e-mail address's GPG-key.
55 # -t <keyId>
56 # --tag-key <keyId> If -c is used, specify a different GPG-key ID to sign.
57 # -m <msg>
58 # --tag-msg <msg> Instead of prompting, use the given tag-message when
59 # -c is specified.
60 # -s <keyId>
61 # --sign-key <keyId> Sign the created tar-ball using the GPG-key <keyId>
62 # instead of using the default key.
63 # -u
64 # --upload Upload to sourceforge.net.
65 # <version> Specify the version for which to create the source
66 # tar-ball. This expects a git object with the name
67 # v<version> to exist, which should be a tag.
68 # <outputDir> The directory in which to place the tar-ball.
70 #------------------------------------------------------------------------------
72 usage() {
73 cat >&2 << _EOF_
75 Usage: $0 [-h|--help]
76 [-c|--create-tag [-t|--tag-key <keyId>] [-m|--tag-msg <msg>]]
77 [-s|--sign-key <keyId>] <version> <outputDir>
79 Creates a source tar-ball for a given <version> in <outputDir>.
81 The <version> argument requires that a git tree-ish object with the name
82 v<version> exists (i.e. a tag named e.g. v0.1.0). If no such tag exists, you
83 can specify -c and the current HEAD will be tagged as v<version>. The output
84 is named <outputDir>/freefoam-<version>.tar.bz2 and a detached signature is
85 created using the users default GPG-key in
86 <outputDir>/freefoam-<version>.tar.bz2.sig (can be overriden using -s).
87 Further the md5 and sha1 digests are computed and placed in
88 <outputDir>/freefoam-<version>.tar.bz2.md5 and
89 <outputDir>/freefoam-<version>.tar.bz2.sha1, respectively.
92 --help Print a help message
94 --create-tag Create a tag named v<version>. By default it is signed
95 by the default e-mail address's GPG-key.
96 -t <keyId>
97 --tag-key <keyId> If -c is used, specify a different GPG-key ID to sign.
98 -m <msg>
99 --tag-msg <msg> Instead of prompting, use the given tag-message when
100 -c is specified.
101 -s <keyId>
102 --sign-key <keyId> Sign the created tar-ball using the GPG-key <keyId>
103 instead of using the default key.
105 --upload Upload to sourceforge.net.
106 <version> Specify the version for which to create the source
107 tar-ball. This expects a git object with the name
108 v<version> to exist, which should be a tag.
109 <outputDir> The directory in which to place the tar-ball.
111 _EOF_
112 if [ $# -gt 0 ]; then
113 exit $1
114 else
115 exit 0
119 abort() {
120 echo "$1" >&2
121 exit 1
124 if [ $# -lt 2 ]; then
125 usage 1
128 CREATE_TAG=no
129 CUSTOM_TAG_KEY=
130 TAG_MSG=
131 SIGN_KEY=
132 DO_UPLOAD=no
133 VERSION=
134 OUTPUT_DIR=
136 while [ $# -gt 0 ]; do
137 case "x$1" in
138 x-h|x--help)
139 usage
141 x-c|x--create-tag)
142 CREATE_TAG=yes
143 shift
145 x-t|x--tag-key)
146 if [ $# -lt 4 ]; then
147 usage 1
149 CUSTOM_TAG_KEY="$2"
150 shift 2
152 x-m|x--tag-msg)
153 if [ $# -lt 4 ]; then
154 usage 1
156 TAG_MSG="$2"
157 shift 2
159 x-s|x--sign-key)
160 if [ $# -lt 4 ]; then
161 usage 1
163 SIGN_KEY="--default-key $2"
164 shift 2
166 x-u|x--upload)
167 DO_UPLOAD=yes
168 shift
171 if [ $# -lt 2 ]; then
172 usage 1
174 VERSION="$1"
175 OUTPUT_DIR="$2"
176 shift 2
177 break
179 esac
180 done
182 if [ -z "$VERSION" -o -z "$OUTPUT_DIR" ]; then
183 usage 1
186 if ! [ -d "$OUTPUT_DIR" -a -w "$OUTPUT_DIR" ]; then
187 echo "Error: The output directory '$OUTPUT_DIR' does not exist or is not writeable" >&2
188 usage 1
191 for ext in "" .sig .md5 .sha1; do
192 if [ -e "$OUTPUT_DIR/freefoam-$VERSION.tar.bz2$ext" ]; then
193 echo "Error: The output file $OUTPUT_DIR/freefoam-$VERSION.tar.bz2$ext already exists" >&2
194 usage 1
196 done
198 # create the tag if requested
199 if [ "$CREATE_TAG" == "yes" ]; then
200 if git rev-list --max-count=1 --quiet --tags "v$VERSION" > /dev/null 2>&1; then
201 echo "Error: Cannot create tag v$VERSION, it already exists"
202 usage 1
204 GIT_TAG_OPTS=
205 if [ -n "$CUSTOM_TAG_KEY" ]; then
206 GIT_TAG_OPTS="$GIT_TAG_OPTS -u $CUSTOM_TAG_KEY"
207 else
208 GIT_TAG_OPTS="$GIT_TAG_OPTS -s"
210 if [ -n "$TAG_MSG" ]; then
211 GIT_TAG_OPTS="$GIT_TAG_OPTS -m '$TAG_MSG'"
213 echo "Creating tag 'v$VERSION'"
214 eval "git tag $GIT_TAG_OPTS v$VERSION"
217 # create the tar-ball
218 echo "Creating the tar ball"
219 TMP=`mktemp -d` || abort "Failed to create temporary directory"
220 git archive --format=tar --prefix=freefoam-$VERSION/ v$VERSION > \
221 $TMP/freefoam-$VERSION.tar || abort "Failed to create tar file"
223 tar -f $TMP/freefoam-$VERSION.tar --delete freefoam-$VERSION/.gitignore || \
224 abort "Failed to remove .gitignore from tar file"
226 echo "Compressing the tar ball"
227 bzip2 --best $TMP/freefoam-$VERSION.tar || abort "Failed to compress the tar ball"
228 mv $TMP/freefoam-$VERSION.tar.bz2 $OUTPUT_DIR/freefoam-$VERSION.tar.bz2 || \
229 abort "Failed to place the compressed tar ball in '$OUTPUT_DIR'"
230 rm -rf $TMP || abort "Failed to remove the temporary directory '$TMP'"
232 # sign the tar-ball
233 echo "Signing the tar ball"
234 gpg --armor -o $OUTPUT_DIR/freefoam-$VERSION.tar.bz2.sig $SIGN_KEY \
235 --sign --detach-sign $OUTPUT_DIR/freefoam-$VERSION.tar.bz2 || \
236 abort "Failed to sign the tar ball"
238 # create md5 and sha1 sums
239 echo "Computing checksums of the tar ball"
240 (cd $OUTPUT_DIR; openssl md5 -out freefoam-$VERSION.tar.bz2.md5 freefoam-$VERSION.tar.bz2)
241 (cd $OUTPUT_DIR; openssl sha1 -out freefoam-$VERSION.tar.bz2.sha1 freefoam-$VERSION.tar.bz2)
243 # upload to sf.net
244 if [ "$DO_UPLOAD" == "yes" ]; then
245 echo "Uploading files to sourceforge.net"
246 rsync -avP $OUTPUT_DIR/freefoam-$VERSION.tar.bz2 \
247 $OUTPUT_DIR/freefoam-$VERSION.tar.bz2.sig \
248 $OUTPUT_DIR/freefoam-$VERSION.tar.bz2.md5 \
249 $OUTPUT_DIR/freefoam-$VERSION.tar.bz2.sha1 \
250 shell.sf.net:uploads/ || abort "Failed to upload the files to sourceforge.net"
251 echo "Finished upload. Remember to create a release on SF.net."
252 echo "You can do so on https://sourceforge.net/project/admin/editpackages.php?group_id=215833"
255 echo "Done"
257 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file