]> git.pld-linux.org Git - packages/rpm.git/blame - builder
- updated from SPECS (bugfix)
[packages/rpm.git] / builder
CommitLineData
d46655ef 1#!/bin/sh
2# -----------
3# $Id$
4# Exit codes:
5# 0 - succesful
6# 1 - help dispayed
7# 2 - no spec file name in cmdl parameters
8# 3 - spec file not stored in repo
9# 4 - some source, patch or icon files not stored in repo
10# 5 - package build failed
11
12VERSION="\
13Build package utility from PLD CVS repository
568630a3 14V 0.11 (C) 1999-2003 Free Penguins".
d46655ef 15PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
568630a3 16
d46655ef 17COMMAND="build"
18
19SPECFILE=""
20BE_VERBOSE=""
21QUIET=""
22CLEAN=""
23DEBUG=""
24NOURLS=""
25NOCVS=""
26NOCVSSPEC=""
568630a3
JB
27NODIST=""
28UPDATE=""
29UPDATE5=""
30ADD5=""
31ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
d46655ef 32if [ -s CVS/Root ]; then
33 CVSROOT=$(cat CVS/Root)
34else
35 CVSROOT=${CVSROOT:-""}
36fi
37# Example: LOGFILE='../log.$PACKAGE_NAME'
38# Yes, you can use variable name! Note _single_ quotes!
39LOGFILE=''
568630a3
JB
40
41LOGDIR=""
42LOGDIROK=""
43LOGDIRFAIL=""
44LASTLOG_FILE=""
45LTAG=""
d46655ef 46CHMOD="yes"
47CHMOD_MODE="0444"
48RPMOPTS=""
49BCOND=""
50
51PATCHES=""
52SOURCES=""
53ICONS=""
54PACKAGE_RELEASE=""
55PACKAGE_VERSION=""
56PACKAGE_NAME=""
57WGET_RETRIES=${MAX_WGET_RETRIES:-0}
568630a3
JB
58CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
59
60CVSTAG=""
61RES_FILE=""
62
63CVS_SERVER="cvs.pld-linux.org"
64DISTFILES_SERVER="ftp://distfiles.pld-linux.org"
d46655ef 65
66DEF_NICE_LEVEL=0
67
68FAIL_IF_NO_SOURCES="yes"
69
568630a3
JB
70GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet"
71GETURI2="wget -c -nd -t$WGET_RETRIES --inet"
72GETLOCAL="cp -a"
d46655ef 73
74if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
75 RPM="rpm"
76 RPMBUILD="rpm"
77else
78 RPM="rpm"
79 RPMBUILD="rpmbuild"
80fi
81
82if [ -f ~/etc/builderrc ]; then
83 . ~/etc/builderrc
84elif [ -f ~/.builderrc ]; then
85 . ~/.builderrc
86fi
87
88#---------------------------------------------
89# functions
90
91usage()
92{
93 if [ -n "$DEBUG" ]; then set -xv; fi
94 echo "\
95Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
96
97 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
98 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
99 [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
568630a3 100 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
648b2a16 101 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
102 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
d46655ef 103 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
568630a3 104 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
d46655ef 105
568630a3
JB
106 -5, --update-md5
107 - update md5 comments in spec, implies -nd
108 -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd
d46655ef 109 -D, --debug - enable script debugging mode,
110 -V, --version - output builder version
568630a3 111 -a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
d46655ef 112 -b, -ba,
113 --build - get all files from CVS repo or HTTP/FTP and build
114 package from <package>.spec,
115 -bb, --build-binary
116 - get all files from CVS repo or HTTP/FTP and build
117 binary only package from <package>.spec,
118 -bs,
119 --build-source - get all files from CVS repo or HTTP/FTP and only
120 pack them into src.rpm,
121 -B, --branch - add branch
122 -c, --clean - clean all temporarily created files (in BUILD,
123 SOURCES, SPECS and \$RPM_BUILD_ROOT),
124 -d <cvsroot>, --cvsroot <cvsroot>
125 - setup \$CVSROOT,
126 --define <macro> <value>
127 - define a macro <macro> with value <value>,
128 -g, --get - get <package>.spec and all related files from
129 CVS repo or HTTP/FTP,
130 -h, --help - this message,
131 -l <logfile>, --logtofile <logfile>
132 - log all to file,
133 -m, --mr-proper - only remove all files related to spec file and
134 all work resources,
135 -nc, --no-cvs - don't download sources from CVS, if source URL is
136 given,
137 -ncs, --no-cvs-specs
138 - don't check specs in CVS
568630a3
JB
139 -nd, --no-distfiles
140 - don't download from distfiles
d46655ef 141 -nm, --no-mirrors - don't download from mirror, if source URL is given,
142 -nu, --no-urls - don't try to download from FTP/HTTP location,
568630a3 143 -ns, --no-srcs - don't download Sources
d46655ef 144 -ns0, --no-source0
568630a3 145 - don't download Source0
d46655ef 146 --opts <rpm opts>
147 - additional options for rpm
148 -q, --quiet - be quiet,
568630a3
JB
149 --date yyyy-mm-dd
150 - build package using resources from specified CVS
151 date,
d46655ef 152 -r <cvstag>, --cvstag <cvstag>
153 - build package using resources from specified CVS
154 tag,
155 -T <cvstag> , --tag <cvstag>
156 - add cvs tag <cvstag> for files,
157 -Tvs, --tag-version-stable
158 - add cvs tags STABLE and NAME-VERSION-RELESE for files,
648b2a16 159 -Tvn, --tag-version-nest
160 - add cvs tags NEST and NAME-VERSION-RELESE for files,
d46655ef 161 -Ts, --tag-stable
162 - add cvs tag STABLE for files,
648b2a16 163 -Tn, --tag-nest
164 - add cvs tag NEST for files,
d46655ef 165 -Tv, --tag-version
166 - add cvs tag NAME-VERSION-RELESE for files,
167 -v, --verbose - be verbose,
168 -u, --try-upgrade
169 - check version, and try to upgrade package
568630a3
JB
170 -un, --try-upgrade-with-float-version
171 - as above, but allow float version
172 -U, --update
173 - refetch sources, don't use distfiles, and update md5
174 comments
d46655ef 175 --with/--without <feature>
176 - conditional build package depending on
177 %_with_<feature>/%_without_<feature> macro
178 switch
179"
180}
181
182parse_spec()
183{
184 if [ -n "$DEBUG" ]; then
568630a3
JB
185 set -x;
186 set -v;
d46655ef 187 fi
188
189 cd $SPECS_DIR
d46655ef 190 if [ "$NOSRCS" != "yes" ]; then
568630a3 191 SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
d46655ef 192 fi
193 if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then
568630a3 194 FAIL_IF_NO_SOURCES="no"
d46655ef 195 fi
196
197 PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
198 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
199 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
200 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
201 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
202
203 if [ -n "$BE_VERBOSE" ]; then
568630a3 204 echo "- Sources : `nourl $SOURCES`"
d46655ef 205 if [ -n "$PATCHES" ]; then
568630a3 206 echo "- Patches : `nourl $PATCHES`"
d46655ef 207 else
568630a3 208 echo "- Patches : *no patches needed*"
d46655ef 209 fi
210 if [ -n "$ICONS" ]; then
568630a3 211 echo "- Icon : `nourl $ICONS`"
d46655ef 212 else
568630a3 213 echo "- Icon : *no package icon*"
d46655ef 214 fi
215 echo "- Name : $PACKAGE_NAME"
216 echo "- Version : $PACKAGE_VERSION"
217 echo "- Release : $PACKAGE_RELEASE"
218 fi
219}
220
221Exit_error()
222{
568630a3
JB
223 if [ -n "$DEBUG" ]; then
224 set -x;
225 set -v;
d46655ef 226 fi
227
228 cd $__PWD
229
230 case "$1" in
231 "err_no_spec_in_cmdl" )
232 echo "ERROR: spec file name not specified.";
233 exit 2 ;;
234 "err_no_spec_in_repo" )
235 echo "Error: spec file not stored in CVS repo.";
236 exit 3 ;;
237 "err_no_source_in_repo" )
238 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
239 exit 4 ;;
240 "err_build_fail" )
648b2a16 241 echo "Error: package build failed. (${2:-no more info})";
d46655ef 242 exit 5 ;;
243 esac
244}
245
246init_builder()
247{
568630a3
JB
248 if [ -n "$DEBUG" ]; then
249 set -x;
250 set -v;
d46655ef 251 fi
252
253 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
254 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
255
256 __PWD=`pwd`
257}
258
259get_spec()
260{
568630a3
JB
261 if [ -n "$DEBUG" ]; then
262 set -x;
263 set -v;
d46655ef 264 fi
265
266 if [ "$NOCVSSPEC" != "yes" ]; then
267 cd $SPECS_DIR
268
269 OPTIONS="up "
270
271 if [ -n "$CVSROOT" ]; then
272 OPTIONS="-d $CVSROOT $OPTIONS"
273 else
274 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
275 echo "warning: No cvs access defined - using local .spec file"
276 NOCVSSPEC="yes"
277 fi
278 fi
568630a3
JB
279
280 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
d46655ef 281 OPTIONS="$OPTIONS -A"
568630a3
JB
282 else
283 if [ -n "$CVSDATE" ]; then
284 OPTIONS="$OPTIONS -D $CVSDATE"
285 fi
286 if [ -n "$CVSTAG" ]; then
287 OPTIONS="$OPTIONS -r $CVSTAG"
288 fi
d46655ef 289 fi
290
568630a3
JB
291 result=1
292 retries_counter=0
293 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
294 retries_counter=$(( $retries_counter + 1 ))
295 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
296 result=$?
297 [ -n "$output" ] && echo "$output"
298 if [ "$result" -ne "0" ]; then
299 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
300 echo "Trying again [$SPECFILE]... ($retries_counter)"
301 sleep 2
302 continue
303 fi
304 Exit_error err_no_spec_in_repo;
305 fi
306 done
d46655ef 307 fi
308 if [ ! -f "$SPECFILE" ]; then
309 Exit_error err_no_spec_in_repo;
310 fi
568630a3 311
d46655ef 312 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
313 chmod $CHMOD_MODE $SPECFILE
314 fi
315 unset OPTIONS
316 grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
317}
318
319find_mirror(){
320
321 cd "$SPECS_DIR"
568630a3
JB
322 url="$1"
323 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
324 cvs update mirrors >&2
d46655ef 325 fi
326
327 IFS="|"
328 while read origin mirror name rest; do
568630a3 329 ol=`echo -n "$origin"|wc -c`
d46655ef 330 prefix="`echo -n "$url" | head -c $ol`"
331 if [ "$prefix" = "$origin" ] ; then
332 suffix="`echo "$url"|cut -b $ol-`"
333 echo -n "$mirror$suffix"
334 return 0
335 fi
336 done < mirrors
337 echo "$url"
338}
339
568630a3
JB
340src_no ()
341{
342 cd $SPECS_DIR
343 $RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | \
344 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
345 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
346 head -1 | xargs
347}
348
349src_md5 ()
350{
351 no=$(src_no "$1")
352 [ -z "$no" ] && return
353 cd $SPECS_DIR
354 spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
355 if [ -z "$spec_rev" ]; then
356 spec_rev="$(head -1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
357 fi
358 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
359 md5=$(grep -s -v '^#' additional-md5sums | \
360 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
361 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
362 grep -E '^[0-9a-f]{32}$')
363 if [ X"$md5" = X"" ] ; then
364 grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs
365 else
366 if [ $(echo "$md5" | wc -l) != 1 ] ; then
367 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
368 fi
369 echo "$md5" | tail -1
370 fi
371}
372
373distfiles_url ()
374{
375 echo "$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
376}
377
378good_md5 ()
379{
380 md5=$(src_md5 "$1")
381 [ "$md5" = "" ] || \
382 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
383}
384
d46655ef 385get_files()
386{
387 GET_FILES="$@"
388
568630a3
JB
389 if [ -n "$DEBUG" ]; then
390 set -x;
391 set -v;
d46655ef 392 fi
393
394 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
395 cd $SOURCE_DIR
396
397 OPTIONS="up "
398 if [ -n "$CVSROOT" ]; then
399 OPTIONS="-d $CVSROOT $OPTIONS"
400 else
401 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
402 echo "warning: No cvs access defined for SOURCES"
403 NOCVS="yes"
404 fi
405 fi
568630a3 406 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
d46655ef 407 OPTIONS="$OPTIONS -A"
568630a3
JB
408 else
409 if [ -n "$CVSDATE" ]; then
410 OPTIONS="$OPTIONS -D $CVSDATE"
411 fi
412 if [ -n "$CVSTAG" ]; then
413 OPTIONS="$OPTIONS -r $CVSTAG"
414 fi
d46655ef 415 fi
416 for i in $GET_FILES; do
568630a3 417 if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
d46655ef 418 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
419 echo "Warning: no URL given for $i"
420 fi
568630a3
JB
421
422 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
423 if good_md5 "$i"; then
424 echo "$(nourl "$i") having proper md5sum already exists"
425 continue
426 fi
427 target=$(nourl "$i")
428 url=$(distfiles_url "$i")
429 if [ `echo $url | grep -E '^(\.|/)'` ] ; then
430 ${GETLOCAL} $url $target
431 else
432 if [ -z "$NOMIRRORS" ] ; then
433 url="`find_mirror "$url"`"
434 fi
435 ${GETURI} -O "$target" "$url" || \
436 if [ `echo $url | grep -E 'ftp://'` ]; then
437 ${GETURI2} -O "$target" "$url"
438 fi
439 test -s "$target" || rm -f "$target"
440 fi
441 elif [ -z "$(src_md5 "$i")" ] && \
442 ( [ -z "$NOCVS" ] || echo $i | grep -qvE '(ftp|http|https)://' ); then
443 result=1
444 retries_counter=0
445 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
446 retries_counter=$(( $retries_counter + 1 ))
447 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
448 result=$?
449 [ -n "$output" ] && echo "$output"
450 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
451 echo "Trying again [`nourl $i`]... ($retries_counter)"
452 sleep 2
453 continue
454 else
455 break
456 fi
457 done
d46655ef 458 fi
568630a3
JB
459
460 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
461 if [ -z "$NOMIRRORS" ] ; then
5dddfe45
JB
462 im="`find_mirror "$i"`"
463 else
464 im="$i"
d46655ef 465 fi
5dddfe45
JB
466 ${GETURI} "$im" || \
467 if [ `echo $im | grep -E 'ftp://'` ]; then ${GETURI2} "$im" ; fi
d46655ef 468 fi
469
568630a3
JB
470
471 fi
472 srcno=$(src_no $i)
473 if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
474 Exit_error err_no_source_in_repo $i;
475 elif [ -n "$UPDATE5" ] && \
476 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
477 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
478 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
479 then
480 echo "Updating source-$srcno md5."
481 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
482 perl -i -ne '
483 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
484 print "# Source'$srcno'-md5:\t'$md5'\n"
485 if /^Source'$srcno'\s*:\s+/;
486 ' \
487 $SPECS_DIR/$SPECFILE
488 fi
489
490 if good_md5 "$i"; then
491 :
492 else
493 echo "MD5 sum mismatch. Use -U to refetch sources,"
494 echo "or -5 to update md5 sums, if you're sure files are correct."
495 Exit_error err_no_source_in_repo $i
d46655ef 496 fi
497 done
568630a3 498
d46655ef 499 if [ "$CHMOD" = "yes" ]; then
500 CHMOD_FILES="`nourl $GET_FILES`"
501 if [ -n "$CHMOD_FILES" ]; then
502 chmod $CHMOD_MODE $CHMOD_FILES
503 fi
504 fi
505 unset OPTIONS
506 fi
507}
508
509tag_files()
510{
511 TAG_FILES="$@"
512
568630a3
JB
513 if [ -n "$DEBUG" ]; then
514 set -x;
515 set -v;
d46655ef 516 fi
517
518 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
519 echo $PACKAGE_VERSION
520 echo $PACKAGE_RELEASE
568630a3 521 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
648b2a16 522 if [ "$TAG_VERSION" = "yes" ]; then
523 echo "CVS tag: $TAGVER"
524 fi
525 if [ -n "$TAG" ]; then
526 echo "CVS tag: $TAG"
527 fi
d46655ef 528
529 OPTIONS="tag -F"
530 if [ -n "$CVSROOT" ]; then
531 OPTIONS="-d $CVSROOT $OPTIONS"
532 fi
533
534 cd $SOURCE_DIR
535 for i in $TAG_FILES; do
536 if [ -f `nourl $i` ]; then
648b2a16 537 if [ "$TAG_VERSION" = "yes" ]; then
538 cvs $OPTIONS $TAGVER `nourl $i`
539 fi
540 if [ -n "$TAG" ]; then
541 cvs $OPTIONS $TAG `nourl $i`
542 fi
d46655ef 543 else
544 Exit_error err_no_source_in_repo $i
545 fi
546 done
547
548 cd $SPECS_DIR
648b2a16 549 if [ "$TAG_VERSION" = "yes" ]; then
550 cvs $OPTIONS $TAGVER $SPECFILE
551 fi
552 if [ -n "$TAG" ]; then
553 cvs $OPTIONS $TAG $SPECFILE
554 fi
d46655ef 555
556 unset OPTIONS
557 fi
558}
559
560branch_files()
561{
568630a3
JB
562 TAG=$1
563 echo "CVS branch tag: $TAG"
564 shift;
d46655ef 565
568630a3 566 TAG_FILES="$@"
d46655ef 567
568630a3
JB
568 if [ -n "$DEBUG" ]; then
569 set -x;
570 set -v;
571 fi
d46655ef 572
568630a3 573 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
d46655ef 574
568630a3
JB
575 OPTIONS="tag -b"
576 if [ -n "$CVSROOT" ]; then
577 OPTIONS="-d $CVSROOT $OPTIONS"
d46655ef 578 fi
568630a3
JB
579 cd $SOURCE_DIR
580 for i in $TAG_FILES; do
581 if [ -f `nourl $i` ]; then
582 cvs $OPTIONS $TAG `nourl $i`
583 else
584 Exit_error err_no_source_in_repo $i
585 fi
586 done
587 cd $SPECS_DIR
588 cvs $OPTIONS $TAG $SPECFILE
589
590 unset OPTIONS
591 fi
d46655ef 592}
593
568630a3
JB
594
595
d46655ef 596build_package()
597{
568630a3 598 if [ -n "$DEBUG" ]; then
d46655ef 599 set -x;
568630a3 600 set -v;
d46655ef 601 fi
602
603 cd $SPECS_DIR
604
568630a3
JB
605 if [ -n "$TRY_UPGRADE" ]; then
606
607 if [ -n "FLOAT_VERSION" ]; then
608 TNOTIFY=`./pldnotify.awk $SPECFILE -n`
609 else
610 TNOTIFY=`./pldnotify.awk $SPECFILE`
611 fi
612
d46655ef 613 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
568630a3 614
d46655ef 615 if [ -n "$TNEWVER" ]; then
568630a3 616
d46655ef 617 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
568630a3 618
d46655ef 619 echo "New version found, updating spec file to version " $TNEWVER
568630a3 620
d46655ef 621 cp -f $SPECFILE $SPECFILE.bak
568630a3 622
d46655ef 623 chmod +w $SPECFILE
568630a3 624
d46655ef 625 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
626 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
568630a3 627
d46655ef 628 parse_spec;
568630a3 629
d46655ef 630 get_files "$SOURCES $PATCHES";
568630a3 631
d46655ef 632 unset TOLDVER TNEWVER TNOTIFY
633 fi
568630a3 634
d46655ef 635 fi
636
637
638 cd $SPECS_DIR
639
640 case "$COMMAND" in
641 build )
642 BUILD_SWITCH="-ba" ;;
643 build-binary )
644 BUILD_SWITCH="-bb" ;;
645 build-source )
646 BUILD_SWITCH="-bs --nodeps" ;;
647 esac
648 if [ -n "$LOGFILE" ]; then
568630a3
JB
649 if [ -n "$CVSTAG" ]; then
650 LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_"
651 else
652 LTAG=""
653 fi
d46655ef 654 LOG=`eval echo $LOGFILE`
568630a3
JB
655 if [ -n "$LASTLOG_FILE" ]; then
656 echo "LASTLOG=$LOG" > $LASTLOG_FILE
657 fi
658 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
659 (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
660 RETVAL=`cat $RES_FILE`
661 rm $RES_FILE
662 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
663 if [ "$RETVAL" -eq "0" ]; then
664 mv $LOG $LOGDIROK
665 else
666 mv $LOG $LOGDIRFAIL
667 fi
668 fi
d46655ef 669 else
670 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
568630a3 671 RETVAL=$?
d46655ef 672 fi
673
568630a3
JB
674 if [ "$RETVAL" -ne "0" ]; then
675
676 if [ -n "$TRY_UPGRADE" ]; then
d46655ef 677 echo "\n!!! Package with new version cannot be build automagically\n"
678 mv -f $SPECFILE.bak $SPECFILE
679 fi
568630a3 680
d46655ef 681 Exit_error err_build_fail;
682 fi
568630a3 683
d46655ef 684 unset BUILD_SWITCH
685}
686
687nourl()
688{
568630a3 689 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
d46655ef 690}
691#---------------------------------------------
692# main()
693
694if [ "$#" = 0 ]; then
695 usage;
696 exit 1
697fi
698
699while test $# -gt 0 ; do
700 case "${1}" in
568630a3
JB
701 -5 | --update-md5 )
702 COMMAND="get";
703 NODIST="yes"
704 UPDATE5="yes"
705 shift ;;
706 -a5 | --add-md5 )
707 COMMAND="get";
708 NODIST="yes"
709 NOCVS="yes"
710 UPDATE5="yes"
711 ADD5="yes"
712 shift ;;
d46655ef 713 -D | --debug )
714 DEBUG="yes"; shift ;;
715 -V | --version )
716 COMMAND="version"; shift ;;
717 -a | --as_anon )
568630a3 718 CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
d46655ef 719 -b | -ba | --build )
720 COMMAND="build"; shift ;;
721 -bb | --build-binary )
722 COMMAND="build-binary"; shift ;;
723 -bs | --build-source )
724 COMMAND="build-source"; shift ;;
725 -B | --branch )
726 COMMAND="branch"; shift; TAG="${1}"; shift;;
727 -c | --clean )
728 CLEAN="--clean --rmspec --rmsource"; shift ;;
729 -d | --cvsroot )
730 shift; CVSROOT="${1}"; shift ;;
731 -g | --get )
732 COMMAND="get"; shift ;;
733 -h | --help )
734 COMMAND="usage"; shift ;;
735 -l | --logtofile )
736 shift; LOGFILE="${1}"; shift ;;
737 -ni| --nice )
738 shift; DEF_NICE_LEVEL=${1}; shift ;;
739 -m | --mr-proper )
740 COMMAND="mr-proper"; shift ;;
741 -nc | --no-cvs )
742 NOCVS="yes"; shift ;;
568630a3 743 -ncs | --no-cvs-specs )
d46655ef 744 NOCVSSPEC="yes"; shift ;;
568630a3
JB
745 -nd | --no-distfiles )
746 NODIST="yes"; shift ;;
d46655ef 747 -nm | --no-mirrors )
748 NOMIRRORS="yes"; shift ;;
749 -nu | --no-urls )
750 NOURLS="yes"; shift ;;
751 -ns | --no-srcs )
752 NOSRCS="yes"; shift ;;
753 -ns0 | --no-source0 )
754 NOSOURCE0="yes"; shift ;;
755 --opts )
756 shift; RPMOPTS="${1}"; shift ;;
757 --with | --without )
758 BCOND="$BCOND $1 $2" ; shift 2 ;;
759 -q | --quiet )
760 QUIET="--quiet"; shift ;;
568630a3
JB
761 --date )
762 CVSDATE="${2}"; shift 2 ;;
d46655ef 763 -r | --cvstag )
764 shift; CVSTAG="${1}"; shift ;;
765 -Tvs | --tag-version-stable )
766 COMMAND="tag";
767 TAG="STABLE"
768 TAG_VERSION="yes"
769 shift;;
648b2a16 770 -Tvn | --tag-version-nest )
d46655ef 771 COMMAND="tag";
648b2a16 772 TAG="NEST"
d46655ef 773 TAG_VERSION="yes"
774 shift;;
775 -Ts | --tag-stable )
776 COMMAND="tag";
777 TAG="STABLE"
778 TAG_VERSION="no"
779 shift;;
648b2a16 780 -Tn | --tag-nest )
d46655ef 781 COMMAND="tag";
648b2a16 782 TAG="NEST"
d46655ef 783 TAG_VERSION="no"
784 shift;;
785 -Tv | --tag-version )
786 COMMAND="tag";
648b2a16 787 TAG=""
d46655ef 788 TAG_VERSION="yes"
789 shift;;
790 -T | --tag )
791 COMMAND="tag";
792 shift
793 TAG="$1"
794 TAG_VERSION="no"
795 shift;;
568630a3
JB
796 -U | --update )
797 UPDATE="yes"
798 NODIST="yes"
799 UPDATE5="yes"
800 COMMAND="get"
801 shift ;;
d46655ef 802 -u | --try-upgrade )
803 TRY_UPGRADE="1"; shift ;;
568630a3
JB
804 -un | --try-upgrade-with-float-version )
805 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
806 -v | --verbose )
807 BE_VERBOSE="1"; shift ;;
d46655ef 808 --define)
809 shift
810 MACRO="${1}"
811 VALUE="${2}"
812 shift 2
813 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
814 ;;
815 * )
568630a3 816 SPECFILE="`basename ${1} .spec`.spec"; shift ;;
d46655ef 817 esac
818done
819
568630a3
JB
820if [ -n "$DEBUG" ]; then
821 set -x;
822 set -v;
d46655ef 823fi
824
825case "$COMMAND" in
826 "build" | "build-binary" | "build-source" )
827 init_builder;
828 if [ -n "$SPECFILE" ]; then
829 get_spec;
830 parse_spec;
648b2a16 831
832 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
568630a3 833 TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
648b2a16 834 CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
835 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
836
837 if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
838 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
839 fi
840 fi
841
d46655ef 842 if [ -n "$ICONS" ]; then
568630a3
JB
843 get_files $ICONS;
844 parse_spec;
845 fi
846 if [ -n "$NOSOURCE0" ] ; then
847 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
d46655ef 848 fi
849 get_files "$SOURCES $PATCHES";
850 build_package;
851 else
852 Exit_error err_no_spec_in_cmdl;
853 fi
854 ;;
855 "branch" )
568630a3 856 init_builder;
d46655ef 857 if [ -n "$SPECFILE" ]; then
858 get_spec;
859 parse_spec;
860 if [ -n "$ICONS" ]; then
861 get_files $ICONS
862 parse_spec;
863 fi
864 get_files $SOURCES $PATCHES;
865 branch_files $TAG "$SOURCES $PATCHES $ICONS";
866 else
867 Exit_error err_no_spec_in_cmdl;
868 fi
568630a3 869 ;;
d46655ef 870 "get" )
871 init_builder;
872 if [ -n "$SPECFILE" ]; then
873 get_spec;
874 parse_spec;
875 if [ -n "$ICONS" ]; then
876 get_files $ICONS
877 parse_spec;
878 fi
879 if [ -n "$NOSOURCE0" ] ; then
880 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
881 fi
882 get_files $SOURCES $PATCHES
883 else
884 Exit_error err_no_spec_in_cmdl;
885 fi
886 ;;
887 "tag" )
888 init_builder;
889 if [ -n "$SPECFILE" ]; then
890 get_spec;
891 parse_spec;
892 if [ -n "$ICONS" ]; then
893 get_files $ICONS
894 parse_spec;
895 fi
896 get_files $SOURCES $PATCHES;
897 tag_files "$SOURCES $PATCHES $ICONS";
898 else
899 Exit_error err_no_spec_in_cmdl;
900 fi
901 ;;
902 "mr-proper" )
903 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
904 ;;
905 "usage" )
906 usage;;
907 "version" )
908 echo "$VERSION";;
909esac
910
911cd $__PWD
This page took 0.175665 seconds and 4 git commands to generate.