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