root/trunk/scripts/create-licq-tarball.sh

Revision 6452, 4.9 kB (checked in by erijo, 6 weeks ago)

Show the output from the command if it fails

  • Property svn:executable set to *
Line 
1#!/bin/bash
2#
3# Script to create a source tarball from Licq's svn repository.
4# Latest version: http://svn.licq.org/svn/trunk/scripts/
5#
6# Copyright (c) 2007-2008 Erik Johansson <erijo@licq.org>
7# Distributed under the terms of the GNU GPL version 2.
8#
9
10### DEFAULT SETTINGS ###
11
12# Where to save the tarball(s)
13TARDIR="."
14
15# What to name the tarball (REV is replaced with the svn revision)
16# Note: Don't add .tar.gz or .tar.bz2
17TARNAME="licq-1.3.6~rREV"
18#TARNAME="licq-1.3.6-rc1"
19
20# Archives to create (1 = create; 0 = don't create)
21CREATE_GZ=0
22CREATE_BZ2=0
23
24# Sign archives using default GPG key (1 = sign; 0 = don't sign)
25SIGN=0
26
27# What revision to export
28LICQREV="HEAD"
29
30# Ownership of files in tarball
31OWNER="root"
32GROUP="root"
33
34# Licq repository
35REPO="http://svn.licq.org/svn"
36
37### END SETTINGS ###
38
39# Prints the usage
40function usage()
41{
42    echo "Usage: $0 [-r rev] [-o dir] [-n name] [-g] [-b] [-s]"
43    echo "  -h, --help   This message"
44    echo "  -r rev       Create tarball from revision rev (default: ${LICQREV})"
45    echo "  -o dir       Save tarball in directory dir (default: ${TARDIR})"
46    echo "  -n name      Name the tarball name (default: ${TARNAME})"
47    echo "               REV is replaced with the svn revision"
48    echo "  -g, --gzip   Create a tar.gz archive"
49    echo "  -b, --bzip2  Create a tar.bz archive"
50    echo "  -s, --sign   Sign archive(s) with default GPG key"
51}
52
53if [ $# -eq 0 ]; then
54    echo "$0: Missing required argument (-g and/or -b)"
55    echo "Try \`$0 --help' for more information"
56    exit 2
57fi
58
59# Parse command line options
60args=$(getopt -n "$0" -o h,r:,o:,n:,g,b,s -l help,gzip,bzip2,sign -- $*)
61if [ $? -ne 0 ]; then
62    echo ""
63    usage
64    exit 1
65fi
66
67set -- $args
68while [ $# -gt 0 ]; do
69    case $1 in
70    -h|--help) usage; exit 0 ;;
71    -r) LICQREV=$(eval echo $2); shift ;;
72    -o) TARDIR=$(eval echo $2); shift ;;
73    -n) TARNAME=$(eval echo $2); shift ;;
74    -g|--gzip) CREATE_GZ=1 ;;
75    -b|--bzip2) CREATE_BZ2=1 ;;
76    -s|--sign) SIGN=1 ;;
77    --) ;;
78    *) echo "$0: unknown option '$1'"; exit 1 ;;
79    esac
80    shift
81done
82
83if [ $CREATE_GZ -eq 0 -a $CREATE_BZ2 -eq 0 ]; then
84    echo "$0: You must choose to create a gzip and/or bzip2 archive"
85    echo ""
86    usage
87    exit 1
88fi
89
90# Remove workdir
91function cleanup()
92{
93   if [ -n "${TMPDIR}" ]; then
94     echo "Removing ${TMPDIR}"
95     rm -rf "${TMPDIR}"
96     TMPDIR=""
97   fi
98}
99
100# Echos "$1 failed" or "failed" and then exits.
101function failed()
102{
103   if [ -z "$1" ]; then
104      echo "failed"
105   else
106      echo "$1 failed"
107   fi
108   if [ -r "${TMPFILE}" ]; then
109      cat "${TMPFILE}"
110   fi
111   cleanup
112   exit 1
113}
114
115function abort()
116{
117   echo "Aborted by user"
118   cleanup
119   exit 1
120}
121
122function run()
123{
124   "$@" &> "${TMPFILE}" || failed
125   rm -f "${TMPFILE}"
126}
127
128trap abort SIGHUP SIGINT SIGQUIT
129
130# Workdir/file
131TMPDIR=$(mktemp -d) || failed "mktemp -d"
132TMPFILE="${TMPDIR}/.cmd.out"
133
134SVNREV=$(svn info -r"${LICQREV}" "${REPO}" | grep "^Revision:" | awk '{print $2}') || failed
135
136DIRNAME="${TARNAME//REV/$SVNREV}"
137TARNAME="${TARNAME//REV/$SVNREV}"
138LICQDIR="${TMPDIR}/${DIRNAME}"
139
140function exit_if_exists()
141{
142   if [ -e "$1" ]; then
143      echo "$1 already exists"
144      cleanup
145      exit 1
146   fi
147}
148
149function svnexport()
150{
151   echo -n "Exporting $1 (r${SVNREV})... "
152   run svn export --ignore-externals -r"${SVNREV}" "${REPO}/$1" "${LICQDIR}/$2"
153   echo "done"
154}
155
156function makecvs()
157{
158   echo -n "Running make -f $1/Makefile.cvs... "
159   run make -C "${LICQDIR}/$1" -f "${LICQDIR}/$1/Makefile.cvs"
160   rm -rf "${LICQDIR}/$1/autom4te.cache"
161   rm -f "${LICQDIR}/$1/Makefile.cvs"
162   echo "done"
163}
164
165test ${CREATE_GZ}  -ne 0 && exit_if_exists "${TARDIR}/${TARNAME}.tar.gz"
166test ${CREATE_BZ2} -ne 0 && exit_if_exists "${TARDIR}/${TARNAME}.tar.bz2"
167
168svnexport "trunk/licq" ""
169svnexport "trunk/admin" "admin"
170
171makecvs "."
172
173for plugin in auto-reply console email msn osd qt-gui rms; do
174   svnexport "trunk/${plugin}" "plugins/${plugin}"
175   makecvs "plugins/${plugin}"
176done
177
178rm -f "${LICQDIR}/admin/Makefile.common"
179
180for plugin in licqweb; do
181   svnexport "trunk/${plugin}" "plugins/${plugin}"
182done
183
184svnexport "trunk/qt4-gui" "plugins/qt4-gui"
185
186echo "Creating tarball ${TARNAME}.tar"
187tar --owner "${OWNER}" --group "${GROUP}" -C "${TMPDIR}" -cf "${TMPDIR}/${TARNAME}.tar" "${DIRNAME}" || failed
188
189function sign()
190{
191   if [ ${SIGN} -ne 0 ]; then
192      echo "Signing $1"
193      gpg --sign --armor --detach-sign --output "$1.sign" "$1" || failed "signing"
194   fi
195}
196
197if [ ${CREATE_GZ} -ne 0 ]; then
198   echo -n "Creating ${TARDIR}/${TARNAME}.tar.gz... "
199   cp "${TMPDIR}/${TARNAME}.tar" "${TARDIR}" || failed "copy tarball"
200   gzip --best "${TARDIR}/${TARNAME}.tar" || failed
201   echo "done"
202
203   sign "${TARDIR}/${TARNAME}.tar.gz"
204fi
205
206if [ ${CREATE_BZ2} -ne 0 ]; then
207   echo -n "Creating ${TARDIR}/${TARNAME}.tar.bz2... "
208   cp "${TMPDIR}/${TARNAME}.tar" "${TARDIR}" || failed "copy tarball"
209   bzip2 --best "${TARDIR}/${TARNAME}.tar" || failed
210   echo "done"
211
212   sign "${TARDIR}/${TARNAME}.tar.bz2"
213fi
214
215cleanup
Note: See TracBrowser for help on using the browser.