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