]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
- When NoSourceX-md5 was set, we tried to lookup SourceX in CVS. Don't.
[packages/rpm-build-tools.git] / builder.sh
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
20 #       - tries to get new version from distfiles without new md5
21 #       - after fetching new version doesn't update md5
22 #       - doesn't get sources for specs with %include /usr/lib/rpm/macros.python
23 #         when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway)
24 #       - as above with %include /usr/lib/rpm/macros.perl and no rpm-perlprov
25 #       - when Icon: field is present, -5 and -a5 doesn't work
26
27 VERSION="\
28 Build package utility from PLD CVS repository
29 V 0.12 (C) 1999-2005 Free Penguins".
30 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
31
32 COMMAND="build"
33 TARGET=""
34
35 SPECFILE=""
36 BE_VERBOSE=""
37 QUIET=""
38 CLEAN=""
39 DEBUG=""
40 NOURLS=""
41 NOCVS=""
42 NOCVSSPEC=""
43 NODIST=""
44 UPDATE=""
45 UPDATE5=""
46 ADD5=""
47 NO5=""
48 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
49 CVSROOT=""
50
51 # It can be used i.e. in log file naming.
52 # See LOGFILE example.
53 DATE=`date +%Y-%m-%d_%H-%M-%S`
54
55 # Example: LOGFILE='../log.$PACKAGE_NAME'
56 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
57 # Yes, you can use variable name! Note _single_ quotes!
58 LOGFILE=''
59
60 LOGDIR=""
61 LOGDIROK=""
62 LOGDIRFAIL=""
63 LASTLOG_FILE=""
64
65 CHMOD="no"
66 CHMOD_MODE="0444"
67 RPMOPTS=""
68 BCOND=""
69 GROUP_BCONDS="no"
70 CVSIGNORE_DF="no"
71
72 PATCHES=""
73 SOURCES=""
74 ICONS=""
75 PACKAGE_RELEASE=""
76 PACKAGE_VERSION=""
77 PACKAGE_NAME=""
78 PROTOCOL="ftp"
79 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
80 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
81
82 CVSTAG=""
83 RES_FILE=""
84
85 CVS_SERVER="cvs.pld-linux.org"
86 DISTFILES_SERVER="://distfiles.pld-linux.org"
87 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
88
89 DEF_NICE_LEVEL=19
90
91 FAIL_IF_NO_SOURCES="yes"
92
93 # Here we load saved user environment used to
94 # predefine options set above, or passed to builder
95 # in command line.
96 # This one reads global system environment settings:
97 if [ -f ~/etc/builderrc ]; then
98         . ~/etc/builderrc
99 fi
100 # And this one cascades settings using user personal
101 # builder settings.
102 # Example of ~/.builderrc:
103 #
104 #UPDATE_POLDEK_INDEXES="yes"
105 #FETCH_BUILD_REQUIRES="yes"
106 #REMOVE_BUILD_REQUIRES="force"
107 #GROUP_BCONDS="yes"
108 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
109 #
110 if [ -n "$HOME_ETC" ]; then
111         USER_CFG="$HOME_ETC/.builderrc"
112 else
113         USER_CFG=~/.builderrc
114 fi
115
116 [ -f "$USER_CFG" ] && . "$USER_CFG"
117
118 if [ -n "$USE_PROZILLA" ]; then
119          GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
120          GETURI2="$GETURI"
121          OUTFILEOPT="-O"
122 elif [ -n "$USE_AXEL" ]; then
123          GETURI="axel -n 4 -a $AXEL_OPTS"
124          GETURI2="$GETURI"
125          OUTFILEOPT="-o"
126 else
127          wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
128          wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
129          
130          GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
131          GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
132          OUTFILEOPT="-O"
133 fi
134
135 GETLOCAL="cp -a"
136
137 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
138         RPM="rpm"
139         RPMBUILD="rpm"
140 else
141         RPM="rpm"
142         RPMBUILD="rpmbuild"
143 fi
144
145 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
146 POLDEK_CMD="/usr/bin/poldek --noask"
147
148 run_poldek()
149 {
150         RES_FILE=~/tmp/poldek-exit-status.$RANDOM
151         if [ -n "$LOGFILE" ]; then
152                 LOG=`eval echo $LOGFILE`
153                 if [ -n "$LASTLOG_FILE" ]; then
154                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
155                 fi
156                 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee $LOG
157                 return $exit_pldk
158         else
159                 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
160                 return `cat ${RES_FILE}`
161                 rm -rf ${RES_FILE}
162         fi
163 }
164
165 #---------------------------------------------
166 # functions
167
168 usage()
169 {
170         if [ -n "$DEBUG" ]; then set -xv; fi
171         echo "\
172 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
173
174 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
175 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
176 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
177 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
178 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
179 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
180 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
181 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
182 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
183
184 -5, --update-md5    - update md5 comments in spec, implies -nd -ncs
185 -a5, --add-md5      - add md5 comments to URL sources, implies -nc -nd -ncs
186 -n5, --no-md5       - ignore md5 comments in spec
187 -D, --debug         - enable builder script debugging mode,
188 -debug              - produce rpm debug package (same as --opts -debug)
189 -V, --version       - output builder version
190 -a, --as_anon       - get files via pserver as cvs@$CVS_SERVER,
191 -b, -ba, --build    - get all files from CVS repo or HTTP/FTP and build package
192                       from <package>.spec,
193 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
194                       only package from <package>.spec,
195 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
196                       them into src.rpm,
197 -bp, --build-prep   - execute the %prep phase of <package>.spec,
198 -B, --branch        - add branch
199 -c, --clean         - clean all temporarily created files (in BUILD, SOURCES,
200                       SPECS and \$RPM_BUILD_ROOT),
201 -d <cvsroot>, --cvsroot <cvsroot>
202                     - setup \$CVSROOT,
203 --define <macro> <value>
204                     - define a macro <macro> with value <value>,
205 --nodeps            - rpm won't check any dependences
206 -g, --get           - get <package>.spec and all related files from CVS repo
207                       or HTTP/FTP,
208 -h, --help          - this message,
209 --http              - use http instead of ftp,
210 -l <logfile>, --logtofile <logfile>
211                     - log all to file,
212 -m, --mr-proper     - only remove all files related to spec file and all work
213                       resources,
214 -nc, --no-cvs       - don't download sources from CVS, if source URL is given,
215 -ncs, --no-cvs-specs
216                     - don't check specs in CVS
217 -nd, --no-distfiles - don't download from distfiles
218 -nm, --no-mirrors   - don't download from mirror, if source URL is given,
219 -nu, --no-urls      - don't try to download from FTP/HTTP location,
220 -ns, --no-srcs      - don't download Sources
221 -ns0, --no-source0  - don't download Source0
222 -nn, --no-net       - don't download anything from the net
223 --opts <rpm opts>   - additional options for rpm
224 -q, --quiet         - be quiet,
225 --date yyyy-mm-dd   - build package using resources from specified CVS date,
226 -r <cvstag>, --cvstag <cvstag>
227                     - build package using resources from specified CVS tag,
228 -R, --fetch-build-requires
229                     - fetch what is BuildRequired,
230 -RB, --remove-build-requires
231                     - remove all you fetched with -R or --fetch-build-requires
232                       remember, this option requires confirmation,
233 -FRB, --force-remove-build-requires
234                     - remove all you fetched with -R or --fetch-build-requires
235                       remember, this option works without confirmation,
236 -sf, --source-files - list sources - bare filenames (intended for offline
237                       operations; does not work when Icon field is present
238                                                          but icon file is absent),
239 -sp, --source-paths - list sources - filenames with full local paths (intended for
240                       offline operations; does not work when Icon field is present
241                                                          but icon file is absent),
242 -T <cvstag> , --tag <cvstag>
243                     - add cvs tag <cvstag> for files,
244 -Tvs, --tag-version-stable
245                     - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
246 -Tvn, --tag-version-nest
247                     - add cvs tags NEST and NAME-VERSION-RELEASE for files,
248 -Ts, --tag-stable
249                     - add cvs tag STABLE for files,
250 -Tn, --tag-nest
251                     - add cvs tag NEST for files,
252 -Tv, --tag-version
253                     - add cvs tag NAME-VERSION-RELEASE for files,
254 -Tp, --tag-prefix <prefix>
255                     - add <prefix> to NAME-VERSION-RELEASE tags,
256 -tt, --test-tag <prefix>
257                     - fail if tag is already present,
258 -ir, --integer-release-only
259                     - allow only integer and snapshot releases
260 -v, --verbose       - be verbose,
261 -u, --try-upgrade   - check version, and try to upgrade package
262 -un, --try-upgrade-with-float-version
263                     - as above, but allow float version
264 -U, --update        - refetch sources, don't use distfiles, and update md5 comments
265 -Upi, --update-poldek-indexes
266                     - refresh or make poldek package index files.
267 --with/--without <feature>
268                     - conditional build package depending on %_with_<feature>/
269                       %_without_<feature> macro switch.  You may now use
270                       --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
271                       constructions. Set GROUP_BCONDS to yes to make use of it.
272 --target <platform>, --target=<platform>
273                     - build for platform <platform>.
274 "
275 }
276
277 cache_rpm_dump () {
278          if [ -n "$DEBUG" ]; then
279                   set -x;
280                   set -v;
281          fi
282 rpm_dump_cache=`
283         case "$RPMBUILD" in
284                 rpm )
285                         rpm -bp --nodeps --define 'prep %dump' $BCOND $TARGET_SWITCH $SPECFILE 2>&1
286                         ;;
287                 rpmbuild )
288                         rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
289                         ;;
290         esac`
291 }
292
293 rpm_dump () {
294         if [ -z "$rpm_dump_cache" ] ; then
295                 echo "internal error: cache_rpm_dump not called!" 1>&2
296         fi
297         echo "$rpm_dump_cache"
298 }
299
300 parse_spec()
301 {
302         if [ -n "$DEBUG" ]; then
303                 set -x;
304                 set -v;
305         fi
306
307         cd $SPECS_DIR
308
309         cache_rpm_dump
310
311         if [ "$NOSRCS" != "yes" ]; then
312                 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
313         fi
314         if (rpm_dump | grep -qEi ":.*nosource.*1"); then
315                 FAIL_IF_NO_SOURCES="no"
316         fi
317
318         PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
319         ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
320         PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
321         PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -n 1`"
322         PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`"
323
324 # These variables may be unset after first cache_rpm_dump call
325 # (because of not-yet-retrieved icon file)
326 #
327 #       if [ -z "$PACKAGE_NAME" -o -z "$PACKAGE_VERSION" -o -z "$PACKAGE_RELEASE" ]; then
328 #                Exit_error err_no_package_data;
329 #       fi
330
331         if [ -n "$BE_VERBOSE" ]; then
332                 echo "- Sources :  `nourl $SOURCES`"
333                 if [ -n "$PATCHES" ]; then
334                         echo "- Patches :  `nourl $PATCHES`"
335                 else
336                         echo "- Patches :  *no patches needed*"
337                 fi
338                 if [ -n "$ICONS" ]; then
339                         echo "- Icon    :  `nourl $ICONS`"
340                 else
341                         echo "- Icon    :  *no package icon*"
342                 fi
343                 echo "- Name    : $PACKAGE_NAME"
344                 echo "- Version : $PACKAGE_VERSION"
345                 echo "- Release : $PACKAGE_RELEASE"
346         fi
347 }
348
349 Exit_error()
350 {
351         if [ -n "$DEBUG" ]; then
352                 set -x;
353                 set -v;
354         fi
355
356         cd "$__PWD"
357
358         case "$1" in
359                 "err_no_spec_in_cmdl" )
360                         remove_build_requires
361                         echo "ERROR: spec file name not specified.";
362                         exit 2 ;;
363                 "err_no_spec_in_repo" )
364                         remove_build_requires
365                         echo "Error: spec file not stored in CVS repo.";
366                         exit 3 ;;
367                 "err_no_source_in_repo" )
368                         remove_build_requires
369                         echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
370                         exit 4 ;;
371                 "err_build_fail" )
372                         remove_build_requires
373                         echo "Error: package build failed. (${2:-no more info})";
374                         exit 5 ;;
375                 "err_no_package_data" )
376                         remove_build_requires
377                         echo "Error: couldn't get out package name/version/release from spec file."
378                         exit 6 ;;
379            "err_tag_exists" )
380                         remove_build_requires
381                         echo "Tag ${2} already exists (spec release: ${3}).";
382                         exit 9 ;;
383            "err_fract_rel" )
384                         remove_build_requires
385                         echo "Release ${2} not integer and not a snapshot.";
386                         exit 10 ;;
387
388         esac
389    echo "Unknown error."
390    exit 100
391 }
392
393 init_builder()
394 {
395         if [ -n "$DEBUG" ]; then
396                 set -x;
397                 set -v;
398         fi
399
400         SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
401         SPECS_DIR="`$RPM --eval '%{_specdir}'`"
402
403         __PWD="`pwd`"
404 }
405
406 get_spec()
407 {
408         if [ -n "$DEBUG" ]; then
409                 set -x;
410                 set -v;
411         fi
412
413         cd "$SPECS_DIR"
414         if [ \! -f "$SPECFILE" ]; then
415                 SPECFILE="`basename $SPECFILE .spec`.spec";
416         fi
417         if [ "$NOCVSSPEC" != "yes" ]; then
418                 OPTIONS="up "
419
420                 if [ -n "$CVSROOT" ]; then
421                         OPTIONS="-d $CVSROOT $OPTIONS"
422                 else
423                         if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
424                                 echo "warning: No cvs access defined - using local .spec file"
425                                 NOCVSSPEC="yes"
426                         fi
427                 fi
428
429                 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
430                         OPTIONS="$OPTIONS -A"
431                 else
432                         if [ -n "$CVSDATE" ]; then
433                                 OPTIONS="$OPTIONS -D $CVSDATE"
434                         fi
435                         if [ -n "$CVSTAG" ]; then
436                                 OPTIONS="$OPTIONS -r $CVSTAG"
437                         fi
438                 fi
439
440                 result=1
441                 retries_counter=0
442                 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
443                 do
444                         retries_counter=$(( $retries_counter + 1 ))
445                         output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
446                         result=$?
447                         [ -n "$output" ] && echo "$output"
448                         if [ "$result" -ne "0" ]; then
449                                 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
450                                         echo "Trying again [$SPECFILE]... ($retries_counter)"
451                                         sleep 2
452                                         continue
453                                 fi
454                                 Exit_error err_no_spec_in_repo;
455                         fi
456                 done
457         fi
458         if [ ! -f "$SPECFILE" ]; then
459                 Exit_error err_no_spec_in_repo;
460         fi
461
462         if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
463                 chmod $CHMOD_MODE $SPECFILE
464         fi
465         unset OPTIONS
466         [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
467 }
468
469 find_mirror()
470 {
471         cd "$SPECS_DIR"
472         url="$1"
473         if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
474                 cvs update mirrors >&2
475         fi
476
477         IFS="|"
478         while read origin mirror name rest
479         do
480                 ol=`echo -n "$origin"|wc -c`
481                 prefix="`echo -n "$url" | head -c $ol`"
482                 if [ "$prefix" = "$origin" ] ; then
483                         suffix="`echo "$url"|cut -b $ol-`"
484                         echo -n "$mirror$suffix"
485                         return 0
486                 fi
487         done < mirrors
488         echo "$url"
489 }
490
491 src_no ()
492 {
493         cd $SPECS_DIR
494         rpm_dump | \
495         grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
496         sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
497         head -n 1 | xargs
498 }
499
500 src_md5 ()
501 {
502         [ X"$NO5" = X"yes" ] && return
503         no=$(src_no "$1")
504         [ -z "$no" ] && return
505         cd $SPECS_DIR
506         spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
507         if [ -z "$spec_rev" ]; then
508                 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
509         fi
510         spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
511         md5=$(grep -s -v '^#' additional-md5sums | \
512         grep -E "[      ]$(basename "$1")[      ]+${spec}([     ,]|\$)" | \
513         sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
514         grep -E '^[0-9a-f]{32}$')
515         if [ X"$md5" = X"" ] ; then
516                 grep -i -E "#[  ]*(No)?Source$no-md5[   ]*:" $SPECFILE | sed -e 's/.*://' | xargs
517         else
518                 if [ $(echo "$md5" | wc -l) != 1 ] ; then
519                         echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
520                 fi
521                 echo "$md5" | tail -n 1
522         fi
523 }
524
525 distfiles_url ()
526 {
527         echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
528 }
529
530 distfiles_attic_url ()
531 {
532         echo "$PROTOCOL$ATTICDISTFILES_SERVER/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
533 }
534
535 good_md5 ()
536 {
537         md5=$(src_md5 "$1")
538         [ "$md5" = "" ] || \
539         [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
540 }
541
542 good_size ()
543 {
544          size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
545          [ -n "$size" -a "$size" -gt 0 ]
546 }
547
548 cvsignore_df ()
549 {
550         if [ "$CVSIGNORE_DF" != "yes" ]; then
551                 return
552         fi
553         cvsignore=${SOURCE_DIR}/.cvsignore
554         if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
555                 echo "$1" >> $cvsignore
556         fi
557 }
558
559 get_files()
560 {
561         GET_FILES="$@"
562
563         if [ -n "$DEBUG" ]; then
564                 set -x;
565                 set -v;
566         fi
567
568         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
569                 cd "$SOURCE_DIR"
570
571                 OPTIONS="up "
572                 if [ -n "$CVSROOT" ]; then
573                         OPTIONS="-d $CVSROOT $OPTIONS"
574                 else
575                         if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
576                                 echo "warning: No cvs access defined for SOURCES"
577                                 NOCVS="yes"
578                         fi
579                 fi
580                 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
581                         OPTIONS="$OPTIONS -A"
582                 else
583                         if [ -n "$CVSDATE" ]; then
584                                 OPTIONS="$OPTIONS -D $CVSDATE"
585                         fi
586                         if [ -n "$CVSTAG" ]; then
587                                 OPTIONS="$OPTIONS -r $CVSTAG"
588                         fi
589                 fi
590                 for i in $GET_FILES
591                 do
592                         if [ -n "$UPDATE5" ]; then
593                                 if [ -n "$ADD5" ]; then
594                                         [ `nourl $i` = "$i" ] && continue
595                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE && continue
596                                 else
597                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE || continue
598                                 fi
599                         fi
600                         FROM_DISTFILES=0
601                         if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
602                                 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
603                                         echo "Warning: no URL given for $i"
604                                 fi
605
606                                 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
607                                         if good_md5 "$i" && good_size "$i"; then
608                                                 echo "$(nourl "$i") having proper md5sum already exists"
609                                                 continue
610                                         fi
611                                         target=$(nourl "$i")
612                                         url=$(distfiles_url "$i")
613                                         url_attic=$(distfiles_attic_url "$i")
614                                         FROM_DISTFILES=1
615                                         if [ `echo $url | grep -E '^(\.|/)'` ]; then
616                                                 ${GETLOCAL} $url $target
617                                         else
618                                                 if [ -z "$NOMIRRORS" ]; then
619                                                         url="`find_mirror "$url"`"
620                                                 fi
621                                                 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
622                                                 if [ `echo $url | grep -E 'ftp://'` ]; then
623                                                         ${GETURI2} ${OUTFILEOPT} "$target" "$url"
624                                                 fi
625                                         fi
626                                         if ! test -s "$target"; then
627                                                 rm -f "$target"
628                                                 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
629                                                         ${GETLOCAL} $url_attic $target
630                                                 else
631                                                         if [ -z "$NOMIRRORS" ]; then
632                                                                 url_attic="`find_mirror "$url_attic"`"
633                                                         fi
634                                                         ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
635                                                         if [ `echo $url_attic | grep -E 'ftp://'` ]; then
636                                                                 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
637                                                         fi
638                                                 fi
639                                         fi
640                                         if test -s "$target"; then
641                                                 cvsignore_df $target
642                                         else
643                                                 rm -f "$target"
644                                                 FROM_DISTFILES=0
645                                         fi
646                                 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
647                                         # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
648                                         result=1
649                                         retries_counter=0
650                                         while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
651                                         do
652                                                 retries_counter=$(( $retries_counter + 1 ))
653                                                 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
654                                                 result=$?
655                                                 [ -n "$output" ] && echo "$output"
656                                                 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
657                                                         echo "Trying again [`nourl $i`]... ($retries_counter)"
658                                                         sleep 2
659                                                         continue
660                                                 else
661                                                         break
662                                                 fi
663                                         done
664                                 fi
665
666                                 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
667                                         if [ -z "$NOMIRRORS" ]; then
668                                                 im="`find_mirror "$i"`"
669                                         else
670                                                 im="$i"
671                                         fi
672                                         ${GETURI} "$im" || \
673                                         if [ `echo $im | grep -E 'ftp://'` ]; then
674                                                 ${GETURI2} "$im"
675                                         fi
676                                 fi
677
678                         fi
679                         srcno=$(src_no $i)
680                         if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
681                                 Exit_error err_no_source_in_repo $i;
682                         elif [ -n "$UPDATE5" ] && \
683                                 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
684                                 [ -z "$(grep -E -i '^NoSource[  ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
685                                 grep -q -i -E '^#[      ]*source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE )
686                         then
687                                 echo "Updating source-$srcno md5."
688                                 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
689                                 perl -i -ne '
690                                 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
691                                 print "# Source'$srcno'-md5:\t'$md5'\n"
692                                 if /^Source'$srcno'\s*:\s+/;
693                                 ' \
694                                 $SPECS_DIR/$SPECFILE
695                         fi
696
697                         if good_md5 "$i" && good_size "$i"; then
698                                 :
699                         elif [ "$FROM_DISTFILES" = 1 ]; then
700                                 # wrong md5 from distfiles: remove the file and try again
701                                 # but only once ...
702                                 echo "MD5 sum mismatch. Trying full fetch."
703                                 FROM_DISTFILES=2
704                                 rm -f $target
705                                 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
706                                 if [ `echo $url | grep -E 'ftp://'` ]; then
707                                         ${GETURI2} ${OUTFILEOPT} "$target" "$url"
708                                 fi
709                                 if ! test -s "$target"; then
710                                         rm -f "$target"
711                                         ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
712                                         if [ `echo $url_attic | grep -E 'ftp://'` ]; then
713                                                 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
714                                         fi
715                                 fi
716                                 test -s "$target" || rm -f "$target"
717                         fi
718
719                         if good_md5 "$i" && good_size "$i" ; then
720                                 :
721                         else
722                                 echo "MD5 sum mismatch or 0 size.  Use -U to refetch sources,"
723                                 echo "or -5 to update md5 sums, if you're sure files are correct."
724                                 Exit_error err_no_source_in_repo $i
725                         fi
726                 done
727
728                 if [ "$CHMOD" = "yes" ]; then
729                         CHMOD_FILES="`nourl $GET_FILES`"
730                         if [ -n "$CHMOD_FILES" ]; then
731                                 chmod $CHMOD_MODE $CHMOD_FILES
732                         fi
733                 fi
734                 unset OPTIONS
735         fi
736 }
737
738 make_tagver() {
739
740                 if [ -n "$DEBUG" ]; then
741                          set -x;
742                          set -v;
743                 fi
744
745                 # Check whether first character of PACKAGE_NAME is legal for tag name
746                 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
747                         TAG_PREFIX=tag_
748                 fi
749                 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"`
750                 # Remove #kernel.version_release from TAGVER because tagging sources
751                 # could occur with different kernel-headers than kernel-headers used at build time.
752                 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
753                 echo -n "$TAGVER"
754 }
755
756 tag_files()
757 {
758         TAG_FILES="$@"
759
760         if [ -n "$DEBUG" ]; then
761                 set -x;
762                 set -v;
763         fi
764
765         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
766                 echo "Version: $PACKAGE_VERSION"
767                 echo "Release: $PACKAGE_RELEASE"
768
769                 TAGVER=`make_tagver`
770
771                 if [ "$TAG_VERSION" = "yes" ]; then
772                         echo "CVS tag: $TAGVER"
773                 fi
774                 if [ -n "$TAG" ]; then
775                         echo "CVS tag: $TAG"
776                 fi
777
778                 OPTIONS="tag -F"
779                 if [ -n "$CVSROOT" ]; then
780                         OPTIONS="-d $CVSROOT $OPTIONS"
781                 fi
782
783                 cd "$SOURCE_DIR"
784                 for i in $TAG_FILES
785                 do
786                         # don't tag files stored on distfiles
787                         [ -n "`src_md5 $i`" ] && continue
788                         if [ -f "`nourl $i`" ]; then
789                                 if [ "$TAG_VERSION" = "yes" ]; then
790                                         cvs $OPTIONS $TAGVER `nourl $i`
791                                 fi
792                                 if [ -n "$TAG" ]; then
793                                         cvs $OPTIONS $TAG `nourl $i`
794                                 fi
795                         else
796                                 Exit_error err_no_source_in_repo $i
797                         fi
798                 done
799
800                 cd "$SPECS_DIR"
801                 if [ "$TAG_VERSION" = "yes" ]; then
802                         cvs $OPTIONS $TAGVER $SPECFILE
803                 fi
804                 if [ -n "$TAG" ]; then
805                         cvs $OPTIONS $TAG $SPECFILE
806                 fi
807
808                 unset OPTIONS
809         fi
810 }
811
812 branch_files()
813 {
814         TAG=$1
815         echo "CVS branch tag: $TAG"
816         shift;
817
818         TAG_FILES="$@"
819
820         if [ -n "$DEBUG" ]; then
821                 set -x;
822                 set -v;
823         fi
824
825         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
826
827                 OPTIONS="tag -b"
828                 if [ -n "$CVSROOT" ]; then
829                         OPTIONS="-d $CVSROOT $OPTIONS"
830                 fi
831                 cd "$SOURCE_DIR"
832                 for i in $TAG_FILES
833                 do
834                         if [ -f `nourl $i` ]; then
835                                 cvs $OPTIONS $TAG `nourl $i`
836                         else
837                                 Exit_error err_no_source_in_repo $i
838                         fi
839                 done
840                 cd "$SPECS_DIR"
841                 cvs $OPTIONS $TAG $SPECFILE
842
843                 unset OPTIONS
844         fi
845 }
846
847
848
849 build_package()
850 {
851         if [ -n "$DEBUG" ]; then
852                 set -x;
853                 set -v;
854         fi
855
856         cd "$SPECS_DIR"
857
858         if [ -n "$TRY_UPGRADE" ]; then
859                 if [ -n "$FLOAT_VERSION" ]; then
860                         TNOTIFY=`./pldnotify.awk $SPECFILE -n`
861                 else
862                         TNOTIFY=`./pldnotify.awk $SPECFILE`
863                 fi
864
865                 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
866
867                 if [ -n "$TNEWVER" ]; then
868                         TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
869                         echo "New version found, updating spec file to version " $TNEWVER
870                         cp -f $SPECFILE $SPECFILE.bak
871                         chmod +w $SPECFILE
872                         eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
873                         eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
874                         parse_spec;
875                         if [ -n "$ICONS" ]; then
876                                 get_files $ICONS;
877                                 parse_spec;
878                         fi
879                         get_files "$SOURCES $PATCHES";
880                         unset TOLDVER TNEWVER TNOTIFY
881                 fi
882         fi
883         cd "$SPECS_DIR"
884
885         case "$COMMAND" in
886                 build )
887                         BUILD_SWITCH="-ba" ;;
888                 build-binary )
889                         BUILD_SWITCH="-bb" ;;
890                 build-source )
891                         BUILD_SWITCH="-bs --nodeps" ;;
892                 build-prep )
893                         BUILD_SWITCH="-bp --nodeps" ;;
894         esac
895         if [ -n "$LOGFILE" ]; then
896                 LOG=`eval echo $LOGFILE`
897                 if [ -d "$LOG" ]; then
898                         echo "Log file $LOG is a directory."
899                         echo "Parse error in the spec?"
900                         Exit_error err_build_fail;
901                 fi
902                 if [ -n "$LASTLOG_FILE" ]; then
903                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
904                 fi
905                 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
906                 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
907                 RETVAL=`cat $RES_FILE`
908                 rm $RES_FILE
909                 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
910                         if [ "$RETVAL" -eq "0" ]; then
911                                 mv $LOG $LOGDIROK
912                         else
913                                 mv $LOG $LOGDIRFAIL
914                         fi
915                 fi
916         else
917                 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE
918                 RETVAL=$?
919         fi
920         if [ "$RETVAL" -ne "0" ]; then
921                 if [ -n "$TRY_UPGRADE" ]; then
922                         echo "\n!!! Package with new version cannot be build automagically\n"
923                         mv -f $SPECFILE.bak $SPECFILE
924                 fi
925                 Exit_error err_build_fail;
926         fi
927         unset BUILD_SWITCH
928 }
929
930 nourl()
931 {
932         echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
933 }
934
935 install_required_packages()
936 {
937         run_poldek -vi $1
938         return $?
939 }
940
941 set_bconds_values()
942 {
943         AVAIL_BCONDS_WITHOUT=""
944         AVAIL_BCONDS_WITH=""
945         if `grep -q ^%bcond ${SPECFILE}`; then
946                 BCOND_VERSION="NEW"
947         elif `egrep -q ^#\ *_with ${SPECFILE}`; then
948                 BCOND_VERSION="OLD"
949         else
950                 BCOND_VERSION="NONE"
951         fi
952
953         # expand bconds from ~/.bcondrc
954         # The file structure is like gentoo's package.use:
955         # ---
956         # * -selinux
957         # samba -mysql -pgsql
958         # w32codec license_agreement
959         # php +mysqli
960         # ---
961         if [ "${BCOND_VERSION}" != "NONE" ] && ( [ -f $HOME/.bcondrc ] || ( [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] ) ) ; then
962                 # This takes package name, first defined in spec.
963                 # so consider that when defining flags for package.
964                 PN=`$RPM -q --qf '%{NAME}\n' --specfile $SPECFILE | head -n 1`
965                 AVAIL=`$RPMBUILD --bcond $SPECFILE`
966
967                 BCONDRC=$HOME/.bcondrc
968                 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && BCONDRC=$HOME_ETC/.bcondrc
969
970                 while read pkg flags; do
971                         # ignore comments
972                         [[ "$pkg" == \#* ]] && continue
973
974                         # any package or current package?
975                         if [ "$pkg" = "*" ] || [ "$pkg" = "$PN" ]; then
976                                 for flag in $flags; do
977                                         opt=${flag#[+-]}
978
979                                         # use only flags which are in this package.
980                                         if [[ $AVAIL = *${opt}* ]]; then
981                                                 if [[ $flag = -* ]]; then
982                                                         BCOND="$BCOND --without $opt"
983                                                 else
984                                                         BCOND="$BCOND --with $opt"
985                                                 fi
986                                         fi
987                                 done
988                         fi
989                 done < $BCONDRC
990         fi
991
992         case "${BCOND_VERSION}" in
993                  NONE)
994                         :
995                         ;;
996                  OLD)
997                         echo "Warning: This spec has old style bconds. Fix it || die."
998                         for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
999                         do
1000                                 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
1001                                 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
1002                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1003                                 else
1004                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1005                                 fi
1006                         done
1007
1008                         for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
1009                         do
1010                                 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
1011                                 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
1012                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1013                                 else
1014                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1015                                 fi
1016                         done
1017                         ;;
1018                 NEW)
1019                         cond_type="" # with || without
1020                         for opt in `$RPMBUILD --bcond $SPECFILE`
1021                         do
1022                                 case "$opt" in
1023                                         _without)
1024                                                 cond_type="without"
1025                                                 ;;
1026                                         _with)
1027                                                 cond_type="with"
1028                                                 ;;
1029                                         *)
1030                                                 case "$cond_type" in
1031                                                         with)
1032                                                                 cond_type=''
1033                                                                 AVAIL_BCOND_WITH="$opt"
1034                                                                 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
1035                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1036                                                                 else
1037                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1038                                                                 fi
1039                                                                 ;;
1040                                                         without)
1041                                                                 cond_type=''
1042                                                                 AVAIL_BCOND_WITHOUT="$opt"
1043                                                                 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
1044                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1045                                                                 else
1046                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1047                                                                 fi
1048                                                                 ;;
1049                                                 esac
1050                                                 ;;
1051                                 esac
1052                         done
1053                         ;;
1054         esac
1055 }
1056
1057 run_sub_builder()
1058 {
1059         package_name="${1}"
1060         echo -ne "Package installation failed:\t$package_name\n"
1061         #
1062         # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1063         # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1064         # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1065         # jakby nie bylo tego kawalka kodu.
1066         #
1067         # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1068         #         Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1069         #
1070         #
1071         # y0shi.
1072
1073         parent_spec_name=''
1074
1075         # Istnieje taki spec? ${package}.spec
1076         if [ -f "${SPECS_DIR}${package}.spec" ]; then
1077                 parent_spec_name=${package}.spec
1078         elif [ -f "${SPECS_DIR}`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
1079                 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
1080         else
1081                 for provides_line in `grep ^Provides:.*$package  ${SPECS_DIR} -R`
1082                 do
1083                         echo $provides_line
1084                 done
1085         fi
1086
1087         if [ "${parent_spec_name}" != "" ]; then
1088                 sub_builder_opts=''
1089                 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
1090                         sub_builder_opts="${sub_builder_opts} -R"
1091                 fi
1092                 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
1093                         sub_builder_opts="${sub_builder_opts} -RB"
1094                 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
1095                         sub_builder_opts="${sub_builder_opts} -FRB"
1096                 fi
1097                 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
1098                         sub_builder_opts="${sub_builder_opts} -Upi"
1099                 fi
1100                 cd "${SPECS_DIR}"
1101                 ./builder ${sub_builder_opts} ${parent_spec_name}
1102         fi
1103         NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1104 }
1105
1106 remove_build_requires()
1107 {
1108         if [ "$INSTALLED_PACKAGES" != "" ]; then
1109                 case "$REMOVE_BUILD_REQUIRES" in
1110                         "force")
1111                                 run_poldek --noask -ve $INSTALLED_PACKAGES
1112                                 ;;
1113                         "nice")
1114                                 run_poldek --ask -ve $INSTALLED_PACKAGES
1115                                 ;;
1116                         *)
1117                                 echo You may want to manually remove following BuildRequires fetched:
1118                                 echo $INSTALLED_PACKAGES
1119                                 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1120                                 ;;
1121                 esac
1122         fi
1123 }
1124
1125 display_bconds()
1126 {
1127         if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1128                 if [ "$BCOND" != "" ]; then
1129                         echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
1130                         echo -ne "$BCOND"
1131                 else
1132                         echo -ne "\nNo conditional flags passed"
1133                 fi
1134                 echo -ne "\n\nfrom available:\n"
1135                 echo -ne "--with   :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1136         fi
1137 }
1138
1139 fetch_build_requires()
1140 {
1141         if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1142                 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1143                          CONF=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print "@" $3 } ' | xargs)
1144                          DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print "@" $3 } ' | xargs)
1145                          if [ -n "$CONF" -o -n "$DEPS" ]; then
1146                                   /usr/bin/poldek --update; /usr/bin/poldek --upa
1147                          fi
1148                          if [ -n "$CONF" ]; then
1149                                   echo "Trying to uninstall conflicting packages ($CONF):"
1150                                   /usr/bin/poldek --noask --nofollow -ev $CONF
1151                          fi
1152                          if [ -n "$DEPS" ]; then
1153                                   echo "Trying to install dependencies ($DEPS):"
1154                                   /usr/bin/poldek --caplookup -uGv $DEPS
1155                          fi
1156                          return
1157                 fi
1158
1159                 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1160                 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1161                 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1162                 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1163                 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1164                 for package_item in `cat $SPECFILE|grep -B100000 ^%changelog|grep -v ^#|grep BuildRequires|grep -v ^-|sed -e "s/^.*BuildRequires://g"|awk '{print $1}'|sed -e s,perl\(,perl-,g -e s,::,-,g -e s,\(.*\),,g -e s,%{,,g -e s,},,g|grep -v OpenGL-devel|sed -e s,sh-utils,coreutils,g -e s,fileutils,coreutils,g -e s,textutils,coreutils,g -e s,kgcc_package,gcc,g -e s,\),,g`
1165                 do
1166                         package_item="`echo $package_item|sed -e s,rpmbuild,rpm-build,g |sed -e s,__perl,perl,g |sed -e s,gasp,binutils-gasp,g -e s,binutils-binutils,binutils,g -e s,apxs,apache,g|sed -e s,apache\(EAPI\)-devel,apache-devel,g -e s,kernel-headers\(netfilter\),kernel-headers,g -e s,awk,mawk,g -e s,mmawk,mawk,g -e s,motif,openmotif,g -e s,openopenmotif,openmotif,g`"
1167                         GO="yes"
1168                         package=`basename "$package_item"|sed -e "s/}$//g"`
1169                         COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1170                         mach=`uname -m`
1171
1172                         COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1173                         if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1174                                 if [ "$COND_ARCH_TST" != "" ] && [ "`echo $COND_ARCH_TST|sed -e "s/i.86/ix86/g"`" != "`echo $mach|sed -e "s/i.86/ix86/g"`" ]; then
1175                                         GO="yes"
1176                                 fi
1177                         # bcond:
1178                         else
1179                                 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1180                                 GO=""
1181                                 # %{without}
1182                                 if `echo $COND_TST|grep -q 'without_'`; then
1183                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
1184                                         if `echo $COND_TST|grep -q !`; then
1185                                                 COND_STATE="with"
1186                                         else
1187                                                 COND_STATE="wout"
1188                                         fi
1189                                         if `echo $AVAIL_BCONDS_WITHOUT|grep -q "<$COND_NAME>"`; then
1190                                                 COND_ARGV="wout"
1191                                         else
1192                                                 COND_ARGV="with"
1193                                         fi
1194                                 # %{with}
1195                                 elif `echo $COND_TST|grep -q 'with_'`; then
1196                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
1197                                         if `echo $COND_TST|grep -q !`; then
1198                                                 COND_STATE="wout"
1199                                         else
1200                                                 COND_STATE="with"
1201                                         fi
1202                                         if `echo $AVAIL_BCONDS_WITH|grep -q "<$COND_NAME>"`; then
1203                                                 COND_ARGV="with"
1204                                         else
1205                                                 COND_ARGV="wout"
1206                                         fi
1207                                 fi
1208                                 RESULT="${COND_STATE}-${COND_ARGV}"
1209                                 case "$RESULT" in
1210                                         "with-wout" | "wout-with" )
1211                                                 GO=""
1212                                                 ;;
1213                                         "wout-wout" | "with-with" )
1214                                                 GO="yes"
1215                                                 ;;
1216                                         * )
1217                                                 echo "Action '$RESULT' was not defined for package '$package_item'"
1218                                                 GO="yes"
1219                                                 ;;
1220                                 esac
1221                         fi
1222
1223                         if [ "$GO" = "yes" ]; then
1224                                 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1225                                         echo "Testing if $package has subrequirements..."
1226                                         run_poldek -t -i $package --dumpn=".$package-req.txt"
1227                                         if [ -f ".$package-req.txt" ]; then
1228                                                 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1229                                                 do
1230                                                         if [ "$package_name" = "$package" ]; then
1231                                                                 echo -ne "Installing BuildRequired package:\t$package_name\n"
1232                                                                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1233                                                                 install_required_packages $package;
1234                                                         else
1235                                                                 echo -ne "Installing (sub)Required package:\t$package_name\n"
1236                                                                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1237                                                                 install_required_packages $package_name;
1238                                                         fi
1239                                                         case $? in
1240                                                                 0)
1241                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1242                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1243                                                                         ;;
1244                                                                 *)
1245                                                                         echo "Attempting to run spawn sub - builder..."
1246                                                                         run_sub_builder $package_name
1247                                                                         if [ $? -eq 0 ]; then
1248                                                                                 install_required_packages $package_name;
1249                                                                                 case $? in
1250                                                                                         0)
1251                                                                                                 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1252                                                                                                 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1253                                                                                                 ;;
1254                                                                                         *)
1255                                                                                                 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1256                                                                                                 ;;
1257                                                                                 esac
1258                                                                         fi
1259                                                                         ;;
1260                                                         esac
1261                                                 done
1262                                                 rm -f ".$package-req.txt"
1263                                         else
1264                                                 echo "Attempting to run spawn sub - builder..."
1265                                                 run_sub_builder $package
1266                                                 if [ $? -eq 0 ]; then
1267                                                         install_required_packages $package;
1268                                                         case $? in
1269                                                                 0)
1270                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1271                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1272                                                                         ;;
1273                                                                 *)
1274                                                                         NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1275                                                                         ;;
1276                                                         esac
1277                                                 fi
1278                                         fi
1279                                 else
1280                                         echo "Package $package is already installed. BuildRequirement satisfied."
1281                                 fi
1282                         fi
1283                 done
1284                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1285                 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1286                         echo "Unable to install following packages and their dependencies:"
1287                         for pkg in "$NOT_INSTALLED_PACKAGES"
1288                         do
1289                                 echo $pkg
1290                         done
1291                         remove_build_requires
1292                         exit 8
1293                 fi
1294         fi
1295 }
1296
1297 #---------------------------------------------
1298 # main()
1299
1300 if [ "$#" = 0 ]; then
1301         usage;
1302         exit 1
1303 fi
1304
1305 while test $# -gt 0
1306 do
1307         case "${1}" in
1308                 -5 | --update-md5 )
1309                         COMMAND="get";
1310                         NODIST="yes"
1311                         NOCVSSPEC="yes"
1312                         UPDATE5="yes"
1313                         shift ;;
1314                 -a5 | --add-md5 )
1315                         COMMAND="get";
1316                         NODIST="yes"
1317                         NOCVS="yes"
1318                         NOCVSSPEC="yes"
1319                         UPDATE5="yes"
1320                         ADD5="yes"
1321                         shift ;;
1322                 -n5 | --no-md5 )
1323                         NO5="yes"
1324                         shift ;;
1325                 -D | --debug )
1326                         DEBUG="yes"; shift ;;
1327                 -V | --version )
1328                         COMMAND="version"; shift ;;
1329                 -a | --as_anon )
1330                         CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1331                 -b | -ba | --build )
1332                         COMMAND="build"; shift ;;
1333                 -bb | --build-binary )
1334                         COMMAND="build-binary"; shift ;;
1335                 -bs | --build-source )
1336                         COMMAND="build-source"; shift ;;
1337                 -bp | --build-prep )
1338                         COMMAND="build-prep"; shift ;;
1339                 -B | --branch )
1340                         COMMAND="branch"; shift; TAG="${1}"; shift;;
1341                 -c | --clean )
1342                         CLEAN="--clean --rmspec --rmsource"; shift ;;
1343                 -d | --cvsroot )
1344                         shift; CVSROOT="${1}"; shift ;;
1345                 -g | --get )
1346                         COMMAND="get"; shift ;;
1347                 -h | --help )
1348                         COMMAND="usage"; shift ;;
1349                 --http )
1350                         PROTOCOL="http"; shift ;;
1351                 -l | --logtofile )
1352                         shift; LOGFILE="${1}"; shift ;;
1353                 -ni| --nice )
1354                         shift; DEF_NICE_LEVEL=${1}; shift ;;
1355                 -m | --mr-proper )
1356                         COMMAND="mr-proper"; shift ;;
1357                 -nc | --no-cvs )
1358                         NOCVS="yes"; shift ;;
1359                 -ncs | --no-cvs-specs )
1360                         NOCVSSPEC="yes"; shift ;;
1361                 -nd | --no-distfiles )
1362                         NODIST="yes"; shift ;;
1363                 -nm | --no-mirrors )
1364                         NOMIRRORS="yes"; shift ;;
1365                 -nu | --no-urls )
1366                         NOURLS="yes"; shift ;;
1367                 -ns | --no-srcs )
1368                         NOSRCS="yes"; shift ;;
1369                 -ns0 | --no-source0 )
1370                         NOSOURCE0="yes"; shift ;;
1371                 -nn | --no-net )
1372                         NOCVS="yes"
1373                         NOCVSSPEC="yes"
1374                         NODIST="yes"
1375                         NOMIRRORS="yes"
1376                         NOURLS="yes"
1377                         NOSRCS="yes"
1378                         shift;;
1379                 --opts )
1380                         shift; RPMOPTS="$RPM_OPTS ${1}"; shift ;;
1381                 --with | --without )
1382                         case $GROUP_BCONDS in
1383                                 "yes")
1384                                         COND=${1}
1385                                         shift
1386                                         while ! `echo ${1}|grep -qE '(^-|spec)'`
1387                                         do
1388                                                 BCOND="$BCOND $COND $1"
1389                                                 shift
1390                                         done;;
1391                                 "no")
1392                                         BCOND="$BCOND $1 $2" ; shift 2 ;;
1393                         esac
1394                         ;;
1395                 --target )
1396                         shift; TARGET="${1}"; shift ;;
1397                 --target=* )
1398                         TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
1399                 -q | --quiet )
1400                         QUIET="--quiet"; shift ;;
1401                 --date )
1402                         CVSDATE="${2}"; shift 2 ;;
1403                 -r | --cvstag )
1404                         shift; CVSTAG="${1}"; shift ;;
1405                 -R | --fetch-build-requires)
1406                         FETCH_BUILD_REQUIRES="yes"
1407                         NOT_INSTALLED_PACKAGES=
1408                         shift ;;
1409                 -RB | --remove-build-requires)
1410                         REMOVE_BUILD_REQUIRES="nice"
1411                         shift ;;
1412                 -FRB | --force-remove-build-requires)
1413                         REMOVE_BUILD_REQUIRES="force"
1414                         shift ;;
1415                 -sf | --sources-files)
1416                         COMMAND="list-sources-files"
1417                         shift ;;        
1418                 -sp | --sources-paths)
1419                         COMMAND="list-sources-local-paths"
1420                         shift ;;        
1421                 -Tvs | --tag-version-stable )
1422                         COMMAND="tag";
1423                         TAG="STABLE"
1424                         TAG_VERSION="yes"
1425                         shift;;
1426                 -Tvn | --tag-version-nest )
1427                         COMMAND="tag";
1428                         TAG="NEST"
1429                         TAG_VERSION="yes"
1430                         shift;;
1431                 -Ts | --tag-stable )
1432                         COMMAND="tag";
1433                         TAG="STABLE"
1434                         TAG_VERSION="no"
1435                         shift;;
1436                 -Tn | --tag-nest )
1437                         COMMAND="tag";
1438                         TAG="NEST"
1439                         TAG_VERSION="no"
1440                         shift;;
1441                 -Tv | --tag-version )
1442                         COMMAND="tag";
1443                         TAG=""
1444                         TAG_VERSION="yes"
1445                         shift;;
1446                 -Tp | --tag-prefix )
1447                         TAG_PREFIX="$2"
1448                         shift 2;;
1449                 -tt | --test-tag )
1450                         TEST_TAG="yes"
1451                         shift;;
1452                 -T | --tag )
1453                         COMMAND="tag";
1454                         shift
1455                         TAG="$1"
1456                         TAG_VERSION="no"
1457                         shift;;
1458                 -ir | --integer-release-only )
1459                         INTEGER_RELEASE="yes"
1460                         shift;;
1461                 -U | --update )
1462                         COMMAND="get"
1463                         UPDATE="yes"
1464                         NOCVSSPEC="yes"
1465                         NODIST="yes"
1466                         UPDATE5="yes"
1467                         shift ;;
1468                 -Upi | --update-poldek-indexes )
1469                         UPDATE_POLDEK_INDEXES="yes"
1470                         shift ;;
1471                 -u | --try-upgrade )
1472                         TRY_UPGRADE="1"; shift ;;
1473                 -un | --try-upgrade-with-float-version )
1474                         TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1475                 -v | --verbose )
1476                         BE_VERBOSE="1"; shift ;;
1477                 --define)
1478                         shift
1479                         MACRO="${1}"
1480                         VALUE="${2}"
1481                         shift 2
1482                         RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1483                         ;;
1484                 --nodeps)
1485                         shift
1486                         RPMOPTS="${RPMOPTS} --nodeps"
1487                         ;;
1488                 -debug)
1489                         RPMOPTS="${RPMOPTS} -debug"; shift ;;
1490                 * )
1491                         SPECFILE="${1}"
1492                         export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1493                         shift ;;
1494         esac
1495 done
1496
1497 if [ -n "$DEBUG" ]; then
1498         set -x;
1499         set -v;
1500 fi
1501
1502 if [ -n "$TARGET" ]; then
1503         case "$RPMBUILD" in
1504                 "rpmbuild")
1505                         TARGET_SWITCH="--target $TARGET" ;;
1506                 "rpm")
1507                         TARGET_SWITCH="--target=$TARGET" ;;
1508         esac
1509 fi
1510
1511 case "$COMMAND" in
1512         "build" | "build-binary" | "build-source" | "build-prep" )
1513                 init_builder;
1514                 if [ -n "$SPECFILE" ]; then
1515                         get_spec;
1516                         set_bconds_values;
1517                         display_bconds;
1518                         fetch_build_requires;
1519                         parse_spec;
1520                         if [ "$INTEGER_RELEASE" = "yes" ]; then
1521                                 echo "Checking release $PACKAGE_RELEASE..."
1522                                 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
1523                                         Exit_error err_fract_rel "$PACKAGE_RELEASE"
1524                                 fi
1525                         fi
1526
1527                         if [ -n "$TEST_TAG" ]; then
1528                                 TAGVER=`make_tagver`
1529                                 echo "Searching for tag $TAGVER..."
1530                                 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1531                                 if [ -n "$TAGREL" ]; then
1532                                         Exit_error err_tag_exists "$TAGVER" "$TAGREL"
1533                                 fi
1534                         fi
1535
1536                         if [ -n "$ICONS" ]; then
1537                                 get_files $ICONS;
1538                                 parse_spec;
1539                         fi
1540                         if [ -n "$NOSOURCE0" ] ; then
1541                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1542                         fi
1543                         get_files "$SOURCES $PATCHES";
1544                         build_package;
1545                         if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
1546                                 run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
1547                         fi
1548                         remove_build_requires;
1549                 else
1550                         Exit_error err_no_spec_in_cmdl;
1551                 fi
1552                 ;;
1553         "branch" )
1554                 init_builder;
1555                 if [ -n "$SPECFILE" ]; then
1556                         get_spec;
1557                         parse_spec;
1558                         if [ -n "$ICONS" ]; then
1559                                 get_files $ICONS
1560                                 parse_spec;
1561                         fi
1562                         get_files $SOURCES $PATCHES;
1563                         branch_files $TAG "$SOURCES $PATCHES $ICONS";
1564                 else
1565                         Exit_error err_no_spec_in_cmdl;
1566                 fi
1567                 ;;
1568         "get" )
1569                 init_builder;
1570                 if [ -n "$SPECFILE" ]; then
1571                         get_spec;
1572                         parse_spec;
1573                         if [ -n "$ICONS" ]; then
1574                                 OLD_UPDATE5=$UPDATE5
1575                                 UPDATE5= get_files $ICONS
1576                                 UPDATE5=$OLD_UPDATE5
1577                                 parse_spec;
1578                         fi
1579                         if [ -n "$NOSOURCE0" ] ; then
1580                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1581                         fi
1582                         get_files $SOURCES $PATCHES
1583                 else
1584                         Exit_error err_no_spec_in_cmdl;
1585                 fi
1586                 ;;
1587         "tag" )
1588                 NOURLS=1
1589                 NODIST=1
1590                 init_builder;
1591                 if [ -n "$SPECFILE" ]; then
1592                         get_spec;
1593                         parse_spec;
1594                         if [ -n "$ICONS" ]; then
1595                                 get_files $ICONS
1596                                 parse_spec;
1597                         fi
1598                         # don't fetch sources from remote locations
1599                         new_SOURCES=""
1600                         for file in $SOURCES
1601                         do
1602                                 [ -n "`src_md5 $file`" ] && continue
1603                                 new_SOURCES="$new_SOURCES $file"
1604                         done
1605                         SOURCES="$new_SOURCES"
1606                         get_files $SOURCES $PATCHES;
1607                         tag_files "$SOURCES $PATCHES $ICONS";
1608                 else
1609                         Exit_error err_no_spec_in_cmdl;
1610                 fi
1611                 ;;
1612         "mr-proper" )
1613                 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1614                 ;;
1615         "list-sources-files" )
1616                 init_builder
1617                 NOCVSSPEC="yes"
1618                 DONT_PRINT_REVISION="yes"
1619                 get_spec
1620                 parse_spec
1621                 SAPS="$SOURCES $PATCHES"
1622                 for SAP in $SAPS ; do
1623                          echo $SAP | awk '{gsub(/.*\//,"") ; print}'
1624                 done
1625                 ;;
1626         "list-sources-local-paths" )
1627                 init_builder
1628                 NOCVSSPEC="yes"
1629                 DONT_PRINT_REVISION="yes"
1630                 get_spec
1631                 parse_spec
1632                 SAPS="$SOURCES $PATCHES"
1633                 for SAP in $SAPS ; do
1634                          echo $SOURCE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
1635                 done
1636                 ;;
1637         "usage" )
1638                 usage;;
1639         "version" )
1640                 echo "$VERSION";;
1641 esac
1642 if [ -f `pwd`/.${SPECFILE}_INSTALLED_PACKAGES -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
1643         rm `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1644 fi
1645 cd "$__PWD"
1646
1647 # vi:syntax=sh:ts=3:sw=4
This page took 0.196481 seconds and 4 git commands to generate.