create-tarball: Make it more comfortable to use the --copy-docs option.
[kai/samba.git] / release-scripts / create-tarball
1 #!/bin/bash
2
3 ## option defaults
4 OPT_BRANCH=""
5 OPT_DOCSDIR=""
6 OPT_TAG=""
7 OPT_KEYID=""
8
9 TOPDIR="`dirname $0`/.."
10 VER_H="${TOPDIR}/source3/include/version.h"
11
12 function exitOnError
13 {
14     local _error="$1"
15     local _msg="$2"
16
17     if [ ${_error} -eq 0 ]; then
18         return 0
19     fi
20
21     echo "FAILURE: ${_msg}"
22     exit ${_error}
23 }
24
25 ##
26 ## Print help usage
27 ##
28
29 function printUsage
30 {
31     echo "Usage $0 [options]"
32     echo "    --help             Print command usage"
33     echo "    --branch <name>    Specify the branch to to create the archive file from"
34     echo "    --copy-docs <dir>  Copy documentation from <dir> rather than building"
35     echo "    --tag <name>       Tag name for release"
36     echo "    --keyid <email>    The GnuPG key ID used to sign the release tag"
37     echo ""
38 }
39
40 ##
41 ## Parse the command line options
42 ##
43
44 function parseOptions
45 {
46     while [ -n "$1" ]; do
47         case "$1" in
48             --help)
49                 printUsage
50                 exit 0
51                 ;;
52             --branch)
53                 shift
54                 if [ -z "$1" ]; then
55                     printUsage
56                     return 1
57                 fi
58                 OPT_BRANCH="$1"
59                 shift
60                 ;;
61             --copy-docs)
62                 shift
63                 if [ -z "$1" ]; then
64                     printUsage
65                     return 1
66                 fi
67                 OPT_DOCSDIR="$1"
68                 shift
69                 ;;
70             --tag)
71                 shift
72                 if [ -z "$1" ]; then
73                     printUsage
74                     return 1
75                 fi
76                 OPT_TAG="$1"
77                 shift
78                 ;;
79             --keyid)
80                 shift
81                 if [ -z "$1" ]; then
82                     printUsage
83                     return 1
84                 fi
85                 OPT_KEYID="$1"
86                 shift
87                 ;;
88             *)
89                 printUsage
90                 return 1
91                 ;;
92         esac
93     done
94
95     if [ -z "${OPT_BRANCH}" ]; then
96         echo "You must specify a branch name!"
97         printUsage
98         return 1
99     fi
100 }
101
102 ##
103 ## Build the dopcumentation (may be a no-op)
104 ##
105
106 function buildDocs
107 {
108     if [ -n "${OPT_DOCSDIR}" ]; then
109         if [ ! -d "${OPT_DOCSDIR}" ]; then
110             exitOnError 1 "${OPT_DOCSDIR} does not exist.  Please specify the absolute path."
111         fi
112
113         mkdir docs
114         exitOnError $? "Failed to create docs directory"
115
116         rsync -av "${OPT_DOCSDIR}"/ docs/
117         exitOnError $? "Failed top copy docs from ${OPT_DOCSDIR}"
118
119         cd docs/
120         /bin/rm -rf test.pdf Samba4*pdf htmldocs/Samba4* htmldocs/test
121         if [ -d manpages-3 ]; then
122                 mv manpages-3 manpages
123         fi
124         if [ -d htmldocs/manpages-3 ]; then
125                 mv htmldocs/manpages-3 htmldocs/manpages
126         fi
127         # Sync thanks, history and registry/ into the docs dir
128         rsync -Ca --exclude=.svn ../../$OPT_BRANCH/docs-xml/registry ../docs/
129         rsync -Ca --exclude=.svn ../../$OPT_BRANCH/docs-xml/archives/ ../docs/
130         cd ../
131
132         return 0
133     fi
134
135     echo "Building documentation.  This may take a while.  Log file in /tmp/docs-build.log.$$"
136
137     ${TOPDIR}/release-scripts/build-docs 2> /tmp/docs-build.log.$$
138     return $?
139
140 }
141
142
143 ##
144 ## Create a release tag
145 ##
146 function createReleaseTag
147 {
148     if [ -z "${OPT_TAG}" ]; then
149         echo "Tagging disabled"
150         return 0
151     fi
152
153     if [ "x`git tag -l ${OPT_TAG}`" != "x" ]; then
154         echo -n "Tag exists.  Do you wish to overwrite? (y/N): "
155         read answer
156
157         if [ "x$answer" != "xy" ]; then
158             echo "Tag creation aborted."
159             exit 1
160         fi
161     fi
162
163     if [ -z "${OPT_KEYID}" ]; then
164         echo -n "Enter the keyid:"
165         read OPT_KEYID
166         if [ -z "${OPT_KEYID}" ]; then
167             exitOnError 1 "No keyid specified"
168         fi
169     fi
170
171     git tag -u ${OPT_KEYID} ${OPT_TAG}
172     exitOnError $? "Failed to create tag"
173
174     return 0
175 }
176 ##
177 ## Main driver
178 ##
179 function main
180 {
181     parseOptions "$@"
182     exitOnError $? "Failed to parse options"
183
184     cd $TOPDIR
185
186     git checkout ${OPT_BRANCH}
187     exitOnError $? "Invalid branch name \"${OPT_BRANCH}\""
188
189     (cd source3 && ./script/mkversion.sh)
190     if [ ! -f $VER_H ]; then
191         exitOnError 1 "Failed to find ${VER_H}!"
192     fi
193
194     version=`grep "define SAMBA_VERSION_OFFICIAL_STRING" $VER_H | awk '{print $3}'`
195     vendor_version=`grep "define SAMBA_VERSION_VENDOR_SUFFIX" $VER_H | awk '{print $3}'`
196     if [ -n "$vendor_version" ]; then
197         version="$version-$vendor_version"
198     fi
199     vendor_patch=`grep "define SAMBA_VERSION_VENDOR_PATCH" $VER_H | awk '{print $3}'`
200     if [ -n "$vendor_patch" ]; then
201         version="$version-$vendor_patch"
202     fi
203     version=`echo $version | sed 's/\"//g'`
204
205     echo "Creating release tarball for Samba $version"
206
207     /bin/rm -rf ../samba-${version}
208     git archive --format=tar --prefix=samba-${version}/ HEAD | (cd .. && tar xf -)
209     exitOnError $? "Failed to create release directory tree"
210
211     pushd ../samba-${version}
212
213     # Remove RFCs as they are non-free content (with a strict interpretation of
214     # the DFSG)
215
216     if [ -d source4 ]; then
217         echo "Removing RFCs"
218         find source4/ -name "rfc*.txt" -exec rm -f {} \;
219         rm -f source4/ldap_server/devdocs/draft-armijo-ldap-syntax-00.txt
220         rm -f source4/ldap_server/devdocs/ldapext-ldapv3-vlv-04.txt
221     fi
222
223     packaging/bin/update-pkginfo ${version} 1 ""
224
225     buildDocs
226     exitOnError $? "Failed to build documentation"
227
228     ( cd source3 && ./autogen.sh )
229
230     cd ..
231     tar cf samba-${version}.tar --exclude=.git* --exclude=CVS --exclude=.svn samba-${version}
232     exitOnError $? "Failed to create tarball from git tree"
233
234     gpg --detach-sign --armor samba-${version}.tar
235     ## exitOnError $? "Failed to sign tarball"
236
237     gzip -9 samba-${version}.tar
238     exitOnError $? "Failed to compress archive"
239
240     popd
241
242     createReleaseTag
243     exitOnError $? "Failed to create release tag"
244
245     return 0
246 }
247
248 main "$@"
249 exit $?