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