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