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