]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
34a909ea472794c1487808d1e84dcdd831d21a84
[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                 source_md5=`grep -i "#[         ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://'`
517                 if [ ! -z "$source_md5" ] ; then
518                          echo $source_md5;
519                 else
520                          # we have empty SourceX-md5, but it is still possible
521                          # that we have NoSourceX-md5 AND NoSource: X
522                          nosource_md5=`grep -i "#[       ]*NoSource$no-md5[      ]*:" $SPECFILE | sed -e 's/.*://'`
523                          if [ ! -z "$nosource_md5" -a ! X"`grep -i "^NoSource:[  ]*$no$" $SPECFILE`" = X"" ] ; then
524                                   echo $nosource_md5;
525                          fi;
526                 fi;
527         else
528                 if [ $(echo "$md5" | wc -l) != 1 ] ; then
529                         echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
530                 fi
531                 echo "$md5" | tail -n 1
532         fi
533 }
534
535 distfiles_url ()
536 {
537         echo "$PROTOCOL$DISTFILES_SERVER/distfiles/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
538 }
539
540 distfiles_attic_url ()
541 {
542         echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
543 }
544
545 good_md5 ()
546 {
547         md5=$(src_md5 "$1")
548         [ "$md5" = "" ] || \
549         [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
550 }
551
552 good_size ()
553 {
554          size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
555          [ -n "$size" -a "$size" -gt 0 ]
556 }
557
558 cvsignore_df ()
559 {
560         if [ "$CVSIGNORE_DF" != "yes" ]; then
561                 return
562         fi
563         cvsignore=${SOURCE_DIR}/.cvsignore
564         if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
565                 echo "$1" >> $cvsignore
566         fi
567 }
568
569 get_files()
570 {
571         GET_FILES="$@"
572
573         if [ -n "$DEBUG" ]; then
574                 set -x;
575                 set -v;
576         fi
577
578         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
579                 cd "$SOURCE_DIR"
580
581                 OPTIONS="up "
582                 if [ -n "$CVSROOT" ]; then
583                         OPTIONS="-d $CVSROOT $OPTIONS"
584                 else
585                         if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
586                                 echo "warning: No cvs access defined for SOURCES"
587                                 NOCVS="yes"
588                         fi
589                 fi
590                 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
591                         OPTIONS="$OPTIONS -A"
592                 else
593                         if [ -n "$CVSDATE" ]; then
594                                 OPTIONS="$OPTIONS -D $CVSDATE"
595                         fi
596                         if [ -n "$CVSTAG" ]; then
597                                 OPTIONS="$OPTIONS -r $CVSTAG"
598                         fi
599                 fi
600                 for i in $GET_FILES
601                 do
602                         if [ -n "$UPDATE5" ]; then
603                                 if [ -n "$ADD5" ]; then
604                                         [ `nourl $i` = "$i" ] && continue
605                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE && continue
606                                 else
607                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE || continue
608                                 fi
609                         fi
610                         FROM_DISTFILES=0
611                         if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
612                                 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
613                                         echo "Warning: no URL given for $i"
614                                 fi
615
616                                 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
617                                         if good_md5 "$i" && good_size "$i"; then
618                                                 echo "$(nourl "$i") having proper md5sum already exists"
619                                                 continue
620                                         fi
621                                         target=$(nourl "$i")
622                                         url=$(distfiles_url "$i")
623                                         url_attic=$(distfiles_attic_url "$i")
624                                         FROM_DISTFILES=1
625                                         if [ `echo $url | grep -E '^(\.|/)'` ]; then
626                                                 ${GETLOCAL} $url $target
627                                         else
628                                                 if [ -z "$NOMIRRORS" ]; then
629                                                         url="`find_mirror "$url"`"
630                                                 fi
631                                                 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
632                                                 if [ `echo $url | grep -E 'ftp://'` ]; then
633                                                         ${GETURI2} ${OUTFILEOPT} "$target" "$url"
634                                                 fi
635                                         fi
636                                         if ! test -s "$target"; then
637                                                 rm -f "$target"
638                                                 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
639                                                         ${GETLOCAL} $url_attic $target
640                                                 else
641                                                         if [ -z "$NOMIRRORS" ]; then
642                                                                 url_attic="`find_mirror "$url_attic"`"
643                                                         fi
644                                                         ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
645                                                         if [ `echo $url_attic | grep -E 'ftp://'` ]; then
646                                                                 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
647                                                         fi
648                                                 fi
649                                         fi
650                                         if test -s "$target"; then
651                                                 cvsignore_df $target
652                                         else
653                                                 rm -f "$target"
654                                                 FROM_DISTFILES=0
655                                         fi
656                                 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
657                                         # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
658                                         result=1
659                                         retries_counter=0
660                                         while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
661                                         do
662                                                 retries_counter=$(( $retries_counter + 1 ))
663                                                 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
664                                                 result=$?
665                                                 [ -n "$output" ] && echo "$output"
666                                                 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
667                                                         echo "Trying again [`nourl $i`]... ($retries_counter)"
668                                                         sleep 2
669                                                         continue
670                                                 else
671                                                         break
672                                                 fi
673                                         done
674                                 fi
675
676                                 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
677                                         if [ -z "$NOMIRRORS" ]; then
678                                                 im="`find_mirror "$i"`"
679                                         else
680                                                 im="$i"
681                                         fi
682                                         ${GETURI} "$im" || \
683                                         if [ `echo $im | grep -E 'ftp://'` ]; then
684                                                 ${GETURI2} "$im"
685                                         fi
686                                 fi
687
688                         fi
689                         srcno=$(src_no $i)
690                         if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
691                                 Exit_error err_no_source_in_repo $i;
692                         elif [ -n "$UPDATE5" ] && \
693                                 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
694                                 [ -z "$(grep -E -i '^NoSource[  ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
695                                 grep -q -i -E '^#[      ]*source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE )
696                         then
697                                 echo "Updating source-$srcno md5."
698                                 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
699                                 perl -i -ne '
700                                 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
701                                 print "# Source'$srcno'-md5:\t'$md5'\n"
702                                 if /^Source'$srcno'\s*:\s+/;
703                                 ' \
704                                 $SPECS_DIR/$SPECFILE
705                         fi
706
707                         if good_md5 "$i" && good_size "$i"; then
708                                 :
709                         elif [ "$FROM_DISTFILES" = 1 ]; then
710                                 # wrong md5 from distfiles: remove the file and try again
711                                 # but only once ...
712                                 echo "MD5 sum mismatch. Trying full fetch."
713                                 FROM_DISTFILES=2
714                                 rm -f $target
715                                 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
716                                 if [ `echo $url | grep -E 'ftp://'` ]; then
717                                         ${GETURI2} ${OUTFILEOPT} "$target" "$url"
718                                 fi
719                                 if ! test -s "$target"; then
720                                         rm -f "$target"
721                                         ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
722                                         if [ `echo $url_attic | grep -E 'ftp://'` ]; then
723                                                 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
724                                         fi
725                                 fi
726                                 test -s "$target" || rm -f "$target"
727                         fi
728
729                         if good_md5 "$i" && good_size "$i" ; then
730                                 :
731                         else
732                                 echo "MD5 sum mismatch or 0 size.  Use -U to refetch sources,"
733                                 echo "or -5 to update md5 sums, if you're sure files are correct."
734                                 Exit_error err_no_source_in_repo $i
735                         fi
736                 done
737
738                 if [ "$CHMOD" = "yes" ]; then
739                         CHMOD_FILES="`nourl $GET_FILES`"
740                         if [ -n "$CHMOD_FILES" ]; then
741                                 chmod $CHMOD_MODE $CHMOD_FILES
742                         fi
743                 fi
744                 unset OPTIONS
745         fi
746 }
747
748 make_tagver() {
749
750                 if [ -n "$DEBUG" ]; then
751                          set -x;
752                          set -v;
753                 fi
754
755                 # Check whether first character of PACKAGE_NAME is legal for tag name
756                 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
757                         TAG_PREFIX=tag_
758                 fi
759                 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"`
760                 # Remove #kernel.version_release from TAGVER because tagging sources
761                 # could occur with different kernel-headers than kernel-headers used at build time.
762                 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
763                 echo -n "$TAGVER"
764 }
765
766 tag_files()
767 {
768         TAG_FILES="$@"
769
770         if [ -n "$DEBUG" ]; then
771                 set -x;
772                 set -v;
773         fi
774
775         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
776                 echo "Version: $PACKAGE_VERSION"
777                 echo "Release: $PACKAGE_RELEASE"
778
779                 TAGVER=`make_tagver`
780
781                 if [ "$TAG_VERSION" = "yes" ]; then
782                         echo "CVS tag: $TAGVER"
783                 fi
784                 if [ -n "$TAG" ]; then
785                         echo "CVS tag: $TAG"
786                 fi
787
788                 OPTIONS="tag -F"
789                 if [ -n "$CVSROOT" ]; then
790                         OPTIONS="-d $CVSROOT $OPTIONS"
791                 fi
792
793                 cd "$SOURCE_DIR"
794                 for i in $TAG_FILES
795                 do
796                         # don't tag files stored on distfiles
797                         [ -n "`src_md5 $i`" ] && continue
798                         if [ -f "`nourl $i`" ]; then
799                                 if [ "$TAG_VERSION" = "yes" ]; then
800                                         cvs $OPTIONS $TAGVER `nourl $i`
801                                 fi
802                                 if [ -n "$TAG" ]; then
803                                         cvs $OPTIONS $TAG `nourl $i`
804                                 fi
805                         else
806                                 Exit_error err_no_source_in_repo $i
807                         fi
808                 done
809
810                 cd "$SPECS_DIR"
811                 if [ "$TAG_VERSION" = "yes" ]; then
812                         cvs $OPTIONS $TAGVER $SPECFILE
813                 fi
814                 if [ -n "$TAG" ]; then
815                         cvs $OPTIONS $TAG $SPECFILE
816                 fi
817
818                 unset OPTIONS
819         fi
820 }
821
822 branch_files()
823 {
824         TAG=$1
825         echo "CVS branch tag: $TAG"
826         shift;
827
828         TAG_FILES="$@"
829
830         if [ -n "$DEBUG" ]; then
831                 set -x;
832                 set -v;
833         fi
834
835         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
836
837                 OPTIONS="tag -b"
838                 if [ -n "$CVSROOT" ]; then
839                         OPTIONS="-d $CVSROOT $OPTIONS"
840                 fi
841                 cd "$SOURCE_DIR"
842                 for i in $TAG_FILES
843                 do
844                         if [ -f `nourl $i` ]; then
845                                 cvs $OPTIONS $TAG `nourl $i`
846                         else
847                                 Exit_error err_no_source_in_repo $i
848                         fi
849                 done
850                 cd "$SPECS_DIR"
851                 cvs $OPTIONS $TAG $SPECFILE
852
853                 unset OPTIONS
854         fi
855 }
856
857
858
859 build_package()
860 {
861         if [ -n "$DEBUG" ]; then
862                 set -x;
863                 set -v;
864         fi
865
866         cd "$SPECS_DIR"
867
868         if [ -n "$TRY_UPGRADE" ]; then
869                 if [ -n "$FLOAT_VERSION" ]; then
870                         TNOTIFY=`./pldnotify.awk $SPECFILE -n`
871                 else
872                         TNOTIFY=`./pldnotify.awk $SPECFILE`
873                 fi
874
875                 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
876
877                 if [ -n "$TNEWVER" ]; then
878                         TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
879                         echo "New version found, updating spec file to version " $TNEWVER
880                         cp -f $SPECFILE $SPECFILE.bak
881                         chmod +w $SPECFILE
882                         eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
883                         eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
884                         parse_spec;
885                         if [ -n "$ICONS" ]; then
886                                 get_files $ICONS;
887                                 parse_spec;
888                         fi
889                         get_files "$SOURCES $PATCHES";
890                         unset TOLDVER TNEWVER TNOTIFY
891                 fi
892         fi
893         cd "$SPECS_DIR"
894
895         case "$COMMAND" in
896                 build )
897                         BUILD_SWITCH="-ba" ;;
898                 build-binary )
899                         BUILD_SWITCH="-bb" ;;
900                 build-source )
901                         BUILD_SWITCH="-bs --nodeps" ;;
902                 build-prep )
903                         BUILD_SWITCH="-bp --nodeps" ;;
904         esac
905         if [ -n "$LOGFILE" ]; then
906                 LOG=`eval echo $LOGFILE`
907                 if [ -d "$LOG" ]; then
908                         echo "Log file $LOG is a directory."
909                         echo "Parse error in the spec?"
910                         Exit_error err_build_fail;
911                 fi
912                 if [ -n "$LASTLOG_FILE" ]; then
913                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
914                 fi
915                 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
916                 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
917                 RETVAL=`cat $RES_FILE`
918                 rm $RES_FILE
919                 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
920                         if [ "$RETVAL" -eq "0" ]; then
921                                 mv $LOG $LOGDIROK
922                         else
923                                 mv $LOG $LOGDIRFAIL
924                         fi
925                 fi
926         else
927                 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE
928                 RETVAL=$?
929         fi
930         if [ "$RETVAL" -ne "0" ]; then
931                 if [ -n "$TRY_UPGRADE" ]; then
932                         echo "\n!!! Package with new version cannot be build automagically\n"
933                         mv -f $SPECFILE.bak $SPECFILE
934                 fi
935                 Exit_error err_build_fail;
936         fi
937         unset BUILD_SWITCH
938 }
939
940 nourl()
941 {
942         echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
943 }
944
945 install_required_packages()
946 {
947         run_poldek -vi $1
948         return $?
949 }
950
951 set_bconds_values()
952 {
953         AVAIL_BCONDS_WITHOUT=""
954         AVAIL_BCONDS_WITH=""
955         if `grep -q ^%bcond ${SPECFILE}`; then
956                 BCOND_VERSION="NEW"
957         elif `egrep -q ^#\ *_with ${SPECFILE}`; then
958                 BCOND_VERSION="OLD"
959         else
960                 BCOND_VERSION="NONE"
961         fi
962
963         # expand bconds from ~/.bcondrc
964         # The file structure is like gentoo's package.use:
965         # ---
966         # * -selinux
967         # samba -mysql -pgsql
968         # w32codec license_agreement
969         # php +mysqli
970         # ---
971         if [ "${BCOND_VERSION}" != "NONE" ] && ( [ -f $HOME/.bcondrc ] || ( [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] ) ) ; then
972                 # This takes package name, first defined in spec.
973                 # so consider that when defining flags for package.
974                 PN=`$RPM -q --qf '%{NAME}\n' --specfile $SPECFILE | head -n 1`
975                 AVAIL=`$RPMBUILD --bcond $SPECFILE`
976
977                 BCONDRC=$HOME/.bcondrc
978                 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && BCONDRC=$HOME_ETC/.bcondrc
979
980                 while read pkg flags; do
981                         # ignore comments
982                         [[ "$pkg" == \#* ]] && continue
983
984                         # any package or current package?
985                         if [ "$pkg" = "*" ] || [ "$pkg" = "$PN" ]; then
986                                 for flag in $flags; do
987                                         opt=${flag#[+-]}
988
989                                         # use only flags which are in this package.
990                                         if [[ $AVAIL = *${opt}* ]]; then
991                                                 if [[ $flag = -* ]]; then
992                                                         BCOND="$BCOND --without $opt"
993                                                 else
994                                                         BCOND="$BCOND --with $opt"
995                                                 fi
996                                         fi
997                                 done
998                         fi
999                 done < $BCONDRC
1000         fi
1001
1002         case "${BCOND_VERSION}" in
1003                  NONE)
1004                         :
1005                         ;;
1006                  OLD)
1007                         echo "Warning: This spec has old style bconds. Fix it || die."
1008                         for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
1009                         do
1010                                 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
1011                                 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
1012                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1013                                 else
1014                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1015                                 fi
1016                         done
1017
1018                         for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
1019                         do
1020                                 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
1021                                 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
1022                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1023                                 else
1024                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1025                                 fi
1026                         done
1027                         ;;
1028                 NEW)
1029                         cond_type="" # with || without
1030                         for opt in `$RPMBUILD --bcond $SPECFILE`
1031                         do
1032                                 case "$opt" in
1033                                         _without)
1034                                                 cond_type="without"
1035                                                 ;;
1036                                         _with)
1037                                                 cond_type="with"
1038                                                 ;;
1039                                         *)
1040                                                 case "$cond_type" in
1041                                                         with)
1042                                                                 cond_type=''
1043                                                                 AVAIL_BCOND_WITH="$opt"
1044                                                                 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
1045                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1046                                                                 else
1047                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1048                                                                 fi
1049                                                                 ;;
1050                                                         without)
1051                                                                 cond_type=''
1052                                                                 AVAIL_BCOND_WITHOUT="$opt"
1053                                                                 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
1054                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1055                                                                 else
1056                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1057                                                                 fi
1058                                                                 ;;
1059                                                 esac
1060                                                 ;;
1061                                 esac
1062                         done
1063                         ;;
1064         esac
1065 }
1066
1067 run_sub_builder()
1068 {
1069         package_name="${1}"
1070         echo -ne "Package installation failed:\t$package_name\n"
1071         #
1072         # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1073         # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1074         # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1075         # jakby nie bylo tego kawalka kodu.
1076         #
1077         # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1078         #         Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1079         #
1080         #
1081         # y0shi.
1082
1083         parent_spec_name=''
1084
1085         # Istnieje taki spec? ${package}.spec
1086         if [ -f "${SPECS_DIR}${package}.spec" ]; then
1087                 parent_spec_name=${package}.spec
1088         elif [ -f "${SPECS_DIR}`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
1089                 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
1090         else
1091                 for provides_line in `grep ^Provides:.*$package  ${SPECS_DIR} -R`
1092                 do
1093                         echo $provides_line
1094                 done
1095         fi
1096
1097         if [ "${parent_spec_name}" != "" ]; then
1098                 sub_builder_opts=''
1099                 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
1100                         sub_builder_opts="${sub_builder_opts} -R"
1101                 fi
1102                 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
1103                         sub_builder_opts="${sub_builder_opts} -RB"
1104                 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
1105                         sub_builder_opts="${sub_builder_opts} -FRB"
1106                 fi
1107                 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
1108                         sub_builder_opts="${sub_builder_opts} -Upi"
1109                 fi
1110                 cd "${SPECS_DIR}"
1111                 ./builder ${sub_builder_opts} ${parent_spec_name}
1112         fi
1113         NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1114 }
1115
1116 remove_build_requires()
1117 {
1118         if [ "$INSTALLED_PACKAGES" != "" ]; then
1119                 case "$REMOVE_BUILD_REQUIRES" in
1120                         "force")
1121                                 run_poldek --noask -ve $INSTALLED_PACKAGES
1122                                 ;;
1123                         "nice")
1124                                 run_poldek --ask -ve $INSTALLED_PACKAGES
1125                                 ;;
1126                         *)
1127                                 echo You may want to manually remove following BuildRequires fetched:
1128                                 echo $INSTALLED_PACKAGES
1129                                 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1130                                 ;;
1131                 esac
1132         fi
1133 }
1134
1135 display_bconds()
1136 {
1137         if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1138                 if [ "$BCOND" != "" ]; then
1139                         echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
1140                         echo -ne "$BCOND"
1141                 else
1142                         echo -ne "\nNo conditional flags passed"
1143                 fi
1144                 echo -ne "\n\nfrom available:\n"
1145                 echo -ne "--with   :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1146         fi
1147 }
1148
1149 fetch_build_requires()
1150 {
1151         if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1152                 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1153                          CONF=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print "@" $3 } ' | xargs)
1154                          DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print "@" $3 } ' | xargs)
1155                          if [ -n "$CONF" -o -n "$DEPS" ]; then
1156                                   /usr/bin/poldek --update; /usr/bin/poldek --upa
1157                          fi
1158                          if [ -n "$CONF" ]; then
1159                                   echo "Trying to uninstall conflicting packages ($CONF):"
1160                                   /usr/bin/poldek --noask --nofollow -ev $CONF
1161                          fi
1162                          if [ -n "$DEPS" ]; then
1163                                   echo "Trying to install dependencies ($DEPS):"
1164                                   /usr/bin/poldek --caplookup -uGv $DEPS
1165                          fi
1166                          return
1167                 fi
1168
1169                 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1170                 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1171                 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1172                 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1173                 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1174                 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`
1175                 do
1176                         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`"
1177                         GO="yes"
1178                         package=`basename "$package_item"|sed -e "s/}$//g"`
1179                         COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1180                         mach=`uname -m`
1181
1182                         COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1183                         if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1184                                 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
1185                                         GO="yes"
1186                                 fi
1187                         # bcond:
1188                         else
1189                                 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1190                                 GO=""
1191                                 # %{without}
1192                                 if `echo $COND_TST|grep -q 'without_'`; then
1193                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
1194                                         if `echo $COND_TST|grep -q !`; then
1195                                                 COND_STATE="with"
1196                                         else
1197                                                 COND_STATE="wout"
1198                                         fi
1199                                         if `echo $AVAIL_BCONDS_WITHOUT|grep -q "<$COND_NAME>"`; then
1200                                                 COND_ARGV="wout"
1201                                         else
1202                                                 COND_ARGV="with"
1203                                         fi
1204                                 # %{with}
1205                                 elif `echo $COND_TST|grep -q 'with_'`; then
1206                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
1207                                         if `echo $COND_TST|grep -q !`; then
1208                                                 COND_STATE="wout"
1209                                         else
1210                                                 COND_STATE="with"
1211                                         fi
1212                                         if `echo $AVAIL_BCONDS_WITH|grep -q "<$COND_NAME>"`; then
1213                                                 COND_ARGV="with"
1214                                         else
1215                                                 COND_ARGV="wout"
1216                                         fi
1217                                 fi
1218                                 RESULT="${COND_STATE}-${COND_ARGV}"
1219                                 case "$RESULT" in
1220                                         "with-wout" | "wout-with" )
1221                                                 GO=""
1222                                                 ;;
1223                                         "wout-wout" | "with-with" )
1224                                                 GO="yes"
1225                                                 ;;
1226                                         * )
1227                                                 echo "Action '$RESULT' was not defined for package '$package_item'"
1228                                                 GO="yes"
1229                                                 ;;
1230                                 esac
1231                         fi
1232
1233                         if [ "$GO" = "yes" ]; then
1234                                 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1235                                         echo "Testing if $package has subrequirements..."
1236                                         run_poldek -t -i $package --dumpn=".$package-req.txt"
1237                                         if [ -f ".$package-req.txt" ]; then
1238                                                 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1239                                                 do
1240                                                         if [ "$package_name" = "$package" ]; then
1241                                                                 echo -ne "Installing BuildRequired package:\t$package_name\n"
1242                                                                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1243                                                                 install_required_packages $package;
1244                                                         else
1245                                                                 echo -ne "Installing (sub)Required package:\t$package_name\n"
1246                                                                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1247                                                                 install_required_packages $package_name;
1248                                                         fi
1249                                                         case $? in
1250                                                                 0)
1251                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1252                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1253                                                                         ;;
1254                                                                 *)
1255                                                                         echo "Attempting to run spawn sub - builder..."
1256                                                                         run_sub_builder $package_name
1257                                                                         if [ $? -eq 0 ]; then
1258                                                                                 install_required_packages $package_name;
1259                                                                                 case $? in
1260                                                                                         0)
1261                                                                                                 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1262                                                                                                 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1263                                                                                                 ;;
1264                                                                                         *)
1265                                                                                                 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1266                                                                                                 ;;
1267                                                                                 esac
1268                                                                         fi
1269                                                                         ;;
1270                                                         esac
1271                                                 done
1272                                                 rm -f ".$package-req.txt"
1273                                         else
1274                                                 echo "Attempting to run spawn sub - builder..."
1275                                                 run_sub_builder $package
1276                                                 if [ $? -eq 0 ]; then
1277                                                         install_required_packages $package;
1278                                                         case $? in
1279                                                                 0)
1280                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1281                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1282                                                                         ;;
1283                                                                 *)
1284                                                                         NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1285                                                                         ;;
1286                                                         esac
1287                                                 fi
1288                                         fi
1289                                 else
1290                                         echo "Package $package is already installed. BuildRequirement satisfied."
1291                                 fi
1292                         fi
1293                 done
1294                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1295                 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1296                         echo "Unable to install following packages and their dependencies:"
1297                         for pkg in "$NOT_INSTALLED_PACKAGES"
1298                         do
1299                                 echo $pkg
1300                         done
1301                         remove_build_requires
1302                         exit 8
1303                 fi
1304         fi
1305 }
1306
1307 #---------------------------------------------
1308 # main()
1309
1310 if [ "$#" = 0 ]; then
1311         usage;
1312         exit 1
1313 fi
1314
1315 while test $# -gt 0
1316 do
1317         case "${1}" in
1318                 -5 | --update-md5 )
1319                         COMMAND="get";
1320                         NODIST="yes"
1321                         NOCVSSPEC="yes"
1322                         UPDATE5="yes"
1323                         shift ;;
1324                 -a5 | --add-md5 )
1325                         COMMAND="get";
1326                         NODIST="yes"
1327                         NOCVS="yes"
1328                         NOCVSSPEC="yes"
1329                         UPDATE5="yes"
1330                         ADD5="yes"
1331                         shift ;;
1332                 -n5 | --no-md5 )
1333                         NO5="yes"
1334                         shift ;;
1335                 -D | --debug )
1336                         DEBUG="yes"; shift ;;
1337                 -V | --version )
1338                         COMMAND="version"; shift ;;
1339                 -a | --as_anon )
1340                         CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1341                 -b | -ba | --build )
1342                         COMMAND="build"; shift ;;
1343                 -bb | --build-binary )
1344                         COMMAND="build-binary"; shift ;;
1345                 -bs | --build-source )
1346                         COMMAND="build-source"; shift ;;
1347                 -bp | --build-prep )
1348                         COMMAND="build-prep"; shift ;;
1349                 -B | --branch )
1350                         COMMAND="branch"; shift; TAG="${1}"; shift;;
1351                 -c | --clean )
1352                         CLEAN="--clean --rmspec --rmsource"; shift ;;
1353                 -d | --cvsroot )
1354                         shift; CVSROOT="${1}"; shift ;;
1355                 -g | --get )
1356                         COMMAND="get"; shift ;;
1357                 -h | --help )
1358                         COMMAND="usage"; shift ;;
1359                 --http )
1360                         PROTOCOL="http"; shift ;;
1361                 -l | --logtofile )
1362                         shift; LOGFILE="${1}"; shift ;;
1363                 -ni| --nice )
1364                         shift; DEF_NICE_LEVEL=${1}; shift ;;
1365                 -m | --mr-proper )
1366                         COMMAND="mr-proper"; shift ;;
1367                 -nc | --no-cvs )
1368                         NOCVS="yes"; shift ;;
1369                 -ncs | --no-cvs-specs )
1370                         NOCVSSPEC="yes"; shift ;;
1371                 -nd | --no-distfiles )
1372                         NODIST="yes"; shift ;;
1373                 -nm | --no-mirrors )
1374                         NOMIRRORS="yes"; shift ;;
1375                 -nu | --no-urls )
1376                         NOURLS="yes"; shift ;;
1377                 -ns | --no-srcs )
1378                         NOSRCS="yes"; shift ;;
1379                 -ns0 | --no-source0 )
1380                         NOSOURCE0="yes"; shift ;;
1381                 -nn | --no-net )
1382                         NOCVS="yes"
1383                         NOCVSSPEC="yes"
1384                         NODIST="yes"
1385                         NOMIRRORS="yes"
1386                         NOURLS="yes"
1387                         NOSRCS="yes"
1388                         shift;;
1389                 --opts )
1390                         shift; RPMOPTS="$RPM_OPTS ${1}"; shift ;;
1391                 --with | --without )
1392                         case $GROUP_BCONDS in
1393                                 "yes")
1394                                         COND=${1}
1395                                         shift
1396                                         while ! `echo ${1}|grep -qE '(^-|spec)'`
1397                                         do
1398                                                 BCOND="$BCOND $COND $1"
1399                                                 shift
1400                                         done;;
1401                                 "no")
1402                                         BCOND="$BCOND $1 $2" ; shift 2 ;;
1403                         esac
1404                         ;;
1405                 --target )
1406                         shift; TARGET="${1}"; shift ;;
1407                 --target=* )
1408                         TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
1409                 -q | --quiet )
1410                         QUIET="--quiet"; shift ;;
1411                 --date )
1412                         CVSDATE="${2}"; shift 2 ;;
1413                 -r | --cvstag )
1414                         shift; CVSTAG="${1}"; shift ;;
1415                 -R | --fetch-build-requires)
1416                         FETCH_BUILD_REQUIRES="yes"
1417                         NOT_INSTALLED_PACKAGES=
1418                         shift ;;
1419                 -RB | --remove-build-requires)
1420                         REMOVE_BUILD_REQUIRES="nice"
1421                         shift ;;
1422                 -FRB | --force-remove-build-requires)
1423                         REMOVE_BUILD_REQUIRES="force"
1424                         shift ;;
1425                 -sf | --sources-files)
1426                         COMMAND="list-sources-files"
1427                         shift ;;        
1428                 -sp | --sources-paths)
1429                         COMMAND="list-sources-local-paths"
1430                         shift ;;        
1431                 -Tvs | --tag-version-stable )
1432                         COMMAND="tag";
1433                         TAG="STABLE"
1434                         TAG_VERSION="yes"
1435                         shift;;
1436                 -Tvn | --tag-version-nest )
1437                         COMMAND="tag";
1438                         TAG="NEST"
1439                         TAG_VERSION="yes"
1440                         shift;;
1441                 -Ts | --tag-stable )
1442                         COMMAND="tag";
1443                         TAG="STABLE"
1444                         TAG_VERSION="no"
1445                         shift;;
1446                 -Tn | --tag-nest )
1447                         COMMAND="tag";
1448                         TAG="NEST"
1449                         TAG_VERSION="no"
1450                         shift;;
1451                 -Tv | --tag-version )
1452                         COMMAND="tag";
1453                         TAG=""
1454                         TAG_VERSION="yes"
1455                         shift;;
1456                 -Tp | --tag-prefix )
1457                         TAG_PREFIX="$2"
1458                         shift 2;;
1459                 -tt | --test-tag )
1460                         TEST_TAG="yes"
1461                         shift;;
1462                 -T | --tag )
1463                         COMMAND="tag";
1464                         shift
1465                         TAG="$1"
1466                         TAG_VERSION="no"
1467                         shift;;
1468                 -ir | --integer-release-only )
1469                         INTEGER_RELEASE="yes"
1470                         shift;;
1471                 -U | --update )
1472                         COMMAND="get"
1473                         UPDATE="yes"
1474                         NOCVSSPEC="yes"
1475                         NODIST="yes"
1476                         UPDATE5="yes"
1477                         shift ;;
1478                 -Upi | --update-poldek-indexes )
1479                         UPDATE_POLDEK_INDEXES="yes"
1480                         shift ;;
1481                 -u | --try-upgrade )
1482                         TRY_UPGRADE="1"; shift ;;
1483                 -un | --try-upgrade-with-float-version )
1484                         TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1485                 -v | --verbose )
1486                         BE_VERBOSE="1"; shift ;;
1487                 --define)
1488                         shift
1489                         MACRO="${1}"
1490                         VALUE="${2}"
1491                         shift 2
1492                         RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1493                         ;;
1494                 --nodeps)
1495                         shift
1496                         RPMOPTS="${RPMOPTS} --nodeps"
1497                         ;;
1498                 -debug)
1499                         RPMOPTS="${RPMOPTS} -debug"; shift ;;
1500                 * )
1501                         SPECFILE="${1}"
1502                         export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1503                         shift ;;
1504         esac
1505 done
1506
1507 if [ -n "$DEBUG" ]; then
1508         set -x;
1509         set -v;
1510 fi
1511
1512 if [ -n "$TARGET" ]; then
1513         case "$RPMBUILD" in
1514                 "rpmbuild")
1515                         TARGET_SWITCH="--target $TARGET" ;;
1516                 "rpm")
1517                         TARGET_SWITCH="--target=$TARGET" ;;
1518         esac
1519 fi
1520
1521 case "$COMMAND" in
1522         "build" | "build-binary" | "build-source" | "build-prep" )
1523                 init_builder;
1524                 if [ -n "$SPECFILE" ]; then
1525                         get_spec;
1526                         set_bconds_values;
1527                         display_bconds;
1528                         fetch_build_requires;
1529                         parse_spec;
1530                         if [ "$INTEGER_RELEASE" = "yes" ]; then
1531                                 echo "Checking release $PACKAGE_RELEASE..."
1532                                 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
1533                                         Exit_error err_fract_rel "$PACKAGE_RELEASE"
1534                                 fi
1535                         fi
1536
1537                         if [ -n "$TEST_TAG" ]; then
1538                                 TAGVER=`make_tagver`
1539                                 echo "Searching for tag $TAGVER..."
1540                                 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1541                                 if [ -n "$TAGREL" ]; then
1542                                         Exit_error err_tag_exists "$TAGVER" "$TAGREL"
1543                                 fi
1544                         fi
1545
1546                         if [ -n "$ICONS" ]; then
1547                                 get_files $ICONS;
1548                                 parse_spec;
1549                         fi
1550                         if [ -n "$NOSOURCE0" ] ; then
1551                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1552                         fi
1553                         get_files "$SOURCES $PATCHES";
1554                         build_package;
1555                         if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
1556                                 run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
1557                         fi
1558                         remove_build_requires;
1559                 else
1560                         Exit_error err_no_spec_in_cmdl;
1561                 fi
1562                 ;;
1563         "branch" )
1564                 init_builder;
1565                 if [ -n "$SPECFILE" ]; then
1566                         get_spec;
1567                         parse_spec;
1568                         if [ -n "$ICONS" ]; then
1569                                 get_files $ICONS
1570                                 parse_spec;
1571                         fi
1572                         get_files $SOURCES $PATCHES;
1573                         branch_files $TAG "$SOURCES $PATCHES $ICONS";
1574                 else
1575                         Exit_error err_no_spec_in_cmdl;
1576                 fi
1577                 ;;
1578         "get" )
1579                 init_builder;
1580                 if [ -n "$SPECFILE" ]; then
1581                         get_spec;
1582                         parse_spec;
1583                         if [ -n "$ICONS" ]; then
1584                                 OLD_UPDATE5=$UPDATE5
1585                                 UPDATE5= get_files $ICONS
1586                                 UPDATE5=$OLD_UPDATE5
1587                                 parse_spec;
1588                         fi
1589                         if [ -n "$NOSOURCE0" ] ; then
1590                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1591                         fi
1592                         get_files $SOURCES $PATCHES
1593                 else
1594                         Exit_error err_no_spec_in_cmdl;
1595                 fi
1596                 ;;
1597         "tag" )
1598                 NOURLS=1
1599                 NODIST=1
1600                 init_builder;
1601                 if [ -n "$SPECFILE" ]; then
1602                         get_spec;
1603                         parse_spec;
1604                         if [ -n "$ICONS" ]; then
1605                                 get_files $ICONS
1606                                 parse_spec;
1607                         fi
1608                         # don't fetch sources from remote locations
1609                         new_SOURCES=""
1610                         for file in $SOURCES
1611                         do
1612                                 [ -n "`src_md5 $file`" ] && continue
1613                                 new_SOURCES="$new_SOURCES $file"
1614                         done
1615                         SOURCES="$new_SOURCES"
1616                         get_files $SOURCES $PATCHES;
1617                         tag_files "$SOURCES $PATCHES $ICONS";
1618                 else
1619                         Exit_error err_no_spec_in_cmdl;
1620                 fi
1621                 ;;
1622         "mr-proper" )
1623                 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1624                 ;;
1625         "list-sources-files" )
1626                 init_builder
1627                 NOCVSSPEC="yes"
1628                 DONT_PRINT_REVISION="yes"
1629                 get_spec
1630                 parse_spec
1631                 SAPS="$SOURCES $PATCHES"
1632                 for SAP in $SAPS ; do
1633                          echo $SAP | awk '{gsub(/.*\//,"") ; print}'
1634                 done
1635                 ;;
1636         "list-sources-local-paths" )
1637                 init_builder
1638                 NOCVSSPEC="yes"
1639                 DONT_PRINT_REVISION="yes"
1640                 get_spec
1641                 parse_spec
1642                 SAPS="$SOURCES $PATCHES"
1643                 for SAP in $SAPS ; do
1644                          echo $SOURCE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
1645                 done
1646                 ;;
1647         "usage" )
1648                 usage;;
1649         "version" )
1650                 echo "$VERSION";;
1651 esac
1652 if [ -f `pwd`/.${SPECFILE}_INSTALLED_PACKAGES -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
1653         rm `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1654 fi
1655 cd "$__PWD"
1656
1657 # vi:syntax=sh:ts=3:sw=4
This page took 0.156085 seconds and 3 git commands to generate.