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