build.sh: use meaningful names for parameter variables
[xorg-util-modular.git] / release.sh
blobea4d9c908524861e35dd0124a5f15ca0fd7e1fb3
1 #!/bin/sh
3 set -e
5 announce_list="xorg-announce@lists.freedesktop.org"
6 xorg_list="xorg@lists.freedesktop.org"
7 dri_list="dri-devel@lists.sourceforge.net"
8 xkb_list="xkb@listserv.bat.ru"
10 host_people=annarchy.freedesktop.org
11 host_xorg=xorg.freedesktop.org
12 host_dri=dri.freedesktop.org
13 user=
14 remote=origin
16 usage()
18 cat <<HELP
19 Usage: `basename $0` [options] <section> <tag_previous> <tag_current>
21 Options:
22 --force force overwritting an existing release
23 --user <name> username on $host_people
24 --help this help message
25 --ignore-local-changes don't abort on uncommitted local changes
26 --remote git remote where the change should be pushed (default "origin")
27 HELP
30 abort_for_changes()
32 cat <<ERR
33 Uncommitted changes found. Did you forget to commit? Aborting.
34 Use --ignore-local-changes to skip this check.
35 ERR
36 exit 1
39 gen_announce_mail()
41 case "$tag_previous" in
42 initial)
43 range="$tag_current"
46 range="$tag_previous".."$tag_current"
48 esac
50 MD5SUM=`which md5sum || which gmd5sum`
51 SHA1SUM=`which sha1sum || which gsha1sum`
53 if [ "$section" = "libdrm" ]; then
54 host=$host_dri
55 list=$dri_list
56 elif [ "$section" = "xkeyboard-config" ]; then
57 host=$host_xorg
58 list=$xkb_list
59 else
60 host=$host_xorg
61 list=$xorg_list
64 cat <<RELEASE
65 Subject: [ANNOUNCE] $module $version
66 To: $announce_list
67 CC: $list
69 `git log --no-merges "$range" | git shortlog`
71 git tag: $tag_current
73 http://$host/$section_path/$tarbz2
74 MD5: `cd $tarball_dir && $MD5SUM $tarbz2`
75 SHA1: `cd $tarball_dir && $SHA1SUM $tarbz2`
77 http://$host/$section_path/$targz
78 MD5: `cd $tarball_dir && $MD5SUM $targz`
79 SHA1: `cd $tarball_dir && $SHA1SUM $targz`
81 RELEASE
84 export LC_ALL=C
86 while [ $# != 0 ]; do
87 case "$1" in
88 --force)
89 force="yes"
90 shift
92 --help)
93 usage
94 exit 0
96 --user)
97 shift
98 user=$1@
99 shift
101 --ignore-local-changes)
102 ignorechanges=1
103 shift
105 --remote)
106 shift
107 remote=$1
108 shift
110 --*)
111 echo "error: unknown option"
112 usage
113 exit 1
116 section="$1"
117 tag_previous="$2"
118 tag_current="$3"
119 shift 3
120 if [ $# != 0 ]; then
121 echo "error: unknown parameter"
122 usage
123 exit 1
126 esac
127 done
129 # Check for uncommitted/queued changes.
130 if [ "x$ignorechanges" != "x1" ]; then
131 set +e
132 git diff --quiet HEAD > /dev/null 2>&1
133 if [ $? -ne 0 ]; then
134 abort_for_changes
136 set -e
139 # Check if the object has been pushed. Do do so
140 # 1. Check if the current branch has the object. If not, abort.
141 # 2. Check if the object is on $remote/branchname. If not, abort.
142 local_sha=`git rev-list -1 $tag_current`
143 current_branch=`git branch | grep "\*" | sed -e "s/\* //"`
144 set +e
145 git rev-list $current_branch | grep $local_sha > /dev/null
146 if [ $? -eq 1 ]; then
147 echo "Cannot find tag '$tag_current' on current branch. Aborting."
148 echo "Switch to the correct branch and re-run the script."
149 exit 1
152 revs=`git rev-list $remote/$current_branch..$current_branch | wc -l`
153 if [ $revs -ne 0 ]; then
154 git rev-list $remote/$current_branch..$current_branch | grep $local_sha > /dev/null
156 if [ $? -ne 1 ]; then
157 echo "$remote/$current_branch doesn't have object $local_sha"
158 echo "for tag '$tag_current'. Did you push branch first? Aborting."
159 exit 1
162 set -e
164 tarball_dir="$(dirname $(find . -name config.status))"
165 module="${tag_current%-*}"
166 if [ "x$module" = "x$tag_current" ]; then
167 # version-number-only tag.
168 pwd=`pwd`
169 module=`basename $pwd`
170 version="$tag_current"
171 else
172 # module-and-version style tag
173 version="${tag_current##*-}"
176 detected_module=`grep 'PACKAGE = ' $tarball_dir/Makefile | sed 's|PACKAGE = ||'`
177 if [ -f $detected_module-$version.tar.bz2 ]; then
178 module=$detected_module
181 modulever=$module-$version
182 tarbz2="$modulever.tar.bz2"
183 targz="$modulever.tar.gz"
184 announce="$tarball_dir/$modulever.announce"
186 echo "checking parameters"
187 if ! [ -f "$tarball_dir/$tarbz2" ] ||
188 ! [ -f "$tarball_dir/$targz" ]; then
189 echo "error: tarballs not found. Did you run make dist?"
190 usage
191 exit 1
194 if [ -z "$tag_previous" ] ||
195 [ -z "$section" ]; then
196 echo "error: previous tag or section not found."
197 usage
198 exit 1
201 if [ "$section" = "libdrm" ]; then
202 section_path="libdrm"
203 srv_path="/srv/$host_dri/www/$section_path"
204 elif [ "$section" = "xkeyboard-config" ]; then
205 section_path="archive/individual/data"
206 srv_path="/srv/$host_xorg/$section_path"
207 else
208 section_path="archive/individual/$section"
209 srv_path="/srv/$host_xorg/$section_path"
212 echo "checking for proper current dir"
213 if ! [ -d .git ]; then
214 echo "error: do this from your git dir, weenie"
215 exit 1
218 echo "checking for an existing tag"
219 if ! git tag -l $tag_current >/dev/null; then
220 echo "error: you must tag your release first!"
221 exit 1
224 echo "checking for an existing release"
225 if ssh $user$host_people ls $srv_path/$targz >/dev/null 2>&1 ||
226 ssh $user$host_people ls $srv_path/$tarbz2 >/dev/null 2>&1; then
227 if [ "x$force" = "xyes" ]; then
228 echo "warning: overriding released file ... here be dragons."
229 else
230 echo "error: file already exists!"
231 exit 1
235 echo "generating announce mail template, remember to sign it"
236 gen_announce_mail >$announce
237 echo " at: $announce"
239 echo "installing release into server"
240 scp $tarball_dir/$targz $tarball_dir/$tarbz2 $user$host_people:$srv_path
242 echo "pushing tag upstream"
243 git push $remote $tag_current