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