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