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