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