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