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