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