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