]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
formatting
[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
14 # Notes (todo):
15 #       - builder -u fetches current version first
16 #       - tries to get new version from distfiles without new md5
17 #       - after fetching new version doesn't update md5
18 #       - doesn't get sources for specs with %include /usr/lib/rpm/macros.python
19 #         when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway)
20 #       - as above with %include /usr/lib/rpm/macros.perl and no rpm-perlprov
21 #       - when Icon: field is present, -5 and -a5 doesn't work
22
23 VERSION="\
24 Build package utility from PLD CVS repository
25 V 0.11 (C) 1999-2003 Free Penguins".
26 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
27
28 COMMAND="build"
29
30 SPECFILE=""
31 BE_VERBOSE=""
32 QUIET=""
33 CLEAN=""
34 DEBUG=""
35 NOURLS=""
36 NOCVS=""
37 NOCVSSPEC=""
38 NODIST=""
39 UPDATE=""
40 UPDATE5=""
41 ADD5=""
42 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
43 CVSROOT=""
44
45 # It can be used i.e. in log file naming.
46 # See LOGFILE example.
47 DATE=`date +%Y-%m-%d_%H-%M-%S`
48
49 # Example: LOGFILE='../log.$PACKAGE_NAME'
50 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
51 # Yes, you can use variable name! Note _single_ quotes!
52 LOGFILE=''
53
54 LOGDIR=""
55 LOGDIROK=""
56 LOGDIRFAIL=""
57 LASTLOG_FILE=""
58
59 CHMOD="no"
60 CHMOD_MODE="0444"
61 RPMOPTS=""
62 BCOND=""
63 GROUP_BCONDS="no"
64
65 PATCHES=""
66 SOURCES=""
67 ICONS=""
68 PACKAGE_RELEASE=""
69 PACKAGE_VERSION=""
70 PACKAGE_NAME=""
71 PROTOCOL="ftp"
72 WGET_RETRIES=${MAX_WGET_RETRIES:-0}
73 CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
74
75 CVSTAG=""
76 RES_FILE=""
77
78 CVS_SERVER="cvs.pld-linux.org"
79 DISTFILES_SERVER="://distfiles.pld-linux.org"
80
81 DEF_NICE_LEVEL=0
82
83 FAIL_IF_NO_SOURCES="yes"
84
85 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
86 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
87
88 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
89 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
90 GETLOCAL="cp -a"
91
92 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
93     RPM="rpm"
94     RPMBUILD="rpm"
95 else
96     RPM="rpm"
97     RPMBUILD="rpmbuild"
98 fi
99
100 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
101 POLDEK_SOURCE="cvs"
102 POLDEK_CMD="/usr/bin/poldek"
103
104 # Here we load saved user environment used to
105 # predefine options set above, or passed to builder
106 # in command line.
107 # This one reads global system environment settings:
108 if [ -f ~/etc/builderrc ]; then
109     . ~/etc/builderrc
110 fi
111 # And this one cascades settings using user personal
112 # builder settings.
113 # Example of ~/.builderrc:
114 #
115 #UPDATE_POLDEK_INDEXES="yes"
116 #FETCH_BUILD_REQUIRES="yes"
117 #REMOVE_BUILD_REQUIRES="force"
118 #GROUP_BCONDS="yes"
119 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
120 #
121 if [ -n "$HOME_ETC" ]; then
122         USER_CFG=$HOME_ETC/.builderrc
123 else
124         USER_CFG=~/.builderrc
125 fi
126
127 [ -f $USER_CFG ] && . $USER_CFG
128
129 run_poldek()
130 {
131         RES_FILE=~/tmp/poldek-exit-status.$RANDOM
132         if [ -n "$LOGFILE" ]; then
133                 LOG=`eval echo $LOGFILE`
134                 if [ -n "$LASTLOG_FILE" ]; then
135                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
136                 fi
137                 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee $LOG
138                 return $exit_pldk
139         else
140                 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
141                 return `cat ${RES_FILE}`
142                 rm -rf ${RES_FILE}
143         fi
144 }
145
146 # Example grep cvs /etc/poldek.conf:
147 # source = cvs /home/users/yoshi/rpm/RPMS/
148 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
149         run_poldek -l -n ${POLDEK_SOURCE} 1>&2 > /dev/null
150         if [ ! "$?" == "0" ]; then
151                 echo "Using improper source '${POLDEK_SOURCE}' in /etc/poldek.conf"
152                 echo "Fix it and try to continue"
153                 exit 7
154         fi
155 fi
156
157 #---------------------------------------------
158 # functions
159
160 usage()
161 {
162         if [ -n "$DEBUG" ]; then set -xv; fi
163         echo "\
164 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
165
166 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
167 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
168 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
169 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
170 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
171 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
172 [{-Tp|--tag-prefix} <prefix>]
173 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>]
174 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec]
175         
176 -5, --update-md5    - update md5 comments in spec, implies -nd -ncs
177 -a5, --add-md5      - add md5 comments to URL sources, implies -nc -nd -ncs
178 -D, --debug         - enable script debugging mode,
179 -V, --version       - output builder version
180 -a, --as_anon       - get files via pserver as cvs@$CVS_SERVER,
181 -b, -ba, --build    - get all files from CVS repo or HTTP/FTP and build package
182                       from <package>.spec,
183 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
184                       only package from <package>.spec,
185 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
186                       them into src.rpm,
187 -bp, --build-prep   - execute the %prep phase of <package>.spec,
188 -B, --branch        - add branch
189 -c, --clean         - clean all temporarily created files (in BUILD, SOURCES,
190                       SPECS and \$RPM_BUILD_ROOT),
191 -d <cvsroot>, --cvsroot <cvsroot>       
192                     - setup \$CVSROOT,
193 --define <macro> <value>
194                     - define a macro <macro> with value <value>,
195 --nodeps            - rpm won't check any dependences
196 -g, --get           - get <package>.spec and all related files from CVS repo
197                       or HTTP/FTP,
198 -h, --help          - this message,
199 --http              - use http instead of ftp,
200 -l <logfile>, --logtofile <logfile>
201                     - log all to file,
202 -m, --mr-proper     - only remove all files related to spec file and all work
203                       resources,
204 -nc, --no-cvs       - don't download sources from CVS, if source URL is given,
205 -ncs, --no-cvs-specs
206                     - don't check specs in CVS
207 -nd, --no-distfiles - don't download from distfiles
208 -nm, --no-mirrors   - don't download from mirror, if source URL is given,
209 -nu, --no-urls      - don't try to download from FTP/HTTP location,
210 -ns, --no-srcs      - don't download Sources
211 -ns0, --no-source0  - don't download Source0
212 --opts <rpm opts>   - additional options for rpm
213 -q, --quiet         - be quiet,
214 --date yyyy-mm-dd   - build package using resources from specified CVS date,
215 -r <cvstag>, --cvstag <cvstag>
216                     - build package using resources from specified CVS tag,
217 -R, --fetch-build-requires
218                     - fetch what is BuildRequired,
219 -RB, --remove-build-requires
220                     - remove all you fetched with -R or --fetch-build-requires
221                       remember, this option requires confirmation,
222 -FRB, --force-remove-build-requires
223                     - remove all you fetched with -R or --fetch-build-requires
224                       remember, this option works without confirmation,
225 -T <cvstag> , --tag <cvstag>
226                     - add cvs tag <cvstag> for files,
227 -Tvs, --tag-version-stable
228                     - add cvs tags STABLE and NAME-VERSION-RELESE for files,
229 -Tvn, --tag-version-nest
230                     - add cvs tags NEST and NAME-VERSION-RELESE for files,
231 -Ts, --tag-stable
232                     - add cvs tag STABLE for files,
233 -Tn, --tag-nest
234                     - add cvs tag NEST for files,
235 -Tv, --tag-version
236                     - add cvs tag NAME-VERSION-RELESE for files,
237 -Tp, --tag-prefix <prefix>
238                     - add <prefix> to NAME-VERSION-RELEASE tags,
239 -v, --verbose       - be verbose,
240 -u, --try-upgrade   - check version, and try to upgrade package
241 -un, --try-upgrade-with-float-version
242                     - as above, but allow float version
243 -U, --update        - refetch sources, don't use distfiles, and update md5 comments
244 -Upi, --update-poldek-indexes
245                     - refresh or make poldek package index files.
246 --with/--without <feature>
247                     - conditional build package depending on %_with_<feature>/
248                       %_without_<feature> macro switch.  You may now use
249                       --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
250                       constructions. Set GROUP_BCONDS to yes to make use of it.
251 "
252 }
253
254 cache_rpm_dump () {
255 rpm_dump_cache=`
256         case "$RPMBUILD" in
257                 rpm )
258                         rpm -bp --nodeps --define 'prep %dump' $BCOND $SPECFILE 2>&1
259                         ;;
260                 rpmbuild )
261                         rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1
262                         ;;
263         esac`
264 }
265
266 rpm_dump () {
267         if [ -z "$rpm_dump_cache" ] ; then
268                 echo "internal error: cache_rpm_dump not called!" 1>&2
269         fi
270         echo "$rpm_dump_cache"
271 }
272
273 parse_spec()
274 {
275         if [ -n "$DEBUG" ]; then
276                 set -x;
277                 set -v;
278         fi
279
280         cd $SPECS_DIR
281
282         cache_rpm_dump
283
284         if [ "$NOSRCS" != "yes" ]; then
285                 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
286         fi
287         if (rpm_dump | grep -qEi ":.*nosource.*1"); then
288                 FAIL_IF_NO_SOURCES="no"
289         fi
290
291         PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
292         ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
293         PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
294         PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`"
295         PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`"
296
297         if [ -n "$BE_VERBOSE" ]; then
298                 echo "- Sources :  `nourl $SOURCES`"
299                 if [ -n "$PATCHES" ]; then
300                         echo "- Patches :  `nourl $PATCHES`"
301                 else
302                         echo "- Patches :  *no patches needed*"
303                 fi
304                 if [ -n "$ICONS" ]; then
305                         echo "- Icon    :  `nourl $ICONS`"
306                 else
307                         echo "- Icon    :  *no package icon*"
308                 fi
309                 echo "- Name    : $PACKAGE_NAME"
310                 echo "- Version : $PACKAGE_VERSION"
311                 echo "- Release : $PACKAGE_RELEASE"
312         fi
313 }
314
315 Exit_error()
316 {
317         if [ -n "$DEBUG" ]; then
318                 set -x;
319                 set -v;
320         fi
321
322         cd "$__PWD"
323
324         case "$1" in
325                 "err_no_spec_in_cmdl" )
326                         remove_build_requires
327                         echo "ERROR: spec file name not specified.";
328                         exit 2 ;;
329                 "err_no_spec_in_repo" )
330                         remove_build_requires
331                         echo "Error: spec file not stored in CVS repo.";
332                         exit 3 ;;
333                 "err_no_source_in_repo" )
334                         remove_build_requires
335                         echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
336                         exit 4 ;;
337                 "err_build_fail" )
338                         remove_build_requires
339                         echo "Error: package build failed. (${2:-no more info})";
340                         exit 5 ;;
341         esac
342 }
343
344 init_builder()
345 {
346         if [ -n "$DEBUG" ]; then
347                 set -x;
348                 set -v;
349         fi
350
351         SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
352         SPECS_DIR="`$RPM --eval '%{_specdir}'`"
353
354         __PWD="`pwd`"
355 }
356
357 get_spec()
358 {
359         if [ -n "$DEBUG" ]; then
360                 set -x;
361                 set -v;
362         fi
363
364         if [ "$NOCVSSPEC" != "yes" ]; then
365                 cd $SPECS_DIR
366
367                 OPTIONS="up "
368
369                 if [ -n "$CVSROOT" ]; then
370                         OPTIONS="-d $CVSROOT $OPTIONS"
371                 else
372                         if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
373                                 echo "warning: No cvs access defined - using local .spec file"
374                                 NOCVSSPEC="yes"
375                         fi
376                 fi
377
378                 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
379                         OPTIONS="$OPTIONS -A"
380                 else
381                         if [ -n "$CVSDATE" ]; then
382                                 OPTIONS="$OPTIONS -D $CVSDATE"
383                         fi
384                         if [ -n "$CVSTAG" ]; then
385                                 OPTIONS="$OPTIONS -r $CVSTAG"
386                         fi
387                 fi
388
389                 result=1
390                 retries_counter=0
391                 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
392                 do
393                         retries_counter=$(( $retries_counter + 1 ))
394                         output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1)
395                         result=$?
396                         [ -n "$output" ] && echo "$output"
397                         if [ "$result" -ne "0" ]; then
398                                 if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then
399                                         echo "Trying again [$SPECFILE]... ($retries_counter)"
400                                         sleep 2
401                                         continue
402                                 fi
403                                 Exit_error err_no_spec_in_repo;
404                         fi
405                 done
406         fi
407         if [ ! -f "$SPECFILE" ]; then
408                 Exit_error err_no_spec_in_repo;
409         fi
410
411         if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
412                 chmod $CHMOD_MODE $SPECFILE
413         fi
414         unset OPTIONS
415         grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
416 }
417
418 find_mirror()
419 {
420         cd "$SPECS_DIR"
421         url="$1"
422         if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
423                 cvs update mirrors >&2
424         fi
425
426         IFS="|"
427         while read origin mirror name rest
428         do
429                 ol=`echo -n "$origin"|wc -c`
430                 prefix="`echo -n "$url" | head -c $ol`"
431                 if [ "$prefix" = "$origin" ] ; then
432                         suffix="`echo "$url"|cut -b $ol-`"
433                         echo -n "$mirror$suffix"
434                         return 0
435                 fi
436         done < mirrors
437         echo "$url"
438 }
439
440 src_no ()
441 {
442         cd $SPECS_DIR
443         rpm_dump | \
444         grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
445         sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
446         head -1 | xargs
447 }
448
449 src_md5 ()
450 {
451         no=$(src_no "$1")
452         [ -z "$no" ] && return
453         cd $SPECS_DIR
454         spec_rev=$(grep $SPECFILE CVS/Entries | sed -e s:/$SPECFILE/:: -e s:/.*::)
455         if [ -z "$spec_rev" ]; then
456                 spec_rev="$(head -1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
457         fi
458         spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
459         md5=$(grep -s -v '^#' additional-md5sums | \
460         grep -E "[      ]$(basename "$1")[      ]+${spec}([     ,]|\$)" | \
461         sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
462         grep -E '^[0-9a-f]{32}$')
463         if [ X"$md5" = X"" ] ; then
464                 grep -i "#[     ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://' | xargs
465         else
466                 if [ $(echo "$md5" | wc -l) != 1 ] ; then
467                         echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
468                 fi
469                 echo "$md5" | tail -1
470         fi
471 }
472
473 distfiles_url ()
474 {
475         echo "$PROTOCOL$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
476 }
477
478 good_md5 ()
479 {
480         md5=$(src_md5 "$1")
481         [ "$md5" = "" ] || \
482         [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
483 }
484
485 get_files()
486 {
487         GET_FILES="$@"
488
489         if [ -n "$DEBUG" ]; then
490                 set -x;
491                 set -v;
492         fi
493
494         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
495                 cd $SOURCE_DIR
496
497                 OPTIONS="up "
498                 if [ -n "$CVSROOT" ]; then
499                         OPTIONS="-d $CVSROOT $OPTIONS"
500                 else
501                         if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
502                                 echo "warning: No cvs access defined for SOURCES"
503                                 NOCVS="yes"
504                         fi
505                 fi
506                 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
507                         OPTIONS="$OPTIONS -A"
508                 else
509                         if [ -n "$CVSDATE" ]; then
510                                 OPTIONS="$OPTIONS -D $CVSDATE"
511                         fi
512                         if [ -n "$CVSTAG" ]; then
513                                 OPTIONS="$OPTIONS -r $CVSTAG"
514                         fi
515                 fi
516                 for i in $GET_FILES
517                 do
518                         if [ -n "$UPDATE5" ]; then
519                                 if [ -n "$ADD5" ]; then
520                                         [ `nourl $i` = "$i" ] && continue
521                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE && continue
522                                 else
523                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE || continue
524                                 fi
525                         fi
526                         FROM_DISTFILES=0
527                         if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then
528                                 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
529                                         echo "Warning: no URL given for $i"
530                                 fi
531
532                                 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
533                                         if good_md5 "$i"; then
534                                                 echo "$(nourl "$i") having proper md5sum already exists"
535                                                 continue
536                                         fi
537                                         target=$(nourl "$i")
538                                         url=$(distfiles_url "$i")
539                                         if [ `echo $url | grep -E '^(\.|/)'` ]; then
540                                                 ${GETLOCAL} $url $target
541                                         else
542                                                 FROM_DISTFILES=1
543                                                 if [ -z "$NOMIRRORS" ]; then
544                                                         url="`find_mirror "$url"`"
545                                                 fi
546                                                 ${GETURI} -O "$target" "$url" || \
547                                                 if [ `echo $url | grep -E 'ftp://'` ]; then
548                                                         ${GETURI2} -O "$target" "$url"
549                                                 fi
550                                                 if ! test -s "$target"; then
551                                                         rm -f "$target"
552                                                         FROM_DISTFILES=0
553                                                 fi
554                                         fi
555                                 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
556                                         # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred
557                                         result=1
558                                         retries_counter=0
559                                         while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]
560                                         do
561                                                 retries_counter=$(( $retries_counter + 1 ))
562                                                 output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1)
563                                                 result=$?
564                                                 [ -n "$output" ] && echo "$output"
565                                                 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
566                                                         echo "Trying again [`nourl $i`]... ($retries_counter)"
567                                                         sleep 2
568                                                         continue
569                                                 else
570                                                         break
571                                                 fi
572                                         done
573                                 fi
574         
575                                 if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then
576                                         if [ -z "$NOMIRRORS" ]; then
577                                                 im="`find_mirror "$i"`"
578                                         else
579                                                 im="$i"
580                                         fi
581                                         ${GETURI} "$im" || \
582                                         if [ `echo $im | grep -E 'ftp://'` ]; then
583                                                 ${GETURI2} "$im"
584                                         fi
585                                 fi
586
587
588                         fi
589                         srcno=$(src_no $i)
590                         if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
591                                 Exit_error err_no_source_in_repo $i;
592                         elif [ -n "$UPDATE5" ] && \
593                                 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
594                                 [ -z "$(grep -E -i '^NoSource[  ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
595                                 grep -q -i -E '^#[      ]*source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE )
596                         then
597                                 echo "Updating source-$srcno md5."
598                                 md5=$(md5sum `nourl $i` | cut -f1 -d' ')
599                                 perl -i -ne '
600                                 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
601                                 print "# Source'$srcno'-md5:\t'$md5'\n"
602                                 if /^Source'$srcno'\s*:\s+/;
603                                 ' \
604                                 $SPECS_DIR/$SPECFILE
605                         fi
606         
607                         if good_md5 "$i"; then
608                                 :
609                         elif [ "$FROM_DISTFILES" = 1 ]; then
610                                 # wrong md5 from distfiles: remove the file and try again
611                                 # but only once ...
612                                 echo "MD5 sum mismatch. Trying full fetch."
613                                 FROM_DISTFILES=2
614                                 rm -f $target
615                                 ${GETURI} -O "$target" "$url" || \
616                                 if [ `echo $url | grep -E 'ftp://'` ]; then
617                                         ${GETURI2} -O "$target" "$url"
618                                 fi
619                                 test -s "$target" || rm -f "$target"
620                         fi
621
622                         if good_md5 "$i"; then
623                                 :
624                         else
625                                 echo "MD5 sum mismatch.  Use -U to refetch sources,"
626                                 echo "or -5 to update md5 sums, if you're sure files are correct."
627                                 Exit_error err_no_source_in_repo $i
628                         fi
629                 done
630
631                 if [ "$CHMOD" = "yes" ]; then
632                         CHMOD_FILES="`nourl $GET_FILES`"
633                         if [ -n "$CHMOD_FILES" ]; then
634                                 chmod $CHMOD_MODE $CHMOD_FILES
635                         fi
636                 fi
637                 unset OPTIONS
638         fi
639 }
640
641 tag_files()
642 {
643         TAG_FILES="$@"
644
645         if [ -n "$DEBUG" ]; then
646                 set -x;
647                 set -v;
648         fi
649
650         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
651                 echo "Version: $PACKAGE_VERSION"
652                 echo "Release: $PACKAGE_RELEASE"
653                 # Check whether first character of PACKAGE_NAME is legal for tag name
654                 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
655                         TAG_PREFIX=tag_
656                 fi
657                 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"`
658                 # Remove #kernel.version_release from TAGVER because tagging sources
659                 # could occur with different kernel-headers than kernel-headers used at build time.
660                 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
661                 if [ "$TAG_VERSION" = "yes" ]; then
662                         echo "CVS tag: $TAGVER"
663                 fi
664                 if [ -n "$TAG" ]; then
665                         echo "CVS tag: $TAG"
666                 fi
667
668                 OPTIONS="tag -F"
669                 if [ -n "$CVSROOT" ]; then
670                         OPTIONS="-d $CVSROOT $OPTIONS"
671                 fi
672
673                 cd $SOURCE_DIR
674                 for i in $TAG_FILES
675                 do
676                         # don't tag non cvs files (ie. stored on distfiles)
677                         [ "`nourl $i`" != "$i" ] && continue
678                         if [ -f "`nourl $i`" ]; then
679                                 if [ "$TAG_VERSION" = "yes" ]; then
680                                         cvs $OPTIONS $TAGVER `nourl $i`
681                                 fi
682                                 if [ -n "$TAG" ]; then
683                                         cvs $OPTIONS $TAG `nourl $i`
684                                 fi
685                         else
686                                 Exit_error err_no_source_in_repo $i
687                         fi
688                 done
689
690                 cd $SPECS_DIR
691                 if [ "$TAG_VERSION" = "yes" ]; then
692                         cvs $OPTIONS $TAGVER $SPECFILE
693                 fi
694                 if [ -n "$TAG" ]; then
695                         cvs $OPTIONS $TAG $SPECFILE
696                 fi
697
698                 unset OPTIONS
699         fi
700 }
701
702 branch_files()
703 {
704         TAG=$1
705         echo "CVS branch tag: $TAG"
706         shift;
707
708         TAG_FILES="$@"
709
710         if [ -n "$DEBUG" ]; then
711                 set -x;
712                 set -v;
713         fi
714
715         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
716
717                 OPTIONS="tag -b"
718                 if [ -n "$CVSROOT" ]; then
719                         OPTIONS="-d $CVSROOT $OPTIONS"
720                 fi
721                 cd $SOURCE_DIR
722                 for i in $TAG_FILES
723                 do
724                         if [ -f `nourl $i` ]; then
725                                 cvs $OPTIONS $TAG `nourl $i`
726                         else
727                                 Exit_error err_no_source_in_repo $i
728                         fi
729                 done
730                 cd $SPECS_DIR
731                 cvs $OPTIONS $TAG $SPECFILE
732
733                 unset OPTIONS
734         fi
735 }
736
737
738
739 build_package()
740 {
741         if [ -n "$DEBUG" ]; then
742                 set -x;
743                 set -v;
744         fi
745
746         cd $SPECS_DIR
747
748         if [ -n "$TRY_UPGRADE" ]; then
749                 if [ -n "$FLOAT_VERSION" ]; then
750                         TNOTIFY=`./pldnotify.awk $SPECFILE -n`
751                 else
752                         TNOTIFY=`./pldnotify.awk $SPECFILE`
753                 fi
754
755                 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
756
757                 if [ -n "$TNEWVER" ]; then
758                         TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
759                         echo "New version found, updating spec file to version " $TNEWVER
760                         cp -f $SPECFILE $SPECFILE.bak
761                         chmod +w $SPECFILE
762                         eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
763                         eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE"
764                         parse_spec;
765                         get_files "$SOURCES $PATCHES";
766                         unset TOLDVER TNEWVER TNOTIFY
767                 fi
768         fi
769         cd $SPECS_DIR
770
771         case "$COMMAND" in
772                 build )
773                         BUILD_SWITCH="-ba" ;;
774                 build-binary )
775                         BUILD_SWITCH="-bb" ;;
776                 build-source )
777                         BUILD_SWITCH="-bs --nodeps" ;;
778                 build-prep )
779                         BUILD_SWITCH="-bp --nodeps" ;;
780         esac
781         if [ -n "$LOGFILE" ]; then
782                 LOG=`eval echo $LOGFILE`
783                 if [ -n "$LASTLOG_FILE" ]; then
784                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
785                 fi
786                 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
787                 (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
788                 RETVAL=`cat $RES_FILE`
789                 rm $RES_FILE
790                 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
791                         if [ "$RETVAL" -eq "0" ]; then
792                                 mv $LOG $LOGDIROK
793                         else
794                                 mv $LOG $LOGDIRFAIL
795                         fi
796                 fi
797         else
798                 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE
799                 RETVAL=$?
800         fi
801         if [ "$RETVAL" -ne "0" ]; then
802                 if [ -n "$TRY_UPGRADE" ]; then
803                         echo "\n!!! Package with new version cannot be build automagically\n"
804                         mv -f $SPECFILE.bak $SPECFILE
805                 fi
806                 Exit_error err_build_fail;
807         fi
808         unset BUILD_SWITCH
809 }
810
811 nourl()
812 {
813         echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
814 }
815
816
817 install_required_packages()
818 {
819         run_poldek -vi $1
820         return $?
821 }
822
823 set_bconds_values()
824 {
825         AVAIL_BCONDS_WITHOUT=""
826         AVAIL_BCONDS_WITH=""
827         if `grep -q ^%bcond ${SPECFILE}`; then
828                 BCOND_VERSION="NEW"
829         elif `grep -q bcond ${SPECFILE}`; then
830                 BCOND_VERSION="OLD"
831         else
832                 BCOND_VERSION="NONE"
833         fi
834         case "${BCOND_VERSION}" in
835                  NONE)
836                         :
837                         ;;
838                  OLD)
839                         echo "Warning: This spec has old style bconds. Fix it || die."
840                         for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_`
841                         do
842                                 AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"`
843                                 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
844                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
845                                 else
846                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
847                                 fi
848                         done
849                 
850                         for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_`
851                         do
852                                 AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"`
853                                 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
854                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
855                                 else
856                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
857                                 fi
858                         done
859                         ;;
860                 NEW)
861                         cond_type="" # with || without
862                         for opt in `$RPMBUILD --bcond $SPECFILE`
863                         do
864                                 case "$opt" in
865                                         _without)
866                                                 cond_type="without"
867                                                 ;;
868                                         _with)
869                                                 cond_type="with"
870                                                 ;;
871                                         *)
872                                                 case "$cond_type" in
873                                                         with)
874                                                                 cond_type=''
875                                                                 AVAIL_BCOND_WITH="$opt"
876                                                                 if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then
877                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
878                                                                 else
879                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
880                                                                 fi
881                                                                 ;;
882                                                         without)
883                                                                 cond_type=''
884                                                                 AVAIL_BCOND_WITHOUT="$opt"
885                                                                 if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then
886                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
887                                                                 else
888                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
889                                                                 fi
890                                                                 ;;
891                                                 esac
892                                                 ;;
893                                 esac
894                         done
895                         ;;
896         esac
897 }
898
899 run_sub_builder()
900 {
901         package_name="${1}"
902         echo -ne "Package installation failed:\t$package_name\n"
903         #
904         # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
905         # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
906         # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
907         # jakby nie bylo tego kawalka kodu.
908         #
909         # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
910         #         Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
911         #
912         #
913         # y0shi.
914
915         parent_spec_name=''
916
917
918         # Istnieje taki spec? ${package}.spec
919         if [ -f "${SPECS_DIR}${package}.spec" ]; then
920                 parent_spec_name=${package}.spec
921         elif [ -f "${SPECS_DIR}`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
922                 parent_spec_name="`echo ${package_name}|sed -e s,-devel.*,,g -e s,-static,,g`.spec"
923         else
924                 for provides_line in `grep ^Provides:.*$package  ${SPECS_DIR} -R`
925                 do
926                         echo $provides_line
927                 done
928         fi
929
930         if [ "${parent_spec_name}" != "" ]; then
931                 sub_builder_opts=''
932                 if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
933                         sub_builder_opts="${sub_builder_opts} -R"
934                 fi
935                 if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
936                         sub_builder_opts="${sub_builder_opts} -RB"
937                 elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
938                         sub_builder_opts="${sub_builder_opts} -FRB"
939                 fi
940                 if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
941                         sub_builder_opts="${sub_builder_opts} -Upi"
942                 fi
943                 cd "${SPECS_DIR}"
944                 ./builder ${sub_builder_opts} ${parent_spec_name}
945         fi
946         NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
947 }
948
949 remove_build_requires()
950 {
951         if [ "$INSTALLED_PACKAGES" != "" ]; then
952                 case "$REMOVE_BUILD_REQUIRES" in
953                         "force")
954                                 run_poldek --noask -ve $INSTALLED_PACKAGES
955                                 ;;
956                         "nice")
957                                 run_poldek --ask -ve $INSTALLED_PACKAGES
958                                 ;;
959                         *)
960                                 echo You may want to manually remove following BuildRequires fetched:
961                                 echo $INSTALLED_PACKAGES
962                                 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
963                                 ;;
964                 esac
965         fi
966 }
967
968 display_bconds()
969 {
970         if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
971                 echo -ne "We are going to build $SPECFILE with the following conditional flags:\n"
972                 if [ "$BCOND" != "" ]; then
973                         echo -ne "$BCOND"
974                 else
975                         echo -ne "No --with || --without conditions passed to $0!"
976                 fi
977                 echo -ne "\n\nfrom available:\n\n"
978                 echo -ne "--with   :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
979         fi
980 }
981
982 fetch_build_requires()
983 {
984         if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
985                 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
986                 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
987                 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
988                 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
989                 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
990                 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,kgcc_package,gcc,g -e s,\),,g`
991                 do
992                         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`"
993                         GO="yes"
994                         package=`basename "$package_item"|sed -e "s/}$//g"`
995                         COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
996                         mach=`uname -m`
997                 
998                         COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
999                         if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1000                                 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
1001                                         GO="yes"
1002                                 fi
1003                         # bcond:
1004                         else
1005                                 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1006                                 GO=""
1007                                 # %{without}
1008                                 if `echo $COND_TST|grep -q 'without_'`; then
1009                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*_without_,,g`
1010                                         if `echo $COND_TST|grep -q !`; then
1011                                                 COND_STATE="with"
1012                                         else
1013                                                 COND_STATE="wout"
1014                                         fi
1015                                         if `echo $AVAIL_BCONDS_WITHOUT|grep -q "<$COND_NAME>"`; then
1016                                                 COND_ARGV="wout"
1017                                         else
1018                                                 COND_ARGV="with"
1019                                         fi
1020                                 # %{with}
1021                                 elif `echo $COND_TST|grep -q 'with_'`; then
1022                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*_with_,,g`
1023                                         if `echo $COND_TST|grep -q !`; then
1024                                                 COND_STATE="wout"
1025                                         else
1026                                                 COND_STATE="with"
1027                                         fi                                      
1028                                         if `echo $AVAIL_BCONDS_WITH|grep -q "<$COND_NAME>"`; then
1029                                                 COND_ARGV="with"
1030                                         else
1031                                                 COND_ARGV="wout"
1032                                         fi      
1033                                 fi
1034                                 RESULT="${COND_STATE}-${COND_ARGV}"
1035                                 case "$RESULT" in
1036                                         "with-wout" | "wout-with" )
1037                                                 GO=""
1038                                                 ;;
1039                                         "wout-wout" | "with-with" )
1040                                                 GO="yes"
1041                                                 ;;
1042                                         * )
1043                                                 echo "Action '$RESULT' was not defined for package '$package_item'"
1044                                                 GO="yes"
1045                                                 ;;
1046                                 esac
1047                         fi
1048
1049                         if [ "$GO" = "yes" ]; then
1050                                 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1051                                         echo "Testing if $package has subrequirements..."
1052                                         run_poldek -t -i $package --dumpn=".$package-req.txt"
1053                                         if [ -f ".$package-req.txt" ]; then
1054                                                 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1055                                                 do
1056                                                         if [ "$package_name" = "$package" ]; then
1057                                                                 echo -ne "Installing BuildRequired package:\t$package_name\n"
1058                                                                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing BuildRequired package: ${package_name}\007"`
1059                                                                 install_required_packages $package;
1060                                                         else
1061                                                                 echo -ne "Installing (sub)Required package:\t$package_name\n"
1062                                                                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}: Installing (sub)Required package: ${package_name}\007"`
1063                                                                 install_required_packages $package_name;
1064                                                         fi
1065                                                         case $? in
1066                                                                 0)
1067                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1068                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1069                                                                         ;;
1070                                                                 *)
1071                                                                         echo "Attempting to run spawn sub - builder..."
1072                                                                         run_sub_builder $package_name
1073                                                                         if [ $? -eq 0 ]; then
1074                                                                                 install_required_packages $package_name;
1075                                                                                 case $? in
1076                                                                                         0)
1077                                                                                                 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1078                                                                                                 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1079                                                                                                 ;;
1080                                                                                         *)
1081                                                                                                 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1082                                                                                                 ;;
1083                                                                                 esac
1084                                                                         fi
1085                                                                         ;;
1086                                                         esac
1087                                                 done
1088                                                 rm -f ".$package-req.txt"
1089                                         else
1090                                                 echo "Attempting to run spawn sub - builder..."
1091                                                 run_sub_builder $package
1092                                                 if [ $? -eq 0 ]; then
1093                                                         install_required_packages $package;
1094                                                         case $? in
1095                                                                 0)
1096                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1097                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1098                                                                         ;;
1099                                                                 *)
1100                                                                         NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1101                                                                         ;;
1102                                                         esac
1103                                                 fi
1104                                         fi
1105                                 else
1106                                         echo "Package $package is already installed. BuildRequirement satisfied."
1107                                 fi
1108                         fi
1109                 done
1110                 export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1111                 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1112                         echo "Nie uda³o siê zainstalowaæ nastêpuj±cych pakietów i ich zale¿no¶ci:"
1113                         for pkg in "$NOT_INSTALLED_PACKAGES"
1114                         do
1115                                 echo $pkg
1116                         done
1117                         remove_build_requires
1118                         exit 1
1119                 fi
1120         fi
1121 }
1122
1123 #---------------------------------------------
1124 # main()
1125
1126 if [ "$#" = 0 ]; then
1127         usage;
1128         exit 1
1129 fi
1130
1131 while test $# -gt 0
1132 do
1133         case "${1}" in
1134                 -5 | --update-md5 )
1135                         COMMAND="get";
1136                         NODIST="yes"
1137                         NOCVSSPEC="yes"
1138                         UPDATE5="yes"
1139                         shift ;;
1140                 -a5 | --add-md5 )
1141                         COMMAND="get";
1142                         NODIST="yes"
1143                         NOCVS="yes"
1144                         NOCVSSPEC="yes"
1145                         UPDATE5="yes"
1146                         ADD5="yes"
1147                         shift ;;
1148                 -D | --debug )
1149                         DEBUG="yes"; shift ;;
1150                 -V | --version )
1151                         COMMAND="version"; shift ;;
1152                 -a | --as_anon )
1153                         CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1154                 -b | -ba | --build )
1155                         COMMAND="build"; shift ;;
1156                 -bb | --build-binary )
1157                         COMMAND="build-binary"; shift ;;
1158                 -bs | --build-source )
1159                         COMMAND="build-source"; shift ;;
1160                 -bp | --build-prep )
1161                         COMMAND="build-prep"; shift ;;
1162                 -B | --branch )
1163                         COMMAND="branch"; shift; TAG="${1}"; shift;;
1164                 -c | --clean )
1165                         CLEAN="--clean --rmspec --rmsource"; shift ;;
1166                 -d | --cvsroot )
1167                         shift; CVSROOT="${1}"; shift ;;
1168                 -g | --get )
1169                         COMMAND="get"; shift ;;
1170                 -h | --help )
1171                         COMMAND="usage"; shift ;;
1172                 --http )
1173                         PROTOCOL="http"; shift ;;
1174                 -l | --logtofile )
1175                         shift; LOGFILE="${1}"; shift ;;
1176                 -ni| --nice )
1177                         shift; DEF_NICE_LEVEL=${1}; shift ;;
1178                 -m | --mr-proper )
1179                         COMMAND="mr-proper"; shift ;;
1180                 -nc | --no-cvs )
1181                         NOCVS="yes"; shift ;;
1182                 -ncs | --no-cvs-specs )
1183                         NOCVSSPEC="yes"; shift ;;
1184                 -nd | --no-distfiles )
1185                         NODIST="yes"; shift ;;
1186                 -nm | --no-mirrors )
1187                         NOMIRRORS="yes"; shift ;;
1188                 -nu | --no-urls )
1189                         NOURLS="yes"; shift ;;
1190                 -ns | --no-srcs )
1191                         NOSRCS="yes"; shift ;;
1192                 -ns0 | --no-source0 )
1193                         NOSOURCE0="yes"; shift ;;
1194                 --opts )
1195                         shift; RPMOPTS="${1}"; shift ;;
1196                 --with | --without )
1197                         case $GROUP_BCONDS in
1198                                 "yes")
1199                                         COND=${1}
1200                                         shift
1201                                         while ! `echo ${1}|grep -qE '(^-|spec)'`
1202                                         do
1203                                                 BCOND="$BCOND $COND $1"
1204                                                 shift
1205                                         done;;
1206                                 "no")
1207                                         BCOND="$BCOND $1 $2" ; shift 2 ;;
1208                         esac
1209                         ;;
1210                 -q | --quiet )
1211                         QUIET="--quiet"; shift ;;
1212                 --date )
1213                         CVSDATE="${2}"; shift 2 ;;
1214                 -r | --cvstag )
1215                         shift; CVSTAG="${1}"; shift ;;
1216                 -R | --fetch-build-requires)
1217                         FETCH_BUILD_REQUIRES="yes"
1218                         NOT_INSTALLED_PACKAGES=
1219                         shift ;;
1220                 -RB | --remove-build-requires)
1221                         REMOVE_BUILD_REQUIRES="nice"
1222                         shift ;;
1223                 -FRB | --force-remove-build-requires)
1224                         REMOVE_BUILD_REQUIRES="force"
1225                         shift ;;
1226                 -Tvs | --tag-version-stable )
1227                         COMMAND="tag";
1228                         TAG="STABLE"
1229                         TAG_VERSION="yes"
1230                         shift;;
1231                 -Tvn | --tag-version-nest )
1232                         COMMAND="tag";
1233                         TAG="NEST"
1234                         TAG_VERSION="yes"
1235                         shift;;
1236                 -Ts | --tag-stable )
1237                         COMMAND="tag";
1238                         TAG="STABLE"
1239                         TAG_VERSION="no"
1240                         shift;;
1241                 -Tn | --tag-nest )
1242                         COMMAND="tag";
1243                         TAG="NEST"
1244                         TAG_VERSION="no"
1245                         shift;;
1246                 -Tv | --tag-version )
1247                         COMMAND="tag";
1248                         TAG=""
1249                         TAG_VERSION="yes"
1250                         shift;;
1251                 -Tp | --tag-prefix )
1252                         TAG_PREFIX="$2"
1253                         shift 2;;
1254                 -T | --tag )
1255                         COMMAND="tag";
1256                         shift
1257                         TAG="$1"
1258                         TAG_VERSION="no"
1259                         shift;;
1260                 -U | --update )
1261                         COMMAND="get"
1262                         UPDATE="yes"
1263                         NOCVSSPEC="yes"
1264                         NODIST="yes"
1265                         UPDATE5="yes"
1266                         shift ;;
1267                 -Upi | --update-poldek-indexes )
1268                         UPDATE_POLDEK_INDEXES="yes"
1269                         shift ;;
1270                 -u | --try-upgrade )
1271                         TRY_UPGRADE="1"; shift ;;
1272                 -un | --try-upgrade-with-float-version )
1273                         TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1274                 -v | --verbose )
1275                         BE_VERBOSE="1"; shift ;;
1276                 --define)
1277                         shift
1278                         MACRO="${1}"
1279                         VALUE="${2}"
1280                         shift 2
1281                         RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1282                         ;;
1283                 --nodeps)
1284                         shift
1285                         RPMOPTS="${RPMOPTS} --nodeps"
1286                         ;;
1287                 * )
1288                         SPECFILE="`basename ${1} .spec`.spec";
1289                         export PROMPT_COMMAND=`echo -ne "\033]0;${SPECFILE}\007"`
1290                         shift ;;
1291         esac
1292 done
1293
1294 if [ -n "$DEBUG" ]; then
1295         set -x;
1296         set -v;
1297 fi
1298
1299 case "$COMMAND" in
1300         "build" | "build-binary" | "build-source" | "build-prep" )
1301                 init_builder;
1302                 if [ -n "$SPECFILE" ]; then
1303                 get_spec;
1304                 set_bconds_values;
1305                 display_bconds;
1306                 fetch_build_requires;
1307                 parse_spec;
1308
1309                 if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then
1310                         TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
1311                         CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }')
1312                         TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1313
1314                         if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then
1315                                 Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL"
1316                         fi
1317                 fi
1318
1319                 if [ -n "$ICONS" ]; then
1320                         get_files $ICONS;
1321                         parse_spec;
1322                 fi
1323                 if [ -n "$NOSOURCE0" ] ; then
1324                         SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1325                 fi
1326                 get_files "$SOURCES $PATCHES";
1327                 build_package;
1328                 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ]; then
1329                         run_poldek --sn ${POLDEK_SOURCE} --mkidx="${POLDEK_INDEX_DIR}/packages.dir.gz"
1330                         run_poldek --sn ${POLDEK_SOURCE} --up
1331                 fi
1332                 remove_build_requires;
1333         else
1334                 Exit_error err_no_spec_in_cmdl;
1335         fi
1336         ;;
1337         "branch" )
1338                 init_builder;
1339                 if [ -n "$SPECFILE" ]; then
1340                         get_spec;
1341                         parse_spec;
1342                         if [ -n "$ICONS" ]; then
1343                                 get_files $ICONS
1344                                 parse_spec;
1345                         fi
1346                         get_files $SOURCES $PATCHES;
1347                         branch_files $TAG "$SOURCES $PATCHES $ICONS";
1348                 else
1349                         Exit_error err_no_spec_in_cmdl;
1350                 fi
1351                 ;;
1352         "get" )
1353                 init_builder;
1354                 if [ -n "$SPECFILE" ]; then
1355                         get_spec;
1356                         parse_spec;
1357                         if [ -n "$ICONS" ]; then
1358                                 get_files $ICONS
1359                                 parse_spec;
1360                         fi
1361                         if [ -n "$NOSOURCE0" ] ; then
1362                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1363                         fi
1364                         get_files $SOURCES $PATCHES
1365                 else
1366                         Exit_error err_no_spec_in_cmdl;
1367                 fi
1368                 ;;
1369         "tag" )
1370                 init_builder;
1371                 if [ -n "$SPECFILE" ]; then
1372                         get_spec;
1373                         parse_spec;
1374                         if [ -n "$ICONS" ]; then
1375                                 get_files $ICONS
1376                                 parse_spec;
1377                         fi
1378                         # don't fetch sources from remote locations
1379                         new_SOURCES=""
1380                         for file in $SOURCES
1381                         do
1382                                 [ "`nourl $file`" != "$file" ] && continue
1383                                 new_SOURCES="$new_SOURCES $file"
1384                         done
1385                         SOURCES="$new_SOURCES"
1386                         get_files $SOURCES $PATCHES;
1387                         tag_files "$SOURCES $PATCHES $ICONS";
1388                 else
1389                         Exit_error err_no_spec_in_cmdl;
1390                 fi
1391                 ;;
1392         "mr-proper" )
1393                 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1394                 ;;
1395         "usage" )
1396                 usage;;
1397         "version" )
1398                 echo "$VERSION";;
1399 esac
1400 test -f `pwd`/.${SPECFILE}_INSTALLED_PACKAGES && rm `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1401 cd "$__PWD"
1402
1403 # vi:syntax=sh:ts=3:sw=4
This page took 0.1443 seconds and 4 git commands to generate.