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