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