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