]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
1071166662d4690d10b0bbadc381a777bd18cb26
[packages/rpm-build-tools.git] / builder.sh
1 #!/bin/sh
2 # -----------
3 # $Id$
4 # Exit codes:
5 #         0 - succesful
6 #         1 - help displayed
7 #         2 - no spec file name in cmdl parameters
8 #         3 - spec file not stored in repo
9 #         4 - some source, patch or icon files not stored in repo
10 #         5 - package build failed
11 #         6 - spec file with errors
12 #         7 - wrong source in /etc/poldek.conf
13 #         8 - Failed installing buildrequirements and subrequirements
14 #         9 - Requested tag already exist
15 #        10 - Refused to build fractional release
16 #       100 - Unknown error (should not happen)
17
18 # Notes (todo):
19 #       - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
20 #       - when Icon: field is present, -5 and -a5 doesn't work
21 #       - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
22
23 VERSION="\
24 Build package utility from PLD Linux CVS repository
25 V 0.13 (C) 1999-2005 Free Penguins".
26 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
27
28 COMMAND="build"
29 TARGET=""
30
31 SPECFILE=""
32 BE_VERBOSE=""
33 QUIET=""
34 CLEAN=""
35 DEBUG=""
36 NOURLS=""
37 NOCVS=""
38 NOCVSSPEC=""
39 NODIST=""
40 UPDATE=""
41 UPDATE5=""
42 ADD5=""
43 NO5=""
44 ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
45 CVSROOT=""
46
47 # It can be used i.e. in log file naming.
48 # See LOGFILE example.
49 DATE=`date +%Y-%m-%d_%H-%M-%S`
50
51 # Example: LOGFILE='../log.$PACKAGE_NAME'
52 # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
53 # Yes, you can use variable name! Note _single_ quotes!
54 LOGFILE=''
55
56 LOGDIR=""
57 LOGDIROK=""
58 LOGDIRFAIL=""
59 LASTLOG_FILE=""
60
61 CHMOD="no"
62 CHMOD_MODE="0444"
63 RPMOPTS=""
64 BCOND=""
65 GROUP_BCONDS="no"
66 CVSIGNORE_DF="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 ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
84
85 DEF_NICE_LEVEL=19
86
87 FAIL_IF_NO_SOURCES="yes"
88
89 # let get_files skip over files which are present to get those damn files fetched
90 SKIP_EXISTING_FILES="no"
91
92 if [ -x /usr/bin/rpm-getdeps ]; then
93          FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
94 else
95          FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
96 fi
97
98 # Here we load saved user environment used to
99 # predefine options set above, or passed to builder
100 # in command line.
101 # This one reads global system environment settings:
102 if [ -f ~/etc/builderrc ]; then
103         . ~/etc/builderrc
104 fi
105 # And this one cascades settings using user personal
106 # builder settings.
107 # Example of ~/.builderrc:
108 #
109 #UPDATE_POLDEK_INDEXES="yes"
110 #FETCH_BUILD_REQUIRES="yes"
111 #REMOVE_BUILD_REQUIRES="force"
112 #GROUP_BCONDS="yes"
113 #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
114 #
115 SU_SUDO=""
116 if [ -n "$HOME_ETC" ]; then
117         USER_CFG="$HOME_ETC/.builderrc"
118 else
119         USER_CFG=~/.builderrc
120 fi
121
122 [ -f "$USER_CFG" ] && . "$USER_CFG"
123
124 wget --help 2>&1 | grep -q ' \-\-no-check\-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
125
126 if [ -n "$USE_PROZILLA" ]; then
127         GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
128         GETURI2="$GETURI"
129         OUTFILEOPT="-O"
130 elif [ -n "$USE_AXEL" ]; then
131         GETURI="axel -a $AXEL_OPTS"
132         GETURI2="$GETURI"
133         OUTFILEOPT="-o"
134 else
135         wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
136         wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
137
138         GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
139         GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
140         OUTFILEOPT="-O"
141 fi
142
143 GETLOCAL="cp -a"
144
145 if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
146         RPM="rpm"
147         RPMBUILD="rpm"
148 else
149         RPM="rpm"
150         RPMBUILD="rpmbuild"
151 fi
152
153 POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
154 POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
155
156 run_poldek()
157 {
158         RES_FILE=~/tmp/poldek-exit-status.$RANDOM
159         if [ -n "$LOGFILE" ]; then
160                 LOG=`eval echo $LOGFILE`
161                 if [ -n "$LASTLOG_FILE" ]; then
162                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
163                 fi
164                 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
165                 return $exit_pldk
166         else
167                 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
168                 return `cat ${RES_FILE}`
169                 rm -rf ${RES_FILE}
170         fi
171 }
172
173 #---------------------------------------------
174 # functions
175
176 usage()
177 {
178         if [ -n "$DEBUG" ]; then set -xv; fi
179         echo "\
180 Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
181
182 [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
183 [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
184 [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
185 [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
186 [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
187 [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
188 [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
189 [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds]
190 [--with/--without <feature>] [--define <macro> <value>] <package>[.spec][:cvstag]
191
192 -5, --update-md5    - update md5 comments in spec, implies -nd -ncs
193 -a5, --add-md5      - add md5 comments to URL sources, implies -nc -nd -ncs
194 -n5, --no-md5       - ignore md5 comments in spec
195 -D, --debug         - enable builder script debugging mode,
196 -debug              - produce rpm debug package (same as --opts -debug)
197 -V, --version       - output builder version
198 -a, --as_anon       - get files via pserver as cvs@$CVS_SERVER,
199 -b, -ba, --build    - get all files from CVS repo or HTTP/FTP and build package
200                       from <package>.spec,
201 -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
202                       only package from <package>.spec,
203 -bp, --build-prep   - execute the %prep phase of <package>.spec,
204 -bc                 - reserved (not implemented)
205 -bi                   reserved (not implemented)
206 -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
207                       them into src.rpm,
208 --short-circuit     - reserved (not implemented)
209 -B, --branch        - add branch
210 -c, --clean         - clean all temporarily created files (in BUILD, SOURCES,
211                       SPECS and \$RPM_BUILD_ROOT),
212 -d <cvsroot>, --cvsroot <cvsroot>
213                     - setup \$CVSROOT,
214 --define <macro> <value>
215                     - define a macro <macro> with value <value>,
216 --nodeps            - rpm won't check any dependences
217 -g, --get           - get <package>.spec and all related files from CVS repo
218                       or HTTP/FTP,
219 -h, --help          - this message,
220 --http              - use http instead of ftp,
221 -l <logfile>, --logtofile <logfile>
222                     - log all to file,
223 -m, --mr-proper     - only remove all files related to spec file and all work
224                       resources,
225 -nc, --no-cvs       - don't download sources from CVS, if source URL is given,
226 -ncs, --no-cvs-specs
227                     - don't check specs in CVS
228 -nd, --no-distfiles - don't download from distfiles
229 -nm, --no-mirrors   - don't download from mirror, if source URL is given,
230 -nu, --no-urls      - don't try to download from FTP/HTTP location,
231 -ns, --no-srcs      - don't download Sources
232 -ns0, --no-source0  - don't download Source0
233 -nn, --no-net       - don't download anything from the net
234 -ske,
235 --skip-existing-files - skip existing files in get_files
236 --opts <rpm opts>   - additional options for rpm
237 -q, --quiet         - be quiet,
238 --date yyyy-mm-dd   - build package using resources from specified CVS date,
239 -r <cvstag>, --cvstag <cvstag>
240                     - build package using resources from specified CVS tag,
241 -R, --fetch-build-requires
242                     - fetch what is BuildRequired,
243 -RB, --remove-build-requires
244                     - remove all you fetched with -R or --fetch-build-requires
245                       remember, this option requires confirmation,
246 -FRB, --force-remove-build-requires
247                     - remove all you fetched with -R or --fetch-build-requires
248                       remember, this option works without confirmation,
249 -sf, --source-files - list sources - bare filenames (intended for offline
250                       operations; does not work when Icon field is present
251                                                          but icon file is absent),
252 -sp, --source-paths - list sources - filenames with full local paths (intended for
253                       offline operations; does not work when Icon field is present
254                                                          but icon file is absent),
255 -su, --source-urls  - list urls - urls to sources and patches
256                       intended for copying urls with spec with lots of macros in urls
257 -T <cvstag> , --tag <cvstag>
258                     - add cvs tag <cvstag> for files,
259 -Tvs, --tag-version-stable
260                     - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
261 -Tvn, --tag-version-nest
262                     - add cvs tags NEST and NAME-VERSION-RELEASE for files,
263 -Ts, --tag-stable
264                     - add cvs tag STABLE for files,
265 -Tn, --tag-nest
266                     - add cvs tag NEST for files,
267 -Tv, --tag-version
268                     - add cvs tag NAME-VERSION-RELEASE for files,
269 -Tp, --tag-prefix <prefix>
270                     - add <prefix> to NAME-VERSION-RELEASE tags,
271 -tt, --test-tag <prefix>
272                     - fail if tag is already present,
273 -ir, --integer-release-only
274                     - allow only integer and snapshot releases
275 -v, --verbose       - be verbose,
276 -u, --try-upgrade   - check version, and try to upgrade package
277 -un, --try-upgrade-with-float-version
278                     - as above, but allow float version
279 -U, --update        - refetch sources, don't use distfiles, and update md5 comments
280 -Upi, --update-poldek-indexes
281                     - refresh or make poldek package index files.
282 -np, --nopatch <patchnumber>
283                     - don't apply <patchnumber>
284 --show-bconds       - show available conditional builds, which can be used
285                     - with --with and/or --without switches.
286 --with/--without <feature>
287                     - conditional build package depending on %_with_<feature>/
288                       %_without_<feature> macro switch.  You may now use
289                       --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
290                       constructions. Set GROUP_BCONDS to yes to make use of it.
291 --target <platform>, --target=<platform>
292                     - build for platform <platform>.
293 "
294 }
295
296 update_shell_title() {
297         [ -t 1 ] || return
298         local len=${COLUMNS:-80}
299         local msg=$(echo "$*" | cut -c-$len)
300
301         msg="builder[$SPECFILE] ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
302         case "$TERM" in
303                 cygwin|xterm*)
304                 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
305         ;;
306                 screen*)
307                 echo >&2 -ne "\033]0;$msg\007"
308         ;;
309         esac
310 }
311
312 # set TARGET from BuildArch: from SPECFILE
313 set_spec_target() {
314          if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
315                   tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
316                   if [ "$tmp" ]; then
317                                 TARGET="$tmp"
318                                 case "$RPMBUILD" in
319                                 "rpmbuild")
320                                          TARGET_SWITCH="--target $TARGET" ;;
321                                 "rpm")
322                                          TARGET_SWITCH="--target=$TARGET" ;;
323                                 esac
324                   fi
325          fi
326 }
327
328 cache_rpm_dump () {
329          if [ -n "$DEBUG" ]; then
330                   set -x;
331                   set -v;
332          fi
333
334         update_shell_title "cache_rpm_dump"
335 rpm_dump_cache=`
336         # we reset macros not to contain macros.build as all the %() macros are
337         # executed here, while none of them are actually needed
338         # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
339         # macros.build + macros contained at the time of this writing 70 %() macros
340         local macrofiles='/usr/lib/rpm/macros:~/etc/.rpmmacros:~/.rpmmacros'
341         local dump='prep %{echo:z: PACKAGE_NAME %{name} }%dump'
342         case "$RPMBUILD" in
343                 rpm )
344                         echo -e "include:/usr/lib/rpm/rpmrc\nmacrofiles:$macrofiles" | \
345                         rpm --rcfile - -bp --nodeps --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1
346                         ;;
347                 rpmbuild )
348                         echo -e "include:/usr/lib/rpm/rpmrc\nmacrofiles:$macrofiles" | \
349                         rpmbuild --rcfile - --nodigest --nosignature --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1
350                         ;;
351         esac`
352         update_shell_title "cache_rpm_dump: OK!"
353 }
354
355 rpm_dump () {
356         if [ -z "$rpm_dump_cache" ] ; then
357                 echo "internal error: cache_rpm_dump not called!" 1>&2
358         fi
359         echo "$rpm_dump_cache"
360 }
361
362 parse_spec()
363 {
364         update_shell_title "parsing specfile"
365         if [ -n "$DEBUG" ]; then
366                 set -x;
367                 set -v;
368         fi
369
370         cd $SPECS_DIR
371         cache_rpm_dump
372
373         if [ "$NOSRCS" != "yes" ]; then
374                 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
375         fi
376         if (rpm_dump | grep -qEi ":.*nosource.*1"); then
377                 FAIL_IF_NO_SOURCES="no"
378         fi
379
380         PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
381         ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
382         PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3}')
383         PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3}')
384         PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3}')
385
386         if [ -n "$BE_VERBOSE" ]; then
387                 echo "- Sources :  `nourl $SOURCES`"
388                 if [ -n "$PATCHES" ]; then
389                         echo "- Patches :  `nourl $PATCHES`"
390                 else
391                         echo "- Patches :  *no patches needed*"
392                 fi
393                 if [ -n "$ICONS" ]; then
394                         echo "- Icon    :  `nourl $ICONS`"
395                 else
396                         echo "- Icon    :  *no package icon*"
397                 fi
398                 echo "- Name    : $PACKAGE_NAME"
399                 echo "- Version : $PACKAGE_VERSION"
400                 echo "- Release : $PACKAGE_RELEASE"
401         fi
402
403         update_shell_title "parse_spec: OK!"
404 }
405
406 Exit_error()
407 {
408         if [ -n "$DEBUG" ]; then
409                 set -x;
410                 set -v;
411         fi
412
413         cd "$__PWD"
414
415         case "$1" in
416                 "err_no_spec_in_cmdl" )
417                         remove_build_requires
418                         echo "ERROR: spec file name not specified.";
419                         exit 2 ;;
420                 "err_no_spec_in_repo" )
421                         remove_build_requires
422                         echo "Error: spec file not stored in CVS repo.";
423                         exit 3 ;;
424                 "err_no_source_in_repo" )
425                         remove_build_requires
426                         echo "Error: some source, patch or icon files not stored in CVS repo. ($2)";
427                         exit 4 ;;
428                 "err_build_fail" )
429                         remove_build_requires
430                         echo "Error: package build failed. (${2:-no more info})";
431                         exit 5 ;;
432                 "err_no_package_data" )
433                         remove_build_requires
434                         echo "Error: couldn't get out package name/version/release from spec file."
435                         exit 6 ;;
436            "err_tag_exists" )
437                         remove_build_requires
438                         echo "Tag ${2} already exists (spec release: ${3}).";
439                         exit 9 ;;
440            "err_fract_rel" )
441                         remove_build_requires
442                         echo "Release ${2} not integer and not a snapshot.";
443                         exit 10 ;;
444                 "err_branch_exists" )
445                         remove_build_requires
446                         echo "Tree branch already exists (${2}).";
447                         exit 11 ;;
448
449         esac
450    echo "Unknown error."
451    exit 100
452 }
453
454 init_builder()
455 {
456         if [ -n "$DEBUG" ]; then
457                 set -x;
458                 set -v;
459         fi
460
461         SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`"
462         SPECS_DIR="`$RPM --eval '%{_specdir}'`"
463
464         __PWD="`pwd`"
465 }
466
467 get_spec()
468 {
469
470         update_shell_title "get_spec"
471
472         if [ -n "$DEBUG" ]; then
473                 set -x;
474                 set -v;
475         fi
476
477         cd "$SPECS_DIR"
478         if [ ! -f "$SPECFILE" ]; then
479                 SPECFILE="`basename $SPECFILE .spec`.spec";
480         fi
481         if [ "$NOCVSSPEC" != "yes" ]; then
482
483                 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
484                         echo "Warning: No CVS access defined - using local .spec file"
485                         NOCVSSPEC="yes"
486                 fi
487
488                 cvsup "$SPECFILE" || Exit_error err_no_spec_in_repo
489         fi
490
491         if [ ! -f "$SPECFILE" ]; then
492                 Exit_error err_no_spec_in_repo;
493         fi
494
495         if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
496                 chmod $CHMOD_MODE $SPECFILE
497         fi
498         unset OPTIONS
499         [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
500
501          set_spec_target
502 }
503
504 find_mirror()
505 {
506         cd "$SPECS_DIR"
507         url="$1"
508         if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
509                 cvs update mirrors >&2
510         fi
511
512         IFS="|"
513         while read origin mirror name rest
514         do
515                 ol=`echo -n "$origin"|wc -c`
516                 prefix="`echo -n "$url" | head -c $ol`"
517                 if [ "$prefix" = "$origin" ] ; then
518                         suffix="`echo "$url"|cut -b $ol-`"
519                         echo -n "$mirror$suffix"
520                         return 0
521                 fi
522         done < mirrors
523         echo "$url"
524 }
525
526 src_no ()
527 {
528         cd $SPECS_DIR
529         rpm_dump | \
530         grep "SOURCEURL[0-9]*[  ]*$1""[         ]*$" | \
531         sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
532         head -n 1 | xargs
533 }
534
535 src_md5 ()
536 {
537         [ X"$NO5" = X"yes" ] && return
538         no=$(src_no "$1")
539         [ -z "$no" ] && return
540         cd $SPECS_DIR
541         spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
542         if [ -z "$spec_rev" ]; then
543                 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
544         fi
545         spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
546         md5=$(grep -s -v '^#' additional-md5sums | \
547         grep -E "[      ]$(basename "$1")[      ]+${spec}([     ,]|\$)" | \
548         sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
549         grep -E '^[0-9a-f]{32}$')
550         if [ X"$md5" = X"" ] ; then
551                 source_md5=`grep -i "#[         ]*Source$no-md5[        ]*:" $SPECFILE | sed -e 's/.*://'`
552                 if [ ! -z "$source_md5" ] ; then
553                         echo $source_md5;
554                 else
555                         # we have empty SourceX-md5, but it is still possible
556                         # that we have NoSourceX-md5 AND NoSource: X
557                         nosource_md5=`grep -i "#[        ]*NoSource$no-md5[      ]*:" $SPECFILE | sed -e 's/.*://'`
558                         if [ ! -z "$nosource_md5" -a ! X"`grep -i "^NoSource:[   ]*$no$" $SPECFILE`" = X"" ] ; then
559                                 echo $nosource_md5;
560                         fi;
561                 fi;
562         else
563                 if [ $(echo "$md5" | wc -l) != 1 ] ; then
564                         echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
565                 fi
566                 echo "$md5" | tail -n 1
567         fi
568 }
569
570 distfiles_url ()
571 {
572         echo "$PROTOCOL$DISTFILES_SERVER/distfiles/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
573 }
574
575 distfiles_attic_url ()
576 {
577         echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
578 }
579
580 good_md5 ()
581 {
582         md5=$(src_md5 "$1")
583         [ "$md5" = "" ] || \
584         [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
585 }
586
587 good_size ()
588 {
589          size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
590          [ -n "$size" -a "$size" -gt 0 ]
591 }
592
593 cvsignore_df ()
594 {
595         if [ "$CVSIGNORE_DF" != "yes" ]; then
596                 return
597         fi
598         cvsignore=${SOURCE_DIR}/.cvsignore
599         if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
600                 echo "$1" >> $cvsignore
601         fi
602 }
603
604 cvsup()
605 {
606          update_shell_title "cvsup"
607          local OPTIONS="up "
608          if [ -n "$CVSROOT" ]; then
609                   OPTIONS="-d $CVSROOT $OPTIONS"
610          fi
611
612          if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
613                   OPTIONS="$OPTIONS -A"
614          else
615                   if [ -n "$CVSDATE" ]; then
616                                 OPTIONS="$OPTIONS -D $CVSDATE"
617                   fi
618                   if [ -n "$CVSTAG" ]; then
619                                 OPTIONS="$OPTIONS -r $CVSTAG"
620                   fi
621          fi
622
623          local result=1
624          local retries_counter=0
625          update_shell_title "cvsup: $# files"
626          while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
627                   retries_counter=$(( $retries_counter + 1 ))
628                   output=$(LC_ALL=C cvs $OPTIONS "$@" 2>&1)
629                   result=$?
630                   [ -n "$output" ] && echo "$output"
631                   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
632                                 echo "Trying again [$*]... ($retries_counter)"
633                                 update_shell_title "cvsup: retry #$retries_counter"
634                                 sleep 2
635                                 continue
636                   else
637                                 break
638                   fi
639          done
640          update_shell_title "cvsup: done!"
641          return $result
642 }
643
644 get_files()
645 {
646         update_shell_title "fetching sources"
647
648         if [ -n "$DEBUG" ]; then
649                 set -x;
650                 set -v;
651         fi
652
653         if [ $# -gt 0 ]; then
654                 cd "$SOURCE_DIR"
655
656                 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
657                         echo "Warning: No CVS access defined for SOURCES"
658                         NOCVS="yes"
659                 fi
660
661                 local nc=0
662                 local get_files_cvs=""
663                 for i in "$@"; do
664                         nc=$((nc + 1))
665                         local cvsup=0
666                         SHELL_TITLE_PREFIX="get_files[$nc/$#]"
667                         update_shell_title "$i"
668                         local fp=`nourl "$i"`
669                         if [ -f "$fp" ] && [ "$SKIP_EXISTING_FILES" = "yes" ]; then
670                                  continue
671                         fi
672                         if [ -n "$UPDATE5" ]; then
673                                 if [ -n "$ADD5" ]; then
674                                         [ "$fp" = "$i" ] && continue
675                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE && continue
676                                 else
677                                         grep -qiE '^#[  ]*Source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE || continue
678                                 fi
679                         fi
680                         FROM_DISTFILES=0
681                         if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
682                                 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
683                                         echo "Warning: no URL given for $i"
684                                 fi
685
686                                 if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then
687                                         if good_md5 "$i" && good_size "$i"; then
688                                                 echo "$(nourl "$i") having proper md5sum already exists"
689                                                 continue
690                                         fi
691                                         target="$fp"
692                                         url=$(distfiles_url "$i")
693                                         url_attic=$(distfiles_attic_url "$i")
694                                         FROM_DISTFILES=1
695                                         if [ "`echo $url | grep -E '^(\.|/)'`" ]; then
696                                                 update_shell_title "${GETLOCAL%% *}: $url"
697                                                 ${GETLOCAL} $url $target
698                                         else
699                                                 if [ -z "$NOMIRRORS" ]; then
700                                                         url="`find_mirror "$url"`"
701                                                 fi
702                                                 update_shell_title "${GETURI%% *}: $url"
703                                                 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
704                                                 if [ "`echo $url | grep -E 'ftp://'`" ]; then
705                                                         update_shell_title "${GETURI2%% *}: $url"
706                                                         ${GETURI2} ${OUTFILEOPT} "$target" "$url"
707                                                 fi
708                                         fi
709                                         if ! test -s "$target"; then
710                                                 rm -f "$target"
711                                                 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
712                                                         update_shell_title "${GETLOCAL%% *}: $url_attic"
713                                                         ${GETLOCAL} $url_attic $target
714                                                 else
715                                                         if [ -z "$NOMIRRORS" ]; then
716                                                                 url_attic="`find_mirror "$url_attic"`"
717                                                         fi
718                                                         update_shell_title "${GETURI%% *}: $url_attic"
719                                                         ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
720                                                         if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
721                                                                  update_shell_title "${GETURI2%% *}: $url_attic"
722                                                                 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
723                                                         fi
724                                                 fi
725                                         fi
726                                         if test -s "$target"; then
727                                                 cvsignore_df $target
728                                         else
729                                                 rm -f "$target"
730                                                 FROM_DISTFILES=0
731                                         fi
732                                 elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then
733                                     get_files_cvs="$get_files_cvs $fp"
734                                         # we'll do cvs up later
735                                         cvsup=1
736                                 fi
737
738                                 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
739                                         if [ -z "$NOMIRRORS" ]; then
740                                                 im="`find_mirror "$i"`"
741                                         else
742                                                 im="$i"
743                                         fi
744                                         update_shell_title "${GETURI%% *}: $im"
745                                         ${GETURI} "$im" || \
746                                         if [ "`echo $im | grep -E 'ftp://'`" ]; then
747                                                  update_shell_title "${GETURI2%% *}: $im"
748                                                 ${GETURI2} "$im"
749                                         fi
750                                 fi
751
752                                 if [ "$cvsup" = 1 ]; then
753                                         continue
754                                 fi
755
756                         fi
757                         srcno=$(src_no $i)
758                         if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
759                                 Exit_error err_no_source_in_repo $i;
760                         elif [ -n "$UPDATE5" ] && \
761                                 ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \
762                                 [ -z "$(grep -E -i '^NoSource[  ]*:[    ]*'$i'([        ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \
763                                 grep -q -i -E '^#[      ]*source'$(src_no $i)'-md5[     ]*:' $SPECS_DIR/$SPECFILE )
764                         then
765                                 echo "Updating source-$srcno md5."
766                                 md5=$(md5sum "$fp" | cut -f1 -d' ')
767                                 perl -i -ne '
768                                 print unless /^\s*#\s*Source'$srcno'-md5\s*:/i;
769                                 print "# Source'$srcno'-md5:\t'$md5'\n"
770                                 if /^Source'$srcno'\s*:\s+/;
771                                 ' \
772                                 $SPECS_DIR/$SPECFILE
773                         fi
774
775                         if good_md5 "$i" && good_size "$i"; then
776                                 :
777                         elif [ "$FROM_DISTFILES" = 1 ]; then
778                                 # wrong md5 from distfiles: remove the file and try again
779                                 # but only once ...
780                                 echo "MD5 sum mismatch. Trying full fetch."
781                                 FROM_DISTFILES=2
782                                 rm -f $target
783                                 update_shell_title "${GETURI%% *}: $url"
784                                 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
785                                 if [ "`echo $url | grep -E 'ftp://'`" ]; then
786                                          update_shell_title "${GETURI2%% *}: $url"
787                                         ${GETURI2} ${OUTFILEOPT} "$target" "$url"
788                                 fi
789                                 if ! test -s "$target"; then
790                                         rm -f "$target"
791                                         update_shell_title "${GETURI%% *}: $url_attic"
792                                         ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
793                                         if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
794                                                  update_shell_title "${GETURI2%% *}: $url_attic"
795                                                 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
796                                         fi
797                                 fi
798                                 test -s "$target" || rm -f "$target"
799                         fi
800
801                         if good_md5 "$i" && good_size "$i" ; then
802                                 :
803                         else
804                                 echo "MD5 sum mismatch or 0 size.  Use -U to refetch sources,"
805                                 echo "or -5 to update md5 sums, if you're sure files are correct."
806                                 Exit_error err_no_source_in_repo $i
807                         fi
808                 done
809                 SHELL_TITLE_PREFIX=""
810
811                 if [ "$get_files_cvs" ]; then
812                          cvsup $get_files_cvs
813                 fi
814
815                 if [ "$CHMOD" = "yes" ]; then
816                         CHMOD_FILES="`nourl "$@"`"
817                         if [ -n "$CHMOD_FILES" ]; then
818                                 chmod $CHMOD_MODE $CHMOD_FILES
819                         fi
820                 fi
821         fi
822 }
823
824 make_tagver() {
825
826                 if [ -n "$DEBUG" ]; then
827                          set -x;
828                          set -v;
829                 fi
830
831                 # Check whether first character of PACKAGE_NAME is legal for tag name
832                 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
833                         TAG_PREFIX=tag_
834                 fi
835                 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"`
836                 # Remove #kernel.version_release from TAGVER because tagging sources
837                 # could occur with different kernel-headers than kernel-headers used at build time.
838                 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
839                 echo -n "$TAGVER"
840 }
841
842 tag_files()
843 {
844         TAG_FILES="$@"
845
846         if [ -n "$DEBUG" ]; then
847                 set -x;
848                 set -v;
849         fi
850
851         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
852                 echo "Version: $PACKAGE_VERSION"
853                 echo "Release: $PACKAGE_RELEASE"
854
855                 TAGVER=`make_tagver`
856
857                 if [ "$TAG_VERSION" = "yes" ]; then
858                         echo "CVS tag: $TAGVER"
859                 fi
860                 if [ -n "$TAG" ]; then
861                         echo "CVS tag: $TAG"
862                 fi
863
864                 OPTIONS="tag -F"
865                 if [ -n "$CVSROOT" ]; then
866                         OPTIONS="-d $CVSROOT $OPTIONS"
867                 fi
868
869                 cd "$SOURCE_DIR"
870                 for i in $TAG_FILES
871                 do
872                         # don't tag files stored on distfiles
873                         [ -n "`src_md5 $i`" ] && continue
874                         if [ -f "`nourl $i`" ]; then
875                                 if [ "$TAG_VERSION" = "yes" ]; then
876                                         cvs $OPTIONS $TAGVER `nourl $i`
877                                 fi
878                                 if [ -n "$TAG" ]; then
879                                         cvs $OPTIONS $TAG `nourl $i`
880                                 fi
881                         else
882                                 Exit_error err_no_source_in_repo $i
883                         fi
884                 done
885
886                 cd "$SPECS_DIR"
887                 if [ "$TAG_VERSION" = "yes" ]; then
888                         cvs $OPTIONS $TAGVER $SPECFILE
889                 fi
890                 if [ -n "$TAG" ]; then
891                         cvs $OPTIONS $TAG $SPECFILE
892                 fi
893
894                 unset OPTIONS
895         fi
896 }
897
898 branch_files()
899 {
900         TAG=$1
901         echo "CVS branch tag: $TAG"
902         shift;
903
904         TAG_FILES="$@"
905
906         if [ -n "$DEBUG" ]; then
907                 set -x;
908                 set -v;
909         fi
910
911         if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
912
913                 OPTIONS="tag -b"
914                 if [ -n "$CVSROOT" ]; then
915                         OPTIONS="-d $CVSROOT $OPTIONS"
916                 fi
917                 cd "$SOURCE_DIR"
918                 for i in $TAG_FILES
919                 do
920                         if [ -f `nourl $i` ]; then
921                                 cvs $OPTIONS $TAG `nourl $i`
922                         else
923                                 Exit_error err_no_source_in_repo $i
924                         fi
925                 done
926                 cd "$SPECS_DIR"
927                 cvs $OPTIONS $TAG $SPECFILE
928
929                 unset OPTIONS
930         fi
931 }
932
933
934
935 build_package()
936 {
937         update_shell_title "build_package"
938         if [ -n "$DEBUG" ]; then
939                 set -x;
940                 set -v;
941         fi
942
943         cd "$SPECS_DIR"
944
945         if [ -n "$TRY_UPGRADE" ]; then
946                   update_shell_title "build_package: try_upgrade"
947                 if [ -n "$FLOAT_VERSION" ]; then
948                         TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1
949                 else
950                         TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1
951                 fi
952
953                 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
954
955                 if [ -n "$TNEWVER" ]; then
956                         TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
957                         echo "New version found, updating spec file to version " $TNEWVER
958                         cp -f $SPECFILE $SPECFILE.bak
959                         chmod +w $SPECFILE
960                         eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
961                         eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE"
962                         parse_spec;
963                         if [ -n "$ICONS" ]; then
964                                 get_files $ICONS;
965                                 parse_spec;
966                         fi
967                         NODIST="yes" UPDATE5="yes" get_files $SOURCES $PATCHES;
968                         unset TOLDVER TNEWVER TNOTIFY
969                 fi
970         fi
971         cd "$SPECS_DIR"
972
973         case "$COMMAND" in
974                 build )
975                         BUILD_SWITCH="-ba" ;;
976                 build-binary )
977                         BUILD_SWITCH="-bb" ;;
978                 build-source )
979                         BUILD_SWITCH="-bs --nodeps" ;;
980                 build-prep )
981                         BUILD_SWITCH="-bp --nodeps" ;;
982         esac
983
984         update_shell_title "build_package: $COMMAND"
985         if [ -n "$LOGFILE" ]; then
986                 LOG=`eval echo $LOGFILE`
987                 if [ -d "$LOG" ]; then
988                         echo "Log file $LOG is a directory."
989                         echo "Parse error in the spec?"
990                         Exit_error err_build_fail;
991                 fi
992                 if [ -n "$LASTLOG_FILE" ]; then
993                         echo "LASTLOG=$LOG" > $LASTLOG_FILE
994                 fi
995                 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
996                 (time eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
997                 RETVAL=`cat $RES_FILE`
998                 rm $RES_FILE
999                 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1000                         if [ "$RETVAL" -eq "0" ]; then
1001                                 mv $LOG $LOGDIROK
1002                         else
1003                                 mv $LOG $LOGDIRFAIL
1004                         fi
1005                 fi
1006         else
1007                 eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE
1008                 RETVAL=$?
1009         fi
1010         if [ "$RETVAL" -ne "0" ]; then
1011                 if [ -n "$TRY_UPGRADE" ]; then
1012                         echo "\n!!! Package with new version cannot be build automagically\n"
1013                         mv -f $SPECFILE.bak $SPECFILE
1014                 fi
1015                 Exit_error err_build_fail;
1016         fi
1017         unset BUILD_SWITCH
1018 }
1019
1020 nourl()
1021 {
1022         echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1023 }
1024
1025 install_required_packages()
1026 {
1027         run_poldek -vi $1
1028         return $?
1029 }
1030
1031 find_spec_bcond() {
1032         # taken from find-spec-bcond, but with just getting the list
1033         local SPEC="$1"
1034         # quick revert hint: '$RPMBUILD --bcond $SPEC'
1035         awk -F"\n" '
1036         /^%changelog/ { exit }
1037         /_with(out)?_[_a-zA-Z0-9]+/{
1038                 match($0, /_with(out)?_[_a-zA-Z0-9]+/);
1039                 print substr($0, RSTART, RLENGTH);
1040         }
1041         /^%bcond_with/{
1042                 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1043                 bcond = substr($0, RSTART +5 , RLENGTH -5);
1044                 gsub(/[ \t]+/,"_",bcond);
1045                 print bcond
1046         }' $SPEC | LC_ALL=C sort -u
1047 }
1048
1049 set_bconds_values()
1050 {
1051         update_shell_title "set bcond values"
1052
1053         AVAIL_BCONDS_WITHOUT=""
1054         AVAIL_BCONDS_WITH=""
1055         if `grep -q ^%bcond ${SPECFILE}`; then
1056                 BCOND_VERSION="NEW"
1057         elif `egrep -q ^#\ *_with ${SPECFILE}`; then
1058                 BCOND_VERSION="OLD"
1059         else
1060                 return
1061         fi
1062
1063         local bcond_avail=$(find_spec_bcond $SPECFILE)
1064
1065         # expand bconds from ~/.bcondrc
1066         # The file structure is like gentoo's package.use:
1067         # ---
1068         # * -selinux
1069         # samba -mysql -pgsql
1070         # w32codec-installer license_agreement
1071         # php +mysqli
1072         # ---
1073         if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
1074                 SN=${SPECFILE%%\.spec}
1075
1076                 local bcondrc=$HOME/.bcondrc
1077                 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
1078
1079                 while read pkg flags; do
1080                         # ignore comments
1081                         [[ "$pkg" == \#* ]] && continue
1082
1083                         # any package or current package?
1084                         if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1085                                 for flag in $flags; do
1086                                         local opt=${flag#[+-]}
1087
1088                                         # use only flags which are in this package.
1089                                         if [[ $bcond_avail = *${opt}* ]]; then
1090                                                 if [[ $flag = -* ]]; then
1091                                                         BCOND="$BCOND --without $opt"
1092                                                 else
1093                                                         BCOND="$BCOND --with $opt"
1094                                                 fi
1095                                         fi
1096                                 done
1097                         fi
1098                 done < $bcondrc
1099                 update_shell_title "parse ~/.bcondrc: DONE!"
1100         fi
1101
1102         update_shell_title "parse bconds"
1103         case "${BCOND_VERSION}" in
1104                 NONE)
1105                         :
1106                         ;;
1107                 OLD)
1108                         echo "Warning: This spec has old style bconds. Fix it || die."
1109                         for opt in `echo "$bcond_avail" | grep ^_without_`
1110                         do
1111                                 AVAIL_BCOND_WITHOUT=${opt#_without_}
1112                                 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
1113                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1114                                 else
1115                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1116                                 fi
1117                         done
1118
1119                         for opt in `echo "$bcond_avail" | grep ^_with_`
1120                         do
1121                                 AVAIL_BCOND_WITH=${opt#_with_}
1122                                 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
1123                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1124                                 else
1125                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1126                                 fi
1127                         done
1128                         ;;
1129                 NEW)
1130                         local cond_type="" # with || without
1131                         for opt in $bcond_avail; do
1132                                 case "$opt" in
1133                                         _without)
1134                                                 cond_type="without"
1135                                                 ;;
1136                                         _with)
1137                                                 cond_type="with"
1138                                                 ;;
1139                                         _without_*)
1140                                                 AVAIL_BCOND_WITHOUT=${opt#_without_}
1141                                                 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
1142                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1143                                                 else
1144                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1145                                                 fi
1146                                                 ;;
1147                                         _with_*)
1148                                                 AVAIL_BCOND_WITH=${opt#_with_}
1149                                                 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
1150                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1151                                                 else
1152                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1153                                                 fi
1154                                                 ;;
1155                                         *)
1156                                                 case "$cond_type" in
1157                                                         with)
1158                                                                 cond_type=''
1159                                                                 AVAIL_BCOND_WITH="$opt"
1160                                                                 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
1161                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1162                                                                 else
1163                                                                         AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1164                                                                 fi
1165                                                                 ;;
1166                                                         without)
1167                                                                 cond_type=''
1168                                                                 AVAIL_BCOND_WITHOUT="$opt"
1169                                                                 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
1170                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1171                                                                 else
1172                                                                         AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1173                                                                 fi
1174                                                                 ;;
1175                                                 esac
1176                                                 ;;
1177                                 esac
1178                         done
1179                         ;;
1180         esac
1181 }
1182
1183 run_sub_builder()
1184 {
1185         package_name="${1}"
1186         update_shell_title "run_sub_builder $package_name"
1187         #
1188         # No i tutaj bym chcia³ zrobiæ sztuczn± inteligencjê, która spróbuje tego
1189         # pakieta zbudowaæ. Aktualnie niewiele dziala, bo generalnie nie widze do
1190         # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1191         # jakby nie bylo tego kawalka kodu.
1192         #
1193         # Update: Poprawi³em parê rzeczy i zaczê³o generowaæ pakiety spoza zadanej listy.
1194         #         Jednym s³owem budowanie niespoldkowanych zale¿no¶ci dzia³a w paru przypadkach.
1195         #
1196         #
1197         # y0shi.
1198
1199         parent_spec_name=''
1200
1201         # Istnieje taki spec? ${package}.spec
1202         if [ -f "${SPECS_DIR}/${package}.spec" ]; then
1203                 parent_spec_name=${package}.spec
1204         elif [ -f "${SPECS_DIR}/`echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g`.spec" ]; then
1205                 parent_spec_name="`echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g`.spec"
1206         else
1207                 for provides_line in `grep ^Provides:.*$package  ${SPECS_DIR} -R`
1208                 do
1209                         echo $provides_line
1210                 done
1211         fi
1212
1213         if [ "${parent_spec_name}" != "" ]; then
1214                 spawn_sub_builder $parent_spec_name
1215         fi
1216         NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1217 }
1218
1219 spawn_sub_builder()
1220 {
1221          package_name="${1}"
1222          update_shell_title "spawn_sub_builder $package_name"
1223
1224          sub_builder_opts=''
1225          if [ "${FETCH_BUILD_REQUIRES}" == "yes" ]; then
1226                   sub_builder_opts="${sub_builder_opts} -R"
1227          fi
1228          if [ "${REMOVE_BUILD_REQUIRES}" == "nice" ]; then
1229                   sub_builder_opts="${sub_builder_opts} -RB"
1230          elif [ "${REMOVE_BUILD_REQUIRES}" == "force" ]; then
1231                   sub_builder_opts="${sub_builder_opts} -FRB"
1232          fi
1233          if [ "${UPDATE_POLDEK_INDEXES}" == "yes" ]; then
1234                   sub_builder_opts="${sub_builder_opts} -Upi"
1235          fi
1236
1237          cd "${SPECS_DIR}"
1238          ./builder ${sub_builder_opts} "$@"
1239 }
1240
1241 remove_build_requires()
1242 {
1243         if [ "$INSTALLED_PACKAGES" != "" ]; then
1244                 case "$REMOVE_BUILD_REQUIRES" in
1245                         "force")
1246                                 run_poldek --noask -ve $INSTALLED_PACKAGES
1247                                 ;;
1248                         "nice")
1249                                 run_poldek --ask -ve $INSTALLED_PACKAGES
1250                                 ;;
1251                         *)
1252                                 echo You may want to manually remove following BuildRequires fetched:
1253                                 echo $INSTALLED_PACKAGES
1254                                 echo Try poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`
1255                                 ;;
1256                 esac
1257         fi
1258 }
1259
1260 display_bconds()
1261 {
1262         if [ "$AVAIL_BCONDS_WITH" != "" ] || [ "$AVAIL_BCONDS_WITHOUT" != "" ]; then
1263                 if [ "$BCOND" != "" ]; then
1264                         echo -ne "\nBuilding $SPECFILE with the following conditional flags:\n"
1265                         echo -ne "$BCOND"
1266                 else
1267                         echo -ne "\nNo conditional flags passed"
1268                 fi
1269                 echo -ne "\n\nfrom available:\n"
1270                 echo -ne "--with   :\t$AVAIL_BCONDS_WITH\n--without:\t$AVAIL_BCONDS_WITHOUT\n\n"
1271         fi
1272 }
1273
1274 display_branches()
1275 {
1276          if [ "$NOCVSSPEC" != "yes" ]; then
1277                   echo -ne "Available branches: "
1278                   cvs status -v "${SPECFILE}" | awk '!/Sticky Tag:/ && /\(branch:/ { print $1 } ' | xargs
1279          fi
1280 }
1281
1282 # checks a given list of packages/files/provides agains current rpmdb.
1283 # outputs all dependencies whcih current rpmdb doesn't satisfy.
1284 # input can be either STDIN or parameters
1285 _rpm_prov_check()
1286 {
1287          local DEPS
1288
1289          if [ "$#" -gt 0 ]; then
1290                   DEPS="$@"
1291          else
1292                   DEPS=$(cat)
1293          fi
1294
1295          DEPS=$(rpm -q --whatprovides $DEPS 2>&1 | awk '/^(error:|no package provides)/ { print }')
1296
1297          # packages
1298          echo "$DEPS" | awk '/^no package provides/ { print $NF }'
1299
1300          # other deps (files)
1301          echo "$DEPS" | awk -F: '/^error:.*No such file/{o = $2; gsub("^ file ", "", o); print o}'
1302 }
1303
1304 # checks if given package/files/provides exists in rpmdb.
1305 # inout can be either stdin or parameters
1306 # returns packages wchi hare present in the rpmdb
1307 _rpm_cnfl_check()
1308 {
1309          local DEPS
1310
1311          if [ "$#" -gt 0 ]; then
1312                   DEPS="$@"
1313          else
1314                   DEPS=$(cat)
1315          fi
1316
1317          rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
1318 }
1319
1320 fetch_build_requires()
1321 {
1322         if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
1323                 update_shell_title "fetch build requires"
1324                 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
1325                         local CONF=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
1326                         local DEPS=$(rpm-getdeps $BCOND $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
1327
1328                         update_shell_title "poldek: update indexes"
1329                         if [ -n "$CONF" ] || [ -n "$DEPS" ]; then
1330                                 $SU_SUDO /usr/bin/poldek -q --update || $SU_SUDO /usr/bin/poldek -q --upa
1331                         fi
1332                         if [ -n "$CONF" ]; then
1333                                 update_shell_title "uninstall conflicting packages: $CONF"
1334                                 echo "Trying to uninstall conflicting packages ($CONF):"
1335                                 $SU_SUDO /usr/bin/poldek --noask --nofollow -ev $CONF
1336                         fi
1337
1338                    while [ "$DEPS" ]; do
1339                                 update_shell_title "install deps: $DEPS"
1340                                 echo "Trying to install dependencies ($DEPS):"
1341                                 local log=.${SPECFILE}_poldek.log
1342                                 $SU_SUDO /usr/bin/poldek --caplookup -uGq $DEPS | tee $log
1343                                 failed=$(awk -F: '/^error:/{print $2}' $log)
1344                                 rm -f $log
1345                                 local ok
1346                                 if [ -n "$failed" ]; then
1347                                          for package in $failed; do
1348                                                   # FIXME: sanitise, deps could be not .spec files
1349                                                   spawn_sub_builder -bb $package && ok="$ok $package"
1350                                          done
1351                                          DEPS="$ok"
1352                                 else
1353                                          DEPS=""
1354                                 fi
1355                    done
1356                         return
1357                 fi
1358
1359                 echo -ne "\nAll packages installed by fetch_build_requires() are written to:\n"
1360                 echo -ne "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES\n"
1361                 echo -ne "\nIf anything fails, you may get rid of them by executing:\n"
1362                 echo "poldek -e \`cat `pwd`/.${SPECFILE}_INSTALLED_PACKAGES\`\n\n"
1363                 echo > `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1364                 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,textutils,coreutils,g -e s,kgcc_package,gcc,g -e s,\),,g`
1365                 do
1366                         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`"
1367                         GO="yes"
1368                         package=`basename "$package_item"|sed -e "s/}$//g"`
1369                         COND_ARCH_TST="`cat $SPECFILE|grep -B1 BuildRequires|grep -B1 $package|grep ifarch|sed -e "s/^.*ifarch//g"`"
1370                         mach=`uname -m`
1371
1372                         COND_TST=`cat $SPECFILE|grep BuildRequires|grep "$package"`
1373                         if `echo $COND_TST|grep -q '^BuildRequires:'`; then
1374                                 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
1375                                         GO="yes"
1376                                 fi
1377                         # bcond:
1378                         else
1379                                 COND_NAME=`echo $COND_TST|sed -e s,:BuildRequires:.*$,,g`
1380                                 GO=""
1381                                 # %{without}
1382                                 if `echo $COND_TST|grep -q 'without_'`; then
1383                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*without_,,g`
1384                                         if `echo $COND_TST|grep -q !`; then
1385                                                 COND_STATE="with"
1386                                         else
1387                                                 COND_STATE="wout"
1388                                         fi
1389                                         COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1390                                         COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1391                                         if [ -n "$COND_WITHOUT" ] || [ -z "$COND_WITH" ]; then
1392                                                 COND_ARGV="wout"
1393                                         else
1394                                                 COND_ARGV="with"
1395                                         fi
1396                                 # %{with}
1397                                 elif `echo $COND_TST|grep -q 'with_'`; then
1398                                         COND_NAME=`echo $COND_NAME|sed -e s,^.*with_,,g`
1399                                         if `echo $COND_TST|grep -q !`; then
1400                                                 COND_STATE="wout"
1401                                         else
1402                                                 COND_STATE="with"
1403                                         fi
1404                                         COND_WITH=`echo $AVAIL_BCONDS_WITH|grep "<$COND_NAME>"`
1405                                         COND_WITHOUT=`echo $AVAIL_BCONDS_WITHOUT|grep "<$COND_NAME>"`
1406                                         if [ -n "$COND_WITH" ] || [ -z "$COND_WITHOUT" ]; then
1407                                                 COND_ARGV="with"
1408                                         else
1409                                                 COND_ARGV="wout"
1410                                         fi
1411                                 fi
1412                                 RESULT="${COND_STATE}-${COND_ARGV}"
1413                                 case "$RESULT" in
1414                                         "with-wout" | "wout-with" )
1415                                                 GO=""
1416                                                 ;;
1417                                         "wout-wout" | "with-with" )
1418                                                 GO="yes"
1419                                                 ;;
1420                                         * )
1421                                                 echo "Action '$RESULT' was not defined for package '$package_item'"
1422                                                 GO="yes"
1423                                                 ;;
1424                                 esac
1425                         fi
1426
1427                         if [ "$GO" = "yes" ]; then
1428                                 if [ "`rpm -q $package|sed -e "s/$package.*/$package/g"`" != "$package" ]; then
1429                                         echo "Testing if $package has subrequirements..."
1430                                         run_poldek -t -i $package --dumpn=".$package-req.txt"
1431                                         if [ -f ".$package-req.txt" ]; then
1432                                                 for package_name in `cat ".$package-req.txt"|grep -v ^#`
1433                                                 do
1434                                                         if [ "$package_name" = "$package" ]; then
1435                                                                 echo -ne "Installing BuildRequired package:\t$package_name\n"
1436                                                                 update_shell_title "Installing BuildRequired package: ${package_name}"
1437                                                                 install_required_packages $package;
1438                                                         else
1439                                                                 echo -ne "Installing (sub)Required package:\t$package_name\n"
1440                                                                 update_shell_title "Installing (sub)Required package: ${package_name}"
1441                                                                 install_required_packages $package_name;
1442                                                         fi
1443                                                         case $? in
1444                                                                 0)
1445                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1446                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1447                                                                         ;;
1448                                                                 *)
1449                                                                         echo "Attempting to run spawn sub - builder..."
1450                                                                         echo -ne "Package installation failed:\t$package_name\n"
1451                                                                         run_sub_builder $package_name
1452                                                                         if [ $? -eq 0 ]; then
1453                                                                                 install_required_packages $package_name;
1454                                                                                 case $? in
1455                                                                                         0)
1456                                                                                                 INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1457                                                                                                 echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1458                                                                                                 ;;
1459                                                                                         *)
1460                                                                                                 NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1461                                                                                                 ;;
1462                                                                                 esac
1463                                                                         fi
1464                                                                         ;;
1465                                                         esac
1466                                                 done
1467                                                 rm -f ".$package-req.txt"
1468                                         else
1469                                                 echo "Attempting to run spawn sub - builder..."
1470                                                 echo -ne "Package installation failed:\t$package\n"
1471                                                 run_sub_builder $package
1472                                                 if [ $? -eq 0 ]; then
1473                                                         install_required_packages $package;
1474                                                         case $? in
1475                                                                 0)
1476                                                                         INSTALLED_PACKAGES="$package_name $INSTALLED_PACKAGES"
1477                                                                         echo $package_name >> `pwd`/.${SPECFILE}_INSTALLED_PACKAGES
1478                                                                         ;;
1479                                                                 *)
1480                                                                         NOT_INSTALLED_PACKAGES="$package_name $NOT_INSTALLED_PACKAGES"
1481                                                                         ;;
1482                                                         esac
1483                                                 fi
1484                                         fi
1485                                 else
1486                                         echo "Package $package is already installed. BuildRequirement satisfied."
1487                                 fi
1488                         fi
1489                 done
1490                 if [ "$NOT_INSTALLED_PACKAGES" != "" ]; then
1491                         echo "Unable to install following packages and their dependencies:"
1492                         for pkg in "$NOT_INSTALLED_PACKAGES"
1493                         do
1494                                 echo $pkg
1495                         done
1496                         remove_build_requires
1497                         exit 8
1498                 fi
1499         fi
1500 }
1501
1502 #---------------------------------------------
1503 # main()
1504
1505 if [ "$#" = 0 ]; then
1506         usage;
1507         exit 1
1508 fi
1509
1510 while test $# -gt 0
1511 do
1512         case "${1}" in
1513                 -5 | --update-md5 )
1514                         COMMAND="get";
1515                         NODIST="yes"
1516                         NOCVSSPEC="yes"
1517                         UPDATE5="yes"
1518                         shift ;;
1519                 -a5 | --add-md5 )
1520                         COMMAND="get";
1521                         NODIST="yes"
1522                         NOCVS="yes"
1523                         NOCVSSPEC="yes"
1524                         UPDATE5="yes"
1525                         ADD5="yes"
1526                         shift ;;
1527                 -n5 | --no-md5 )
1528                         NO5="yes"
1529                         shift ;;
1530                 -D | --debug )
1531                         DEBUG="yes"; shift ;;
1532                 -V | --version )
1533                         COMMAND="version"; shift ;;
1534                 -a | --as_anon )
1535                         CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;;
1536                 -b | -ba | --build )
1537                         COMMAND="build"; shift ;;
1538                 -bb | --build-binary )
1539                         COMMAND="build-binary"; shift ;;
1540                 -bs | --build-source )
1541                         COMMAND="build-source"; shift ;;
1542                 -bp | --build-prep )
1543                         COMMAND="build-prep"; shift ;;
1544                 -B | --branch )
1545                         COMMAND="branch"; shift; TAG="${1}"; shift;;
1546                 -c | --clean )
1547                         CLEAN="--clean --rmspec --rmsource"; shift ;;
1548                 -d | --cvsroot )
1549                         shift; CVSROOT="${1}"; shift ;;
1550                 -g | --get )
1551                         COMMAND="get"; shift ;;
1552                 -h | --help )
1553                         COMMAND="usage"; shift ;;
1554                 --http )
1555                         PROTOCOL="http"; shift ;;
1556                 -l | --logtofile )
1557                         shift; LOGFILE="${1}"; shift ;;
1558                 -ni| --nice )
1559                         shift; DEF_NICE_LEVEL=${1}; shift ;;
1560                 -ske | --skip-existing-files)
1561                         SKIP_EXISTING_FILES="yes"; shift ;;
1562                 -m | --mr-proper )
1563                         COMMAND="mr-proper"; shift ;;
1564                 -nc | --no-cvs )
1565                         NOCVS="yes"; shift ;;
1566                 -ncs | --no-cvs-specs )
1567                         NOCVSSPEC="yes"; shift ;;
1568                 -nd | --no-distfiles )
1569                         NODIST="yes"; shift ;;
1570                 -nm | --no-mirrors )
1571                         NOMIRRORS="yes"; shift ;;
1572                 -nu | --no-urls )
1573                         NOURLS="yes"; shift ;;
1574                 -ns | --no-srcs )
1575                         NOSRCS="yes"; shift ;;
1576                 -ns0 | --no-source0 )
1577                         NOSOURCE0="yes"; shift ;;
1578                 -nn | --no-net )
1579                         NOCVS="yes"
1580                         NOCVSSPEC="yes"
1581                         NODIST="yes"
1582                         NOMIRRORS="yes"
1583                         NOURLS="yes"
1584                         NOSRCS="yes"
1585                         ALWAYS_CVSUP="no"
1586                         shift;;
1587                 --opts )
1588                         shift; RPMOPTS="$RPM_OPTS ${1}"; shift ;;
1589                 --nopatch | -np )
1590                         shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
1591                 --with | --without )
1592                         case $GROUP_BCONDS in
1593                                 "yes")
1594                                         COND=${1}
1595                                         shift
1596                                         while ! `echo ${1}|grep -qE '(^-|spec)'`
1597                                         do
1598                                                 BCOND="$BCOND $COND $1"
1599                                                 shift
1600                                         done;;
1601                                 "no")
1602                                         if [[ "$2" = *,* ]]; then
1603                                                  for a in $(echo "$2" | tr , ' '); do
1604                                                           BCOND="$BCOND $1 $a"
1605                                                  done
1606                                         else
1607                                                  BCOND="$BCOND $1 $2"
1608                                         fi
1609                                         shift 2 ;;
1610                         esac
1611                         ;;
1612                 --target )
1613                         shift; TARGET="${1}"; shift ;;
1614                 --target=* )
1615                         TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
1616                 -q | --quiet )
1617                         QUIET="--quiet"; shift ;;
1618                 --date )
1619                         CVSDATE="${2}"; shift 2 ;;
1620                 -r | --cvstag )
1621                         shift; CVSTAG="${1}"; shift ;;
1622                 -R | --fetch-build-requires)
1623                         FETCH_BUILD_REQUIRES="yes"
1624                         NOT_INSTALLED_PACKAGES=
1625                         shift ;;
1626                 -RB | --remove-build-requires)
1627                         REMOVE_BUILD_REQUIRES="nice"
1628                         shift ;;
1629                 -FRB | --force-remove-build-requires)
1630                         REMOVE_BUILD_REQUIRES="force"
1631                         shift ;;
1632                 -sf | --sources-files)
1633                         COMMAND="list-sources-files"
1634                         shift ;;
1635                 -sp | --sources-paths)
1636                         COMMAND="list-sources-local-paths"
1637                         shift ;;
1638                 -su | --sources-urls)
1639                         COMMAND="list-sources-urls"
1640                         shift ;;
1641                 -Tvs | --tag-version-stable )
1642                         COMMAND="tag";
1643                         TAG="STABLE"
1644                         TAG_VERSION="yes"
1645                         shift;;
1646                 -Tvn | --tag-version-nest )
1647                         COMMAND="tag";
1648                         TAG="NEST"
1649                         TAG_VERSION="yes"
1650                         shift;;
1651                 -Ts | --tag-stable )
1652                         COMMAND="tag";
1653                         TAG="STABLE"
1654                         TAG_VERSION="no"
1655                         shift;;
1656                 -Tn | --tag-nest )
1657                         COMMAND="tag";
1658                         TAG="NEST"
1659                         TAG_VERSION="no"
1660                         shift;;
1661                 -Tv | --tag-version )
1662                         COMMAND="tag";
1663                         TAG=""
1664                         TAG_VERSION="yes"
1665                         shift;;
1666                 -Tp | --tag-prefix )
1667                         TAG_PREFIX="$2"
1668                         shift 2;;
1669                 -tt | --test-tag )
1670                         TEST_TAG="yes"
1671                         shift;;
1672                 -T | --tag )
1673                         COMMAND="tag";
1674                         shift
1675                         TAG="$1"
1676                         TAG_VERSION="no"
1677                         shift;;
1678                 -ir | --integer-release-only )
1679                         INTEGER_RELEASE="yes"
1680                         shift;;
1681                 -U | --update )
1682                         COMMAND="get"
1683                         UPDATE="yes"
1684                         NOCVSSPEC="yes"
1685                         NODIST="yes"
1686                         UPDATE5="yes"
1687                         shift ;;
1688                 -Upi | --update-poldek-indexes )
1689                         UPDATE_POLDEK_INDEXES="yes"
1690                         shift ;;
1691                 -u | --try-upgrade )
1692                         TRY_UPGRADE="1"; shift ;;
1693                 -un | --try-upgrade-with-float-version )
1694                         TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
1695                 -v | --verbose )
1696                         BE_VERBOSE="1"; shift ;;
1697                 --define)
1698                         shift
1699                         MACRO="${1}"
1700                         VALUE="${2}"
1701                         shift 2
1702                         RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
1703                         ;;
1704                 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
1705                         SHOW_BCONDS="yes"
1706                         shift
1707                         ;;
1708                 --nodeps)
1709                         shift
1710                         RPMOPTS="${RPMOPTS} --nodeps"
1711                         ;;
1712                 -debug)
1713                         RPMOPTS="${RPMOPTS} -debug"; shift ;;
1714                 * )
1715                         SPECFILE="${1}"
1716                         # check if specname was passed as specname:cvstag
1717                         if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
1718                                 CVSTAG="${SPECFILE##*:}";
1719                                 SPECFILE="${SPECFILE%%:*}";
1720                         fi
1721                         shift ;;
1722         esac
1723 done
1724
1725 if [ -n "$DEBUG" ]; then
1726         set -x;
1727         set -v;
1728 fi
1729
1730 if [ -n "$TARGET" ]; then
1731         case "$RPMBUILD" in
1732                 "rpmbuild")
1733                         TARGET_SWITCH="--target $TARGET" ;;
1734                 "rpm")
1735                         TARGET_SWITCH="--target=$TARGET" ;;
1736         esac
1737 fi
1738
1739 update_shell_title "$COMMAND"
1740 case "$COMMAND" in
1741         "build" | "build-binary" | "build-source" | "build-prep" )
1742                 init_builder;
1743                 if [ -n "$SPECFILE" ]; then
1744                         get_spec;
1745                         parse_spec;
1746                         set_bconds_values;
1747                         display_bconds;
1748                         display_branches;
1749                         [ X"$SHOW_BCONDS" = X"yes" ] && exit 0
1750                         fetch_build_requires;
1751                         if [ "$INTEGER_RELEASE" = "yes" ]; then
1752                                 echo "Checking release $PACKAGE_RELEASE..."
1753                                 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
1754                                         Exit_error err_fract_rel "$PACKAGE_RELEASE"
1755                                 fi
1756                         fi
1757
1758                         if [ -n "$TEST_TAG" ]; then
1759                                 TAGVER=`make_tagver`
1760                                 echo "Searching for tag $TAGVER..."
1761                                 TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g')
1762                                 if [ -n "$TAGREL" ]; then
1763                                         Exit_error err_tag_exists "$TAGVER" "$TAGREL"
1764                                 fi
1765
1766                                 # - do not allow to build from HEAD when XX-branch exists
1767                                 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto-\([a-zA-Z]\+\)-.*#\1#g')
1768                                 if [ "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
1769                                          TAG_BRANCH="${TREE_PREFIX}-branch"
1770                                          TAG_STATUS=$(cvs status -v $SPECFILE | grep -Ei "${TAG_BRANCH}.+(branch: [0-9.]+)")
1771                                          if [ -n "$TAG_STATUS" -a "$CVSTAG" = "HEAD" ]; then
1772                                                   Exit_error err_branch_exists "$TAG_STATUS"
1773                                          fi
1774
1775                                 fi
1776                         fi
1777
1778                         if [ -n "$ICONS" ]; then
1779                                 get_files $ICONS;
1780                                 parse_spec;
1781                         fi
1782                         if [ -n "$NOSOURCE0" ] ; then
1783                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1784                         fi
1785                         get_files $SOURCES $PATCHES;
1786                         build_package;
1787                         if [ "$UPDATE_POLDEK_INDEXES" = "yes" -a "$COMMAND" != "build-prep" ]; then
1788                                 run_poldek --sdir="${POLDEK_INDEX_DIR}" --mkidxz
1789                         fi
1790                         remove_build_requires;
1791                 else
1792                         Exit_error err_no_spec_in_cmdl;
1793                 fi
1794                 ;;
1795         "branch" )
1796                 init_builder;
1797                 if [ -n "$SPECFILE" ]; then
1798                         get_spec;
1799                         parse_spec;
1800                         if [ -n "$ICONS" ]; then
1801                                 get_files $ICONS
1802                                 parse_spec;
1803                         fi
1804                         get_files $SOURCES $PATCHES;
1805                         branch_files $TAG "$SOURCES $PATCHES $ICONS";
1806                 else
1807                         Exit_error err_no_spec_in_cmdl;
1808                 fi
1809                 ;;
1810         "get" )
1811                 init_builder;
1812                 if [ -n "$SPECFILE" ]; then
1813                         get_spec;
1814                         parse_spec;
1815                         if [ -n "$ICONS" ]; then
1816                                 OLD_UPDATE5=$UPDATE5
1817                                 UPDATE5= get_files $ICONS
1818                                 UPDATE5=$OLD_UPDATE5
1819                                 parse_spec;
1820                         fi
1821                         if [ -n "$NOSOURCE0" ] ; then
1822                                 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
1823                         fi
1824                         get_files $SOURCES $PATCHES
1825                 else
1826                         Exit_error err_no_spec_in_cmdl;
1827                 fi
1828                 ;;
1829         "tag" )
1830                 NOURLS=1
1831                 NODIST="yes"
1832                 init_builder;
1833                 if [ -n "$SPECFILE" ]; then
1834                         get_spec;
1835                         parse_spec;
1836                         if [ -n "$ICONS" ]; then
1837                                 get_files $ICONS
1838                                 parse_spec;
1839                         fi
1840                         # don't fetch sources from remote locations
1841                         new_SOURCES=""
1842                         for file in $SOURCES
1843                         do
1844                                 [ -n "`src_md5 $file`" ] && continue
1845                                 new_SOURCES="$new_SOURCES $file"
1846                         done
1847                         SOURCES="$new_SOURCES"
1848                         get_files $SOURCES $PATCHES;
1849                         tag_files "$SOURCES $PATCHES $ICONS";
1850                 else
1851                         Exit_error err_no_spec_in_cmdl;
1852                 fi
1853                 ;;
1854         "mr-proper" )
1855                 $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE
1856                 ;;
1857         "list-sources-files" )
1858                 init_builder
1859                 NOCVSSPEC="yes"
1860                 DONT_PRINT_REVISION="yes"
1861                 get_spec
1862                 parse_spec
1863                 SAPS="$SOURCES $PATCHES"
1864                 for SAP in $SAPS ; do
1865                          echo $SAP | awk '{gsub(/.*\//,"") ; print}'
1866                 done
1867                 ;;
1868         "list-sources-urls" )
1869                 init_builder
1870                 NOCVSSPEC="yes"
1871                 DONT_PRINT_REVISION="yes"
1872                 get_spec
1873                 parse_spec
1874                 SAPS="$SOURCES $PATCHES"
1875                 for SAP in $SAPS ; do
1876                          echo $SAP
1877                 done
1878                 ;;
1879         "list-sources-local-paths" )
1880                 init_builder
1881                 NOCVSSPEC="yes"
1882                 DONT_PRINT_REVISION="yes"
1883                 get_spec
1884                 parse_spec
1885                 SAPS="$SOURCES $PATCHES"
1886                 for SAP in $SAPS ; do
1887                          echo $SOURCE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
1888                 done
1889                 ;;
1890         "usage" )
1891                 usage;;
1892         "version" )
1893                 echo "$VERSION";;
1894 esac
1895 if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
1896         rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
1897 fi
1898 cd "$__PWD"
1899
1900 # vi:syntax=sh:ts=4:sw=4
This page took 0.170414 seconds and 3 git commands to generate.