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