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