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