]> git.pld-linux.org Git - projects/pld-builder.new.git/blob - client/make-request.sh
cd /usr/share/empty as workaround for asterisk expansion
[projects/pld-builder.new.git] / client / make-request.sh
1 #!/bin/sh
2
3 # prevent "*" from being expanded in builders var
4 cd /usr/share/empty
5
6 builders=
7 specs=
8 with=
9 without=
10 flags=
11 command=
12 command_flags=
13 gpg_opts=
14 default_branch='HEAD'
15 distro=
16 url=
17
18 [ -x /usr/bin/python ] && send_mode="python" || send_mode="mail"
19
20 if [ -n "$HOME_ETC" ]; then
21         USER_CFG=$HOME_ETC/.requestrc
22 else
23         USER_CFG=$HOME/.requestrc
24 fi
25
26 if [ ! -f "$USER_CFG" ]; then
27         echo "Creating config file $USER_CFG. You *must* edit it."
28         cat > $USER_CFG <<EOF
29 priority=2
30 requester=deviloper@pld-linux.org
31 default_key=deviloper@pld-linux.org
32 send_mode="$send_mode"
33 url="$url"
34 mailer="/usr/sbin/sendmail -t"
35 gpg_opts=""
36 distro=th
37 url="http://ep09.pld-linux.org:1234/"
38
39 # defaults:
40 f_upgrade=yes
41 EOF
42 exit
43 fi
44
45 if [ -f "$USER_CFG" ]; then
46         . $USER_CFG
47 fi
48
49 send_request() {
50         # switch to mail mode, if no url set
51         [ -z "$url" ] && send_mode="mail"
52
53
54         case "$send_mode" in
55         "mail")
56                 echo >&2 "* Sending using mail mode"
57                 cat - | $mailer
58                 ;;
59         *)
60                 echo >&2 "* Sending using http mode to $url"
61                 cat - | python -c '
62 import sys, urllib2
63
64 try:
65         data = sys.stdin.read()
66         req = urllib2.Request(sys.argv[1], data)
67         f = urllib2.urlopen(req, timeout = 10)
68         f.close()
69 except Exception, e:
70         print >> sys.stderr, "Problem while sending request via HTTP: %s" % e
71         sys.exit(1)
72 print >> sys.stdout, "Request queued via HTTP."
73 ' "$url"
74                 ;;
75         esac
76 }
77
78 die() {
79         echo >&2 "$0: $*"
80         exit 1
81 }
82
83 usage() {
84         echo "Usage: make-request.sh [OPTION] ... [SPECFILE] ...."
85         echo ""
86         echo "Mandatory arguments to long options are mandatory for short options too."
87         echo "  -C  --config-file /path/to/config/file"
88         echo "       Source additional config file (after $USER_CFG), useful when"
89         echo "       when sending build requests to Ac/Th from the same account"
90         echo "  -b 'BUILDER BUILDER ...'  --builder='BUILDER BUILDER ...'"
91         echo "       Sends request to given builders (in 'version-arch' format)"
92         echo "  --with VALUE --without VALUE"
93         echo "       Build package with(out) a given bcond"
94         echo "  --kernel VALUE"
95         echo "       set alt_kernel to VALUE"
96         echo "  --target VALUE"
97         echo "       set --target to VALUE"
98         echo "  --branch VALUE"
99         echo "       specify default branch for specs in request"
100         echo "  -t   --test-build"
101         echo "       Performs a 'test-build'. Package will be uploaded to test/ tree"
102         echo "       and won't be upgraded on builders"
103         echo "  -r   --ready-build"
104         echo "       Build and upgrade package and upload it to ready/ tree"
105         echo "  -u   --upgrade"
106         echo "       Forces package upgrade (for use with -c or -q, not -t)"
107         echo "  -n   --no-upgrade"
108         echo "       Disables package upgrade (for use with -r)"
109         echo "  -ni  -no-install-br"
110         echo "       Do not install missing BuildRequires (--nodeps)"
111         echo "  -j   Number of parallel jobs for single build"
112         echo "  -f   --flag"
113         echo "  -d   --distro"
114         echo "       Specify value for \$distro"
115         echo "  -cf  --command-flag"
116         echo "       Not yet documented"
117         echo "  -c   --command"
118         echo "       Executes a given command on builders"
119         echo "       --test-remove-pkg"
120         echo "       shortcut for --command poldek -evt ARGS"
121         echo "       --remove-pkg"
122         echo "       shortcut for --command poldek -ev --noask ARGS"
123         echo "       --upgrade-pkg"
124         echo "       shortcut for --command poldek --up -Uv ARGS"
125         echo "       --cvsup"
126         echo "       Updates builders infrastructure (outside chroot)"
127         echo "  -q   "
128         echo "       shortcut for --command rpm -q ARGS"
129         echo "  -g   --gpg-opts \"opts\""
130         echo "       Pass additional options to gpg binary"
131         echo "  -p   --priority VALUE"
132         echo "       sets request priority (default 2)"
133         echo "  -h   --help"
134         echo "       Displays this help message"
135         exit 0;
136 }
137
138
139 while [ $# -gt 0 ] ; do
140         case "$1" in
141                 --distro | -d )
142                         distro=$2
143                         shift
144                         ;;
145
146                 --config-file | -C )
147                         [ -f $2 ] && . $2 || die "Config file not found"
148                         shift
149                         ;;
150
151                 --builder | -b )
152                         builders="$builders $2"
153                         shift
154                         ;;
155
156                 --with )
157                         with="$with $2"
158                         shift
159                         ;;
160
161                 --without )
162                         without="$without $2"
163                         shift
164                         ;;
165
166                 --test-build | -t )
167                         build_mode=test
168                         f_upgrade=no
169                         ;;
170
171                 --kernel )
172                         kernel=$2
173                         shift
174                         ;;
175
176                 --target)
177                         target=$2
178                         shift
179                         ;;
180
181                 --branch)
182                         branch=$2
183                         shift
184                         ;;
185
186                 --priority | -p )
187                         priority=$2
188                         shift
189                         ;;
190
191                 --ready-build | -r )
192                         build_mode=ready
193                         ;;
194
195                 --upgrade | -u )
196                         f_upgrade=yes
197                         ;;
198
199                 --no-upgrade | -n )
200                         f_upgrade=no
201                         ;;
202
203                 --no-install-br | -ni )
204                         flags="$flags no-install-br"
205                         ;;
206
207                 -j )
208                         jobs="$2"
209                         shift
210                         ;;
211
212                 --flag | -f )
213                         flags="$flags $2"
214                         shift
215                         ;;
216
217                 --command-flags | -cf )
218                         command_flags="$2"
219                         shift
220                         ;;
221
222                 --command | -c )
223                         command="$2"
224                         f_upgrade=no
225                         shift
226                         ;;
227                 --test-remove-pkg)
228                         command="poldek -evt $2"
229                         f_upgrade=no
230                         shift
231                         ;;
232                 --remove-pkg)
233                         command="for a in $2; do poldek -ev --noask \$a; done"
234                         f_upgrade=no
235                         shift
236                         ;;
237                 --upgrade-pkg|-Uhv)
238                         command="poldek --up -Uv $2"
239                         f_upgrade=no
240                         shift
241                         ;;
242                 -q)
243                         command="rpm -q $2"
244                         f_upgrade=no
245                         shift
246                         ;;
247
248                 --cvsup )
249                         command_flags="no-chroot"
250                         command="cvs up"
251                         f_upgrade=no
252                         ;;
253
254                 --gpg-opts | -g )
255                         gpg_opts="$2"
256                         shift
257                         ;;
258
259                 --help | -h )
260                         usage
261                         ;;
262
263                 -* )
264                         die "unknown knob: $1"
265                         ;;
266
267                 *:* | * )
268                         specs="$specs $1"
269                         ;;
270         esac
271         shift
272 done
273
274 case "$distro" in
275 ac)
276         builder_email="builder-ac@pld-linux.org"
277         default_builders="ac-*"
278         default_branch="AC-branch"
279         ;;
280 ac-java) # fake "distro" for java available ac architectures
281         builder_email="builder-ac@pld-linux.org"
282         default_builders="ac-i586 ac-i686 ac-athlon ac-amd64"
283         default_branch="AC-branch"
284         ;;
285 ac-xen) # fake "distro" for xen-enabled architectures
286         builder_email="builder-ac@pld-linux.org"
287         default_builders="ac-i686 ac-athlon ac-amd64"
288         default_branch="AC-branch"
289         ;;
290 ti)
291         builder_email="builderti@ep09.pld-linux.org"
292         default_builders="ti-*"
293         ;;
294 th)
295         builder_email="builderth@ep09.pld-linux.org"
296         default_builders="th-*"
297         url="http://ep09.pld-linux.org:1234/"
298         ;;
299 th-java) # fake "distro" for java available th architectures
300         builder_email="builderth@ep09.pld-linux.org"
301         default_builders="th-x86_64 th-athlon th-i686"
302         url="http://ep09.pld-linux.org:1234/"
303         ;;
304 aidath)
305         builder_email="builderaidath@ep09.pld-linux.org"
306         default_builders="aidath-*"
307         ;;
308 *)
309         die "distro \`$distro' not known"
310         ;;
311 esac
312
313 branch=${branch:-$default_branch}
314
315 specs=`for s in $specs; do
316         case "$s" in
317         *.spec:*) # spec with branch
318                 basename $s
319                 ;;
320         *.spec) # spec without branch
321                 echo $(basename $s):$branch
322                 ;;
323         *:*) # package name with branch
324                 basename $s | sed -e 's/:/.spec:/'
325                 ;;
326         *) # just package name
327                 echo $(basename $s).spec:$branch
328                 ;;
329         esac
330 done`
331
332 if [[ "$requester" != *@* ]] ; then
333         requester="$requester@pld-linux.org"
334 fi
335
336 if [ -z "$builders" ] ; then
337         builders="$default_builders"
338 fi
339
340 if [ "$f_upgrade" = "yes" ] ; then
341         flags="$flags upgrade"
342 fi
343
344 if [ "$build_mode" = "test" ] ; then
345         if [ "$f_upgrade" = "yes" ] ; then
346                 die "--upgrade and --test-build are mutually exclusive"
347         fi
348         flags="$flags test-build"
349 fi
350
351 if [ -z "$build_mode" ] ; then
352         # missing build mode, builders go crazy when you proceed"
353         die "please specify build mode"
354 fi
355
356
357 ok=
358 for s in $specs; do
359         ok=1
360 done
361
362 if [ "$ok" = "" ] ; then
363         if [ "$command" = "" ] ; then
364                 die "no specs passed"
365         fi
366 else
367         if [ "$command" != "" ] ; then
368                 die "cannot pass specs and --command"
369         fi
370 fi
371
372 id=$(uuidgen)
373
374 gen_req() {
375         echo "<group id='$id' no='0' flags='$flags'>"
376         echo "  <time>$(date +%s)</time>"
377         echo "  <priority>$priority</priority>"
378         if [ -n "$jobs" ]; then
379                 echo "  <maxjobs>$jobs</maxjobs>"
380         fi
381         echo
382
383         if [ "$command" != "" ] ; then
384                 bid=$(uuidgen)
385                 echo >&2 "* Command: $command"
386                 echo "  <batch id='$bid' depends-on=''>"
387                 echo "           <command flags='$command_flags'>$(echo "$command" | sed -e 's,&,\&amp;,g;s,<,\&lt;,g;s,>,\&gt;,g')</command>"
388                 echo "           <info></info>"
389                 for b in $builders; do
390                         echo >&2 "* Builder: $b"
391                         echo "           <builder>$b</builder>"
392                 done
393                 echo "  </batch>"
394         else
395
396         echo >&2 "* Using priority $priority"
397         if [ -n "$jobs" ]; then
398                 echo >&2 "* Using jobs $jobs"
399         fi
400         echo >&2 "* Using email $builder_email"
401         echo >&2 "* Build mode: $build_mode"
402         if [ "$f_upgrade" = "yes" ] ; then
403                 echo >&2 "* Upgrade mode: $f_upgrade"
404         fi
405         echo >&2 "* Queue-ID: $id"
406
407         # first id:
408         fid=
409         i=1
410
411         for b in $builders; do
412                 echo >&2 "* Builder: $b"
413         done
414         for s in $specs; do
415                 bid=$(uuidgen)
416                 echo "  <batch id='$bid' depends-on='$fid'>"
417                 [ "$fid" = "" ] && fid="$bid"
418                 name=$(echo "$s" | sed -e 's|:.*||')
419                 branch=$(echo "$s" | sed -e 's|.*:||')
420                 echo >&2 "* Adding #$i $name:$branch${kernel:+ alt_kernel=$kernel}${target:+ target=$target}"
421                 echo "           <spec>$name</spec>"
422                 echo "           <branch>$branch</branch>"
423                 echo "           ${kernel:+<kernel>$kernel</kernel>}"
424                 echo "           ${target:+<target>$target</target>}"
425                 echo "           <info></info>"
426                 echo
427                 for b in $with; do
428                         echo "           <with>$b</with>"
429                 done
430                 for b in $without; do
431                         echo "           <without>$b</without>"
432                 done
433                 echo
434                 for b in $builders; do
435                         echo "           <builder>$b</builder>"
436                 done
437                 echo "  </batch>"
438                 i=$((i+1))
439         done
440
441         fi
442
443         echo "</group>"
444 }
445
446 gen_email () {
447         # make request first, so the STDERR/STDOUT streams won't be mixed
448         local req=$(gen_req)
449
450 cat <<EOF
451 From: $requester
452 To: $builder_email
453 Subject: build request
454 Message-Id: <$id@$(hostname)>
455 X-New-PLD-Builder: request
456 X-Requester-Version: \$Id$
457
458 $(echo "$req" | gpg --clearsign --default-key $default_key $gpg_opts)
459 EOF
460 }
461
462 gen_email | send_request
This page took 0.078746 seconds and 3 git commands to generate.