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