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