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