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