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