]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame_incremental - builder.sh
- ts!=sw causes spaces inserted everywhere
[packages/rpm-build-tools.git] / builder.sh
... / ...
CommitLineData
1#!/bin/sh
2# -----------
3# $Id$
4# Exit codes:
5# 0 - succesful
6# 1 - help displayed
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# 6 - spec file with errors
12# 7 - wrong source in /etc/poldek.conf
13# 8 - Failed installing buildrequirements and subrequirements
14# 9 - Requested tag already exist
15# 10 - Refused to build fractional release
16# 100 - Unknown error (should not happen)
17
18# Notes (todo):
19# - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
20# - when Icon: field is present, -5 and -a5 doesn't work
21# - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
22
23VERSION="\
24Build package utility from PLD Linux CVS repository
25V 0.13 (C) 1999-2005 Free Penguins".
26PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
27
28COMMAND="build"
29TARGET=""
30
31SPECFILE=""
32BE_VERBOSE=""
33QUIET=""
34CLEAN=""
35DEBUG=""
36NOURLS=""
37NOCVS=""
38NOCVSSPEC=""
39NODIST=""
40UPDATE=""
41UPDATE5=""
42ADD5=""
43NO5=""
44ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
45CVSROOT=""
46
47# It can be used i.e. in log file naming.
48# See LOGFILE example.
49DATE=`date +%Y-%m-%d_%H-%M-%S`
50
51# Example: LOGFILE='../log.$PACKAGE_NAME'
52# Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
53# Yes, you can use variable name! Note _single_ quotes!
54LOGFILE=''
55
56LOGDIR=""
57LOGDIROK=""
58LOGDIRFAIL=""
59LASTLOG_FILE=""
60
61CHMOD="no"
62CHMOD_MODE="0444"
63RPMOPTS=""
64BCOND=""
65GROUP_BCONDS="no"
66CVSIGNORE_DF="no"
67
68PATCHES=""
69SOURCES=""
70ICONS=""
71PACKAGE_RELEASE=""
72PACKAGE_VERSION=""
73PACKAGE_NAME=""
74PROTOCOL="ftp"
75WGET_RETRIES=${MAX_WGET_RETRIES:-0}
76CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
77
78CVSTAG=""
79RES_FILE=""
80
81CVS_SERVER="cvs.pld-linux.org"
82DISTFILES_SERVER="://distfiles.pld-linux.org"
83ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
84
85DEF_NICE_LEVEL=19
86
87FAIL_IF_NO_SOURCES="yes"
88
89# let get_files skip over files which are present to get those damn files fetched
90SKIP_EXISTING_FILES="no"
91
92if [ -x /usr/bin/rpm-getdeps ]; then
93 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
94else
95 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
96fi
97
98# Here we load saved user environment used to
99# predefine options set above, or passed to builder
100# in command line.
101# This one reads global system environment settings:
102if [ -f ~/etc/builderrc ]; then
103 . ~/etc/builderrc
104fi
105# And this one cascades settings using user personal
106# builder settings.
107# Example of ~/.builderrc:
108#
109#UPDATE_POLDEK_INDEXES="yes"
110#FETCH_BUILD_REQUIRES="yes"
111#REMOVE_BUILD_REQUIRES="force"
112#GROUP_BCONDS="yes"
113#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
114#
115SU_SUDO=""
116if [ -n "$HOME_ETC" ]; then
117 USER_CFG="$HOME_ETC/.builderrc"
118else
119 USER_CFG=~/.builderrc
120fi
121
122[ -f "$USER_CFG" ] && . "$USER_CFG"
123
124wget --help 2>&1 | grep -q ' \-\-no-check\-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
125
126if [ -n "$USE_PROZILLA" ]; then
127 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
128 GETURI2="$GETURI"
129 OUTFILEOPT="-O"
130elif [ -n "$USE_AXEL" ]; then
131 GETURI="axel -a $AXEL_OPTS"
132 GETURI2="$GETURI"
133 OUTFILEOPT="-o"
134else
135 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
136 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
137
138 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
139 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
140 OUTFILEOPT="-O"
141fi
142
143GETLOCAL="cp -a"
144
145if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
146 RPM="rpm"
147 RPMBUILD="rpm"
148else
149 RPM="rpm"
150 RPMBUILD="rpmbuild"
151fi
152
153POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
154POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
155
156run_poldek()
157{
158 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
159 if [ -n "$LOGFILE" ]; then
160 LOG=`eval echo $LOGFILE`
161 if [ -n "$LASTLOG_FILE" ]; then
162 echo "LASTLOG=$LOG" > $LASTLOG_FILE
163 fi
164 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
165 return $exit_pldk
166 else
167 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
168 return `cat ${RES_FILE}`
169 rm -rf ${RES_FILE}
170 fi
171}
172
173#---------------------------------------------
174# functions
175
176usage()
177{
178 if [ -n "$DEBUG" ]; then set -xv; fi
179 echo "\
180Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
181
182[-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
183[{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
184[-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
185[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
186[-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
187[-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
188[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
189[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds]
190[--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
191
192-5, --update-md5 - update md5 comments in spec, implies -nd -ncs
193-a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
194-n5, --no-md5 - ignore md5 comments in spec
195-D, --debug - enable builder script debugging mode,
196-debug - produce rpm debug package (same as --opts -debug)
197-V, --version - output builder version
198-a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
199-b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
200 from <package>.spec,
201-bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
202 only package from <package>.spec,
203-bp, --build-prep - execute the %prep phase of <package>.spec,
204-bc - reserved (not implemented)
205-bi reserved (not implemented)
206-bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
207 them into src.rpm,
208--short-circuit - reserved (not implemented)
209-B, --branch - add branch
210-c, --clean - clean all temporarily created files (in BUILD, SOURCES,
211 SPECS and \$RPM_BUILD_ROOT),
212-d <cvsroot>, --cvsroot <cvsroot>
213 - setup \$CVSROOT,
214--define <macro> <value>
215 - define a macro <macro> with value <value>,
216--nodeps - rpm won't check any dependences
217-g, --get - get <package>.spec and all related files from CVS repo
218 or HTTP/FTP,
219-h, --help - this message,
220--http - use http instead of ftp,
221-l <logfile>, --logtofile <logfile>
222 - log all to file,
223-m, --mr-proper - only remove all files related to spec file and all work
224 resources,
225-nc, --no-cvs - don't download sources from CVS, if source URL is given,
226-ncs, --no-cvs-specs
227 - don't check specs in CVS
228-nd, --no-distfiles - don't download from distfiles
229-nm, --no-mirrors - don't download from mirror, if source URL is given,
230-nu, --no-urls - don't try to download from FTP/HTTP location,
231-ns, --no-srcs - don't download Sources
232-ns0, --no-source0 - don't download Source0
233-nn, --no-net - don't download anything from the net
234-ske,
235--skip-existing-files - skip existing files in get_files
236--opts <rpm opts> - additional options for rpm
237-q, --quiet - be quiet,
238--date yyyy-mm-dd - build package using resources from specified CVS date,
239-r <cvstag>, --cvstag <cvstag>
240 - build package using resources from specified CVS tag,
241-R, --fetch-build-requires
242 - fetch what is BuildRequired,
243-RB, --remove-build-requires
244 - remove all you fetched with -R or --fetch-build-requires
245 remember, this option requires confirmation,
246-FRB, --force-remove-build-requires
247 - remove all you fetched with -R or --fetch-build-requires
248 remember, this option works without confirmation,
249-sf, --source-files - list sources - bare filenames (intended for offline
250 operations; does not work when Icon field is present
251 but icon file is absent),
252-sp, --source-paths - list sources - filenames with full local paths (intended for
253 offline operations; does not work when Icon field is present
254 but icon file is absent),
255-su, --source-urls - list urls - urls to sources and patches
256 intended for copying urls with spec with lots of macros in urls
257-T <cvstag> , --tag <cvstag>
258 - add cvs tag <cvstag> for files,
259-Tvs, --tag-version-stable
260 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
261-Tvn, --tag-version-nest
262 - add cvs tags NEST and NAME-VERSION-RELEASE for files,
263-Ts, --tag-stable
264 - add cvs tag STABLE for files,
265-Tn, --tag-nest
266 - add cvs tag NEST for files,
267-Tv, --tag-version
268 - add cvs tag NAME-VERSION-RELEASE for files,
269-Tp, --tag-prefix <prefix>
270 - add <prefix> to NAME-VERSION-RELEASE tags,
271-tt, --test-tag <prefix>
272 - fail if tag is already present,
273-ir, --integer-release-only
274 - allow only integer and snapshot releases
275-v, --verbose - be verbose,
276-u, --try-upgrade - check version, and try to upgrade package
277-un, --try-upgrade-with-float-version
278 - as above, but allow float version
279-U, --update - refetch sources, don't use distfiles, and update md5 comments
280-Upi, --update-poldek-indexes
281 - refresh or make poldek package index files.
282-np, --nopatch <patchnumber>
283 - don't apply <patchnumber>
284--show-bconds - show available conditional builds, which can be used
285 - with --with and/or --without switches.
286--with/--without <feature>
287 - conditional build package depending on %_with_<feature>/
288 %_without_<feature> macro switch. You may now use
289 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
290 constructions. Set GROUP_BCONDS to yes to make use of it.
291--target <platform>, --target=<platform>
292 - build for platform <platform>.
293"
294}
295
296update_shell_title() {
297 [ -t 1 ] || return
298 local len=${COLUMNS:-80}
299 local msg=$(echo "$*" | cut -c-$len)
300
301 msg="builder[$SPECFILE] ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
302 case "$TERM" in
303 cygwin|xterm*)
304 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
305 ;;
306 screen*)
307 echo >&2 -ne "\033]0;$msg\007"
308 ;;
309 esac
310}
311
312# set TARGET from BuildArch: from SPECFILE
313set_spec_target() {
314 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
315 tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
316 if [ "$tmp" ]; then
317 TARGET="$tmp"
318 case "$RPMBUILD" in
319 "rpmbuild")
320 TARGET_SWITCH="--target $TARGET" ;;
321 "rpm")
322 TARGET_SWITCH="--target=$TARGET" ;;
323 esac
324 fi
325 fi
326}
327
328cache_rpm_dump () {
329 if [ -n "$DEBUG" ]; then
330 set -x;
331 set -v;
332 fi
333
334rpm_dump_cache=`
335 case "$RPMBUILD" in
336 rpm )
337 rpm -bp --nodeps --define 'prep %dump' $BCOND $TARGET_SWITCH $SPECFILE 2>&1
338 ;;
339 rpmbuild )
340 rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $TARGET_SWITCH $SPECFILE 2>&1
341 ;;
342 esac`
343}
344
345rpm_dump () {
346 if [ -z "$rpm_dump_cache" ] ; then
347 echo "internal error: cache_rpm_dump not called!" 1>&2
348 fi
349 echo "$rpm_dump_cache"
350}
351
352parse_spec()
353{
354 update_shell_title "parsing specfile"
355 if [ -n "$DEBUG" ]; then
356 set -x;
357 set -v;
358 fi
359
360 cd $SPECS_DIR
361
362 cache_rpm_dump
363
364 if [ "$NOSRCS" != "yes" ]; then
365 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
366 fi
367 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
368 FAIL_IF_NO_SOURCES="no"
369 fi
370
371 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
372 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
373 PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
374 PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -n 1`"
375 PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
376
377# These variables may be unset after first cache_rpm_dump call
378# (because of not-yet-retrieved icon file)
379#
380# if [ -z "$PACKAGE_NAME" -o -z "$PACKAGE_VERSION" -o -z "$PACKAGE_RELEASE" ]; then
381# Exit_error err_no_package_data;
382# fi
383
384 if [ -n "$BE_VERBOSE" ]; then
385 echo "- Sources : `nourl $SOURCES`"
386 if [ -n "$PATCHES" ]; then
387 echo "- Patches : `nourl $PATCHES`"
388 else
389 echo "- Patches : *no patches needed*"
390 fi
391 if [ -n "$ICONS" ]; then
392 echo "- Icon : `nourl $ICONS`"
393 else
394 echo "- Icon : *no package icon*"
395 fi
396 echo "- Name : $PACKAGE_NAME"
397 echo "- Version : $PACKAGE_VERSION"
398 echo "- Release : $PACKAGE_RELEASE"
399 fi
400}
401
402Exit_error()
403{
404 if [ -n "$DEBUG" ]; then
405 set -x;
406 set -v;
407 fi
408
409 cd "$__PWD"
410
411 case "$1" in
412 "err_no_spec_in_cmdl" )
413 remove_build_requires
414 echo "ERROR: spec file name not specified.";
415 exit 2 ;;
416 "err_no_spec_in_repo" )
417 remove_build_requires
418 echo "Error: spec file not stored in CVS repo.";
419 exit 3 ;;
420 "err_no_source_in_repo" )
421 remove_build_requires
422 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
423 exit 4 ;;
424 "err_build_fail" )
425 remove_build_requires
426 echo "Error: package build failed. (${2:-no more info})";
427 exit 5 ;;
428 "err_no_package_data" )
429 remove_build_requires
430 echo "Error: couldn't get out package name/version/release from spec file."
431 exit 6 ;;
432 "err_tag_exists" )
433 remove_build_requires
434 echo "Tag ${2} already exists (spec release: ${3}).";
435 exit 9 ;;
436 "err_fract_rel" )
437 remove_build_requires
438 echo "Release ${2} not integer and not a snapshot.";
439 exit 10 ;;
440 "err_branch_exists" )
441 remove_build_requires
442 echo "Tree branch already exists (${2}).";
443 exit 11 ;;
444
445 esac
446 echo "Unknown error."
447 exit 100
448}
449
450init_builder()
451{
452 if [ -n "$DEBUG" ]; then
453 set -x;
454 set -v;
455 fi
456
457 SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
458 SPECS_DIR="`$RPM --eval '%{_specdir}'`"
459
460 __PWD="`pwd`"
461}
462
463get_spec()
464{
465
466 update_shell_title "get_spec"
467
468 if [ -n "$DEBUG" ]; then
469 set -x;
470 set -v;
471 fi
472
473 cd "$SPECS_DIR"
474 if [ \! -f "$SPECFILE" ]; then
475 SPECFILE="`basename $SPECFILE .spec`.spec";
476 fi
477 if [ "$NOCVSSPEC" != "yes" ]; then
478 OPTIONS="up "
479
480 if [ -n "$CVSROOT" ]; then
481 OPTIONS="-d $CVSROOT $OPTIONS"
482 else
483 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
484 echo "warning: No cvs access defined - using local .spec file"
485 NOCVSSPEC="yes"
486 fi
487 fi
488
489 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
490 OPTIONS="$OPTIONS -A"
491 else
492 if [ -n "$CVSDATE" ]; then
493 OPTIONS="$OPTIONS -D $CVSDATE"
494 fi
495 if [ -n "$CVSTAG" ]; then
496 OPTIONS="$OPTIONS -r $CVSTAG"
497 fi
498 fi
499
500 result=1
501 retries_counter=0
502 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
503 do
504 retries_counter=$(( $retries_counter + 1 ))
505 output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
506 result=$?
507 [ -n "$output" ] && echo "$output"
508 if [ "$result" -ne "0" ]; then
509 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
510 echo "Trying again [$SPECFILE]... ($retries_counter)"
511 sleep 2
512 continue
513 fi
514 Exit_error err_no_spec_in_repo;
515 fi
516 done
517 fi
518 if [ ! -f "$SPECFILE" ]; then
519 Exit_error err_no_spec_in_repo;
520 fi
521
522 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
523 chmod $CHMOD_MODE $SPECFILE
524 fi
525 unset OPTIONS
526 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
527
528 set_spec_target
529}
530
531find_mirror()
532{
533 cd "$SPECS_DIR"
534 url="$1"
535 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
536 cvs update mirrors >&2
537 fi
538
539 IFS="|"
540 while read origin mirror name rest
541 do
542 ol=`echo -n "$origin"|wc -c`
543 prefix="`echo -n "$url" | head -c $ol`"
544 if [ "$prefix" = "$origin" ] ; then
545 suffix="`echo "$url"|cut -b $ol-`"
546 echo -n "$mirror$suffix"
547 return 0
548 fi
549 done < mirrors
550 echo "$url"
551}
552
553src_no ()
554{
555 cd $SPECS_DIR
556 rpm_dump | \
557 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
558 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
559 head -n 1 | xargs
560}
561
562src_md5 ()
563{
564 [ X"$NO5" = X"yes" ] && return
565 no=$(src_no "$1")
566 [ -z "$no" ] && return
567 cd $SPECS_DIR
568 spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
569 if [ -z "$spec_rev" ]; then
570 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
571 fi
572 spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
573 md5=$(grep -s -v '^#' additional-md5sums | \
574 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
575 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
576 grep -E '^[0-9a-f]{32}$')
577 if [ X"$md5" = X"" ] ; then
578 source_md5=`grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
579 if [ ! -z "$source_md5" ] ; then
580 echo $source_md5;
581 else
582 # we have empty SourceX-md5, but it is still possible
583 # that we have NoSourceX-md5 AND NoSource: X
584 nosource_md5=`grep -i "#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
585 if [ ! -z "$nosource_md5" -a ! X"`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" = X"" ] ; then
586 echo $nosource_md5;
587 fi;
588 fi;
589 else
590 if [ $(echo "$md5" | wc -l) != 1 ] ; then
591 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
592 fi
593 echo "$md5" | tail -n 1
594 fi
595}
596
597distfiles_url ()
598{
599 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
600}
601
602distfiles_attic_url ()
603{
604 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
605}
606
607good_md5 ()
608{
609 md5=$(src_md5 "$1")
610 [ "$md5" = "" ] || \
611 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
612}
613
614good_size ()
615{
616 size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
617 [ -n "$size" -a "$size" -gt 0 ]
618}
619
620cvsignore_df ()
621{
622 if [ "$CVSIGNORE_DF" != "yes" ]; then
623 return
624 fi
625 cvsignore=${SOURCE_DIR}/.cvsignore
626 if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
627 echo "$1" >> $cvsignore
628 fi
629}
630
631cvsup()
632{
633 update_shell_title "cvsup"
634 local OPTIONS="up "
635 if [ -n "$CVSROOT" ]; then
636 OPTIONS="-d $CVSROOT $OPTIONS"
637 else
638 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
639 echo "warning: No cvs access defined for SOURCES"
640 NOCVS="yes"
641 fi
642 fi
643 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
644 OPTIONS="$OPTIONS -A"
645 else
646 if [ -n "$CVSDATE" ]; then
647 OPTIONS="$OPTIONS -D $CVSDATE"
648 fi
649 if [ -n "$CVSTAG" ]; then
650 OPTIONS="$OPTIONS -r $CVSTAG"
651 fi
652 fi
653
654 local result=1
655 local retries_counter=0
656 update_shell_title "cvsup: $# files"
657 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
658 retries_counter=$(( $retries_counter + 1 ))
659 output=$(LC_ALL=C cvs $OPTIONS "$@" 2>&1)
660 result=$?
661 [ -n "$output" ] && echo "$output"
662 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then
663 echo "Trying again [$*]... ($retries_counter)"
664 update_shell_title "cvsup: retry #$retries_counter"
665 sleep 2
666 continue
667 else
668 break
669 fi
670 done
671 update_shell_title "cvsup: done!"
672}
673
674get_files()
675{
676 GET_FILES="$@"
677 update_shell_title "fetching sources"
678
679 if [ -n "$DEBUG" ]; then
680 set -x;
681 set -v;
682 fi
683
684 if [ $# -gt 0 ]; then
685 cd "$SOURCE_DIR"
686
687 local nf=$(echo "$GET_FILES" | wc -w)
688 local nc=0
689 local get_files_cvs=""
690 for i in $GET_FILES; do
691 nc=$((nc + 1))
692 SHELL_TITLE_PREFIX="get_files[$nc/$nf]"
693 update_shell_title "$i"
694 local fp=`nourl "$i"`
695 if [ -f "$fp" ] && [ "$SKIP_EXISTING_FILES" = "yes" ]; then
696 continue
697 fi
698 if [ -n "$UPDATE5" ]; then
699 if [ -n "$ADD5" ]; then
700 [ "$fp" = "$i" ] && continue
701 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
702 else
703 grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
704 fi
705 fi
706 FROM_DISTFILES=0
707 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
708 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
709 echo "Warning: no URL given for $i"
710 fi
711
712 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
713 if good_md5 "$i" && good_size "$i"; then
714 echo "$(nourl "$i") having proper md5sum already exists"
715 continue
716 fi
717 target=$(nourl "$i")
718 url=$(distfiles_url "$i")
719 url_attic=$(distfiles_attic_url "$i")
720 FROM_DISTFILES=1
721 if [ "`echo $url | grep -E '^(\.|/)'`" ]; then
722 update_shell_title "${GETLOCAL}: $url"
723 ${GETLOCAL} $url $target
724 else
725 if [ -z "$NOMIRRORS" ]; then
726 url="`find_mirror "$url"`"
727 fi
728 update_shell_title "${GETURI}: $url"
729 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
730 if [ "`echo $url | grep -E 'ftp://'`" ]; then
731 update_shell_title "${GETURI2}: $url"
732 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
733 fi
734 fi
735 if ! test -s "$target"; then
736 rm -f "$target"
737 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
738 update_shell_title "${GETLOCAL}: $url_attic"
739 ${GETLOCAL} $url_attic $target
740 else
741 if [ -z "$NOMIRRORS" ]; then
742 url_attic="`find_mirror "$url_attic"`"
743 fi
744 update_shell_title "${GETURI}: $url_attic"
745 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
746 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
747 update_shell_title "${GETURI2}: $url_attic"
748 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
749 fi
750 fi
751 fi
752 if test -s "$target"; then
753 cvsignore_df $target
754 else
755 rm -f "$target"
756 FROM_DISTFILES=0
757 fi
758 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
759 get_files_cvs="$get_files_cvs $fp"
760 continue
761 fi
762
763 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
764 if [ -z "$NOMIRRORS" ]; then
765 im="`find_mirror "$i"`"
766 else
767 im="$i"
768 fi
769 update_shell_title "${GETURI}: $im"
770 ${GETURI} "$im" || \
771 if [ "`echo $im | grep -E 'ftp://'`" ]; then
772 update_shell_title "${GETURI2}: $im"
773 ${GETURI2} "$im"
774 fi
775 fi
776
777 fi
778 srcno=$(src_no $i)
779 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
780 Exit_error err_no_source_in_repo $i;
781 elif [ -n "$UPDATE5" ] && \
782 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
783 [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
784 grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
785 then
786 echo "Updating source-$srcno md5."
787 md5=$(md5sum "$fp" | cut -f1 -d' ')
788 perl -i -ne '
789 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
790 print "# Source'$srcno'-md5:\t'$md5'\n"
791 if /^Source'$srcno'\s*:\s+/;
792 ' \
793 $SPECS_DIR/$SPECFILE
794 fi
795
796 if good_md5 "$i" && good_size "$i"; then
797 :
798 elif [ "$FROM_DISTFILES" = 1 ]; then
799 # wrong md5 from distfiles: remove the file and try again
800 # but only once ...
801 echo "MD5 sum mismatch. Trying full fetch."
802 FROM_DISTFILES=2
803 rm -f $target
804 update_shell_title "${GETURI}: $url"
805 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
806 if [ "`echo $url | grep -E 'ftp://'`" ]; then
807 update_shell_title "${GETURI2}: $url"
808 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
809 fi
810 if ! test -s "$target"; then
811 rm -f "$target"
812 update_shell_title "${GETURI}: $url_attic"
813 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
814 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
815 update_shell_title "${GETURI2}: $url_attic"
816 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
817 fi
818 fi
819 test -s "$target" || rm -f "$target"
820 fi
821
822 if good_md5 "$i" && good_size "$i" ; then
823 :
824 else
825 echo "MD5 sum mismatch or 0 size. Use -U to refetch sources,"
826 echo "or -5 to update md5 sums, if you're sure files are correct."
827 Exit_error err_no_source_in_repo $i
828 fi
829 done
830 SHELL_TITLE_PREFIX=""
831
832 if [ "$get_files_cvs" ]; then
833 cvsup $get_files_cvs
834 fi
835
836 if [ "$CHMOD" = "yes" ]; then
837 CHMOD_FILES="`nourl $GET_FILES`"
838 if [ -n "$CHMOD_FILES" ]; then
839 chmod $CHMOD_MODE $CHMOD_FILES
840 fi
841 fi
842 fi
843}
844
845make_tagver() {
846
847 if [ -n "$DEBUG" ]; then
848 set -x;
849 set -v;
850 fi
851
852 # Check whether first character of PACKAGE_NAME is legal for tag name
853 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
854 TAG_PREFIX=tag_
855 fi
856 TAGVER=$TAG_PREFIX$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
857 # Remove #kernel.version_release from TAGVER because tagging sources
858 # could occur with different kernel-headers than kernel-headers used at build time.
859 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
860 echo -n "$TAGVER"
861}
862
863tag_files()
864{
865 TAG_FILES="$@"
866
867 if [ -n "$DEBUG" ]; then
868 set -x;
869 set -v;
870 fi
871
872 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
873 echo "Version: $PACKAGE_VERSION"
874 echo "Release: $PACKAGE_RELEASE"
875
876 TAGVER=`make_tagver`
877
878 if [ "$TAG_VERSION" = "yes" ]; then
879 echo "CVS tag: $TAGVER"
880 fi
881 if [ -n "$TAG" ]; then
882 echo "CVS tag: $TAG"
883 fi
884
885 OPTIONS="tag -F"
886 if [ -n "$CVSROOT" ]; then
887 OPTIONS="-d $CVSROOT $OPTIONS"
888 fi
889
890 cd "$SOURCE_DIR"
891 for i in $TAG_FILES
892 do
893 # don't tag files stored on distfiles
894 [ -n "`src_md5 $i`" ] && continue
895 if [ -f "`nourl $i`" ]; then
896 if [ "$TAG_VERSION" = "yes" ]; then
897 cvs $OPTIONS $TAGVER `nourl $i`
898 fi
899 if [ -n "$TAG" ]; then
900 cvs $OPTIONS $TAG `nourl $i`
901 fi
902 else
903 Exit_error err_no_source_in_repo $i
904 fi
905 done
906
907 cd "$SPECS_DIR"
908 if [ "$TAG_VERSION" = "yes" ]; then
909 cvs $OPTIONS $TAGVER $SPECFILE
910 fi
911 if [ -n "$TAG" ]; then
912 cvs $OPTIONS $TAG $SPECFILE
913 fi
914
915 unset OPTIONS
916 fi
917}
918
919branch_files()
920{
921 TAG=$1
922 echo "CVS branch tag: $TAG"
923 shift;
924
925 TAG_FILES="$@"
926
927 if [ -n "$DEBUG" ]; then
928 set -x;
929 set -v;
930 fi
931
932 if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
933
934 OPTIONS="tag -b"
935 if [ -n "$CVSROOT" ]; then
936 OPTIONS="-d $CVSROOT $OPTIONS"
937 fi
938 cd "$SOURCE_DIR"
939 for i in $TAG_FILES
940 do
941 if [ -f `nourl $i` ]; then
942 cvs $OPTIONS $TAG `nourl $i`
943 else
944 Exit_error err_no_source_in_repo $i
945 fi
946 done
947 cd "$SPECS_DIR"
948 cvs $OPTIONS $TAG $SPECFILE
949
950 unset OPTIONS
951 fi
952}
953
954
955
956build_package()
957{
958 update_shell_title "build_package"
959 if [ -n "$DEBUG" ]; then
960 set -x;
961 set -v;
962 fi
963
964 cd "$SPECS_DIR"
965
966 if [ -n "$TRY_UPGRADE" ]; then
967 update_shell_title "build_package: try_upgrade"
968 if [ -n "$FLOAT_VERSION" ]; then
969 TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1
970 else
971 TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1
972 fi
973
974 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
975
976 if [ -n "$TNEWVER" ]; then
977 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
978 echo "New version found, updating spec file to version " $TNEWVER
979 cp -f $SPECFILE $SPECFILE.bak
980 chmod +w $SPECFILE
981 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
982 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE"
983 parse_spec;
984 if [ -n "$ICONS" ]; then
985 get_files $ICONS;
986 parse_spec;
987 fi
988 NODIST="yes" UPDATE5="yes" get_files "$SOURCES $PATCHES";
989 unset TOLDVER TNEWVER TNOTIFY
990 fi
991 fi
992 cd "$SPECS_DIR"
993
994 case "$COMMAND" in
995 build )
996 BUILD_SWITCH="-ba" ;;
997 build-binary )
998 BUILD_SWITCH="-bb" ;;
999 build-source )
1000 BUILD_SWITCH="-bs --nodeps" ;;
1001 build-prep )
1002 BUILD_SWITCH="-bp --nodeps" ;;
1003 esac
1004
1005 update_shell_title "build_package: $COMMAND"
1006 if [ -n "$LOGFILE" ]; then
1007 LOG=`eval echo $LOGFILE`
1008 if [ -d "$LOG" ]; then
1009 echo "Log file $LOG is a directory."
1010 echo "Parse error in the spec?"
1011 Exit_error err_build_fail;
1012 fi
1013 if [ -n "$LASTLOG_FILE" ]; then
1014 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1015 fi
1016 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
1017 (time eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
1018 RETVAL=`cat $RES_FILE`
1019 rm $RES_FILE
1020 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1021 if [ "$RETVAL" -eq "0" ]; then
1022 mv $LOG $LOGDIROK
1023 else
1024 mv $LOG $LOGDIRFAIL
1025 fi
1026 fi
1027 else
1028 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE
1029 RETVAL=$?
1030 fi
1031 if [ "$RETVAL" -ne "0" ]; then
1032 if [ -n "$TRY_UPGRADE" ]; then
1033 echo "\n!!! Package with new version cannot be build automagically\n"
1034 mv -f $SPECFILE.bak $SPECFILE
1035 fi
1036 Exit_error err_build_fail;
1037 fi
1038 unset BUILD_SWITCH
1039}
1040
1041nourl()
1042{
1043 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1044}
1045
1046install_required_packages()
1047{
1048 run_poldek -vi $1
1049 return $?
1050}
1051
1052set_bconds_values()
1053{
1054 update_shell_title "set bcond values"
1055
1056 AVAIL_BCONDS_WITHOUT=""
1057 AVAIL_BCONDS_WITH=""
1058 if `grep -q ^%bcond ${SPECFILE}`; then
1059 BCOND_VERSION="NEW"
1060 elif `egrep -q ^#\ *_with ${SPECFILE}`; then
1061 BCOND_VERSION="OLD"
1062 else
1063 BCOND_VERSION="NONE"
1064 fi
1065
1066 # expand bconds from ~/.bcondrc
1067 # The file structure is like gentoo's package.use:
1068 # ---
1069 # * -selinux
1070 # samba -mysql -pgsql
1071 # w32codec-installer license_agreement
1072 # php +mysqli
1073 # ---
1074 if [ "${BCOND_VERSION}" != "NONE" ] && ( [ -f $HOME/.bcondrc ] || ( [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] ) ) ; then
1075 # This takes package name, first defined in spec.
1076 # so consider that when defining flags for package.
1077 PN=`$RPM -q --qf '%{NAME}\n' --specfile $SPECFILE | head -n 1`
1078 SN=${SPECFILE%%\.spec}
1079 AVAIL=`$RPMBUILD --bcond $SPECFILE`
1080
1081 BCONDRC=$HOME/.bcondrc
1082 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && BCONDRC=$HOME_ETC/.bcondrc
1083
1084 while read pkg flags; do
1085 # ignore comments
1086 [[ "$pkg" == \#* ]] && continue
1087
1088 # any package or current package?
1089 if [ "$pkg" = "*" ] || [ "$pkg" = "$PN" ] || [ "$pkg" = "$SN" ]; then
1090 for flag in $flags; do
1091 opt=${flag#[+-]}
1092
1093 # use only flags which are in this package.
1094 if [[ $AVAIL = *${opt}* ]]; then
1095 if [[ $flag = -* ]]; then
1096 BCOND="$BCOND --without $opt"
1097 else
1098 BCOND="$BCOND --with $opt"
1099 fi
1100 fi
1101 done
1102 fi
1103 done < $BCONDRC
1104 fi
1105
1106 case "${BCOND_VERSION}" in
1107 NONE)
1108 :
1109 ;;
1110 OLD)
1111 echo "Warning: This spec has old style bconds. Fix it || die."
1112 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
1113 do
1114 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
1115 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
1116 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1117 else
1118 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1119 fi
1120 done
1121
1122 for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
1123 do
1124 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
1125 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
1126 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1127 else
1128 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1129 fi
1130 done
1131 ;;
1132 NEW)
1133 cond_type="" # with || without
1134 for opt in `$RPMBUILD --bcond $SPECFILE`
1135 do
1136 case "$opt" in
1137 _without)
1138 cond_type="without"
1139 ;;
1140 _with)
1141 cond_type="with"
1142 ;;
1143 _without_*)
1144 AVAIL_BCOND_WITHOUT="`echo $opt | sed 's/^_without_//g'`"
1145 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
1146 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1147 else
1148 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1149 fi
1150 ;;
1151 _with_*)
1152 AVAIL_BCOND_WITH="`echo $opt | sed 's/^_with_//g'`"
1153 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
1154 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1155 else
1156 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1157 fi
1158 ;;
1159 *)
1160 case "$cond_type" in
1161 with)
1162 cond_type=''
1163 AVAIL_BCOND_WITH="$opt"
1164 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
1165 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1166 else
1167 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1168 fi
1169 ;;
1170 without)
1171 cond_type=''
1172 AVAIL_BCOND_WITHOUT="$opt"
1173 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
1174 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1175 else
1176 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1177 fi
1178 ;;
1179 esac
1180 ;;
1181 esac
1182 done
1183 ;;
1184 esac
1185}
1186
1187run_sub_builder()
1188{
1189 package_name="${1}"
1190 update_shell_title "run_sub_builder $package_name"
1191 #
1192