1#!/bin/bash
2
3SRCTEST=src/server.c
4PACKAGE=lighttpd
5BASEDOWNLOADURL="http://download.lighttpd.net/lighttpd/releases-1.4.x"
6SNAPSHOTURL="http://download.lighttpd.net/lighttpd/snapshots-1.4.x"
7
8AUTHOR=stbuehler
9
10# may take one argument for prereleases like
11# ./packdist.sh [--nopack] rc1-r10
12
13syntax() {
14	echo "./packdist.sh [--nopack] [--help] [~rc1]" >&2
15	exit 2
16}
17
18if [ ! -f ${SRCTEST} ]; then
19	echo "Current directory is not the source directory"
20	exit 1
21fi
22
23dopack=1
24
25while [ $# -gt 0 ]; do
26	case "$1" in
27	"--nopack")
28		dopack=0
29		;;
30	"--help")
31		syntax
32		;;
33	"rc"*|"~rc"*)
34		if [ -n "$append" ]; then
35			echo "Only one append allowed" >&2
36			syntax
37		fi
38		echo "Appending '$1'"
39		append="$1"
40		BASEDOWNLOADURL="${SNAPSHOTURL}"
41		;;
42	*)
43		echo "Unknown option '$1'" >&2
44		syntax
45		;;
46	esac
47	shift
48done
49
50force() {
51	"$@" || {
52		echo "Command failed: $*"
53		exit 1
54	}
55}
56
57# summarize all changes since last release
58genchanges() {
59	(
60		cat ../NEWS | sed "/^- ${version}/,/^-/p;d" | sed "/^- /d;/^$/d" | sed -e 's/^  \*/\*/'
61	) > CHANGES
62	return 0
63}
64
65# genereate links in old textile format "text":url
66genlinks_changes() {
67	local repourl ticketurl inf out
68	repourl="http://redmine.lighttpd.net/projects/lighttpd/repository/revisions/"
69	ticketurl="http://redmine.lighttpd.net/issues/"
70	inf="$1"
71	outf="$1".links
72	(
73		sed -e 's%\(http://[a-zA-Z0-9.:_/\-]\+\)%"\1":\1%g' |
74		sed -e 's%#\([0-9]\+\)%"#\1":'"${ticketurl}"'\1%g' |
75		sed -e 's%r\([0-9]\+\)%"r\1":'"${repourl}"'\1%g' |
76		sed -e 's%\(CVE-[0-9\-]\+\)%"\1":http://cve.mitre.org/cgi-bin/cvename.cgi?name=\1%g' |
77		cat
78	) < "$inf" > "$outf"
79}
80genlinks_downloads() {
81	local repourl ticketurl inf out
82	repourl="http://redmine.lighttpd.net/projects/lighttpd/repository/revisions/"
83	ticketurl="http://redmine.lighttpd.net/issues/"
84	inf="$1"
85	outf="$1".links
86	(
87		sed -e 's%\(http://[a-zA-Z0-9.:_/\-]\+\)%"\1":\1%g' |
88		cat
89	) < "$inf" > "$outf"
90}
91
92blog_post() {
93	if [ -z "${append}" ]; then
94		# release
95		cat <<EOF
96---
97layout: post
98title: ${version}
99author: $AUTHOR
100author_email: ${AUTHOR}@lighttpd.net
101categories:
102- download
103tags:
104- ${version}
105- lighttpd
106- releases
107---
108{% excerpt %}
109
110TODO
111
112h2. Important changes
113
114TODO
115
116h2. Downloads
117
118EOF
119		cat DOWNLOADS.links
120		cat <<EOF
121
122{% endexcerpt %}
123h2. Changes from ${prevversion}
124
125EOF
126		cat CHANGES.links
127	else
128		# pre release
129		cat <<EOF
130---
131layout: post
132title: 'PRE-RELEASE: lighttpd ${version}${append}'
133categories:
134- lighttpd
135tags:
136- '1.4'
137- ${version}
138- lighttpd
139- prerelease
140---
141{% excerpt %}
142We would like to draw your attention to the latest pre-release of the stable 1.4 branch of lighttpd.
143
144You can get the pre-release from these urls:
145EOF
146		cat DOWNLOADS.links
147		cat <<EOF
148
149Please test it as much as possible and provide us with feedback.
150A lot of testing ensures a good release.
151
152<!-- TODO: describe major changes -->
153
154{% endexcerpt %}
155
156h4. Changes from ${prevversion}
157
158EOF
159		cat CHANGES.links
160
161		cat <<EOF
162
163If you want to get the latest source for any branch, you can get it from our svn repository.
164Documentation to do so can be obtained from this page: "DevelSubversion":http://redmine.lighttpd.net/projects/lighttpd/wiki/DevelSubversion
165Bug reports or feature requests can be filed in our ticket system: "New Issue":http://redmine.lighttpd.net/projects/lighttpd/issues/new
166Please make sure to check if there isn't a ticket already here: "Issues":http://redmine.lighttpd.net/projects/lighttpd/issues
167Perhaps you also want to have a look at our "download site":http://download.lighttpd.net/lighttpd/
168
169Thank you for flying light.
170EOF
171	fi
172}
173
174if [ ${dopack} = "1" ]; then
175	force ./autogen.sh
176
177	if [ -d distbuild ]; then
178		# make distcheck may leave readonly files
179		chmod u+w -R distbuild
180		rm -rf distbuild
181	fi
182
183	force mkdir distbuild
184	force cd distbuild
185
186	force ../configure --prefix=/usr
187
188	# force make
189	# force make check
190
191	force make distcheck
192	force fakeroot make dist
193else
194	force cd distbuild
195fi
196
197version=`./config.status -V | head -n 1 | cut -d' ' -f3`
198name="${PACKAGE}-${version}"
199if [ -n "${append}" ]; then
200	cp "${name}.tar.gz" "${name}${append}.tar.gz"
201	cp "${name}.tar.xz" "${name}${append}.tar.xz"
202	name="${name}${append}"
203fi
204
205force sha256sum "${name}.tar."{gz,xz} > "${name}.sha256sum"
206
207rm -f "${name}".tar.*.asc
208
209force gpg -a --output "${name}.tar.gz.asc" --detach-sig "${name}.tar.gz"
210force gpg -a --output "${name}.tar.xz.asc" --detach-sig "${name}.tar.xz"
211
212(
213	echo "* ${BASEDOWNLOADURL}/${name}.tar.gz"
214	echo "** GPG signature: ${BASEDOWNLOADURL}/${name}.tar.gz.asc"
215	echo "** SHA256: @$(sha256sum ${name}.tar.gz | cut -d' ' -f1)@"
216	echo "* ${BASEDOWNLOADURL}/${name}.tar.xz"
217	echo "** GPG signature: ${BASEDOWNLOADURL}/${name}.tar.xz.asc"
218	echo "** SHA256: @$(sha256sum ${name}.tar.xz | cut -d' ' -f1)@"
219	echo "* SHA256 checksums: ${BASEDOWNLOADURL}/${name}.sha256sum"
220) > DOWNLOADS
221
222(
223	echo "* \"${name}.tar.gz\":${BASEDOWNLOADURL}/${name}.tar.gz (\"GPG signature\":${BASEDOWNLOADURL}/${name}.tar.gz.asc)"
224	echo "** SHA256: @$(sha256sum ${name}.tar.gz | cut -d' ' -f1)@"
225	echo "* \"${name}.tar.xz\":${BASEDOWNLOADURL}/${name}.tar.xz (\"GPG signature\":${BASEDOWNLOADURL}/${name}.tar.xz.asc)"
226	echo "** SHA256: @$(sha256sum ${name}.tar.xz | cut -d' ' -f1)@"
227	echo "* \"SHA256 checksums\":${BASEDOWNLOADURL}/${name}.sha256sum"
228) > DOWNLOADS.links
229
230force genchanges
231force genlinks_changes CHANGES
232#force genlinks_downloads DOWNLOADS
233
234prevversion="${version%.*}.$((${version##*.} - 1))"
235
236if [ -z "${append}" ]; then
237	# only for Releases
238	(
239		cat <<EOF
240h1. Release Info
241
242* Version: ${version}
243* Previous version: [[Release-${prevversion//./_}|${prevversion}]]
244* Branch: 1.4
245* Status: stable
246* Release Purpose: bug fixes
247* Release manager: $AUTHOR
248* Released date: $(date +"%Y-%m-%d")
249
250h1. Important changes from ${prevversion}
251
252TODO
253
254h1. Downloads
255
256EOF
257		cat DOWNLOADS
258		cat <<EOF
259
260h1. Changes from ${prevversion}
261
262EOF
263		cat CHANGES
264		cat <<EOF
265
266h1. External references
267
268* http://www.lighttpd.net/$(date +"%Y/%-m/%-d")/${version}
269
270EOF
271	) > "Release-${version//./_}.page"
272
273	cat "Release-${version//./_}.page"
274fi
275
276echo
277echo -------
278echo
279
280
281
282blog_post > $(date +"%Y-%m-%d")-"${version}.textile"
283cat $(date +"%Y-%m-%d")-"${version}.textile"
284
285echo
286echo -------
287echo
288
289echo wget "${BASEDOWNLOADURL}/${name}".'{tar.gz,tar.xz,sha256sum}; sha256sum -c '${name}'.sha256sum'
290