]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- need %patchset_source() as it defines PatchX
[packages/rpm-build-tools.git] / builder.sh
CommitLineData
1d7abbe3 1#!/bin/ksh
cd445739
AM
2# -----------
3# $Id$
4# Exit codes:
2a5f078d 5# 0 - succesful
6# 1 - help displayed
7# 2 - no spec file name in cmdl parameters
8# 3 - spec file not stored in repo
9# 4 - some source, patch or icon files not stored in repo
10# 5 - package build failed
11# 6 - spec file with errors
12# 7 - wrong source in /etc/poldek.conf
13# 8 - Failed installing buildrequirements and subrequirements
14# 9 - Requested tag already exist
15# 10 - Refused to build fractional release
16# 100 - Unknown error (should not happen)
cd445739
AM
17
18# Notes (todo):
f7b91886 19# - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
cd445739 20# - when Icon: field is present, -5 and -a5 doesn't work
f3ada241 21# - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
931a4acf 22
4003ad8c 23VERSION="\
c9acaed9 24Build package utility from PLD Linux CVS repository
ac1516e0 25v0.17 (C) 1999-2006 Free Penguins".
d6a77ddb 26PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
b03f053b 27
cd445739 28COMMAND="build"
64ea5308 29TARGET=""
cd445739 30
bde1c404 31SPECFILE=""
d287305c 32BE_VERBOSE=""
4003ad8c 33QUIET=""
cd445739
AM
34CLEAN=""
35DEBUG=""
36NOURLS=""
37NOCVS=""
38NOCVSSPEC=""
39NODIST=""
47761337 40NOINIT=""
cd445739 41UPDATE=""
cd445739
AM
42ADD5=""
43NO5=""
44ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
c8f50498 45CVSROOT=""
cd445739
AM
46
47# It can be used i.e. in log file naming.
48# See LOGFILE example.
49DATE=`date +%Y-%m-%d_%H-%M-%S`
50
51# Example: LOGFILE='../log.$PACKAGE_NAME'
52# Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
53# Yes, you can use variable name! Note _single_ quotes!
54LOGFILE=''
55
56LOGDIR=""
57LOGDIROK=""
58LOGDIRFAIL=""
59LASTLOG_FILE=""
60
61CHMOD="no"
62CHMOD_MODE="0444"
63RPMOPTS=""
d1c5a9a7 64RPMBUILDOPTS=""
cd445739
AM
65BCOND=""
66GROUP_BCONDS="no"
947025e5 67CVSIGNORE_DF="no"
d287305c 68
69PATCHES=""
70SOURCES=""
cd445739 71ICONS=""
d287305c 72PACKAGE_RELEASE=""
73PACKAGE_VERSION=""
74PACKAGE_NAME=""
cd445739
AM
75PROTOCOL="ftp"
76WGET_RETRIES=${MAX_WGET_RETRIES:-0}
77CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
78
79CVSTAG=""
80RES_FILE=""
39dcc7de 81CVS_FORCE=""
cd445739
AM
82
83CVS_SERVER="cvs.pld-linux.org"
84DISTFILES_SERVER="://distfiles.pld-linux.org"
d4730dae 85ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
cd445739 86
36d03934 87DEF_NICE_LEVEL=19
86aafdbe 88SCHEDTOOL="auto"
cd445739
AM
89
90FAIL_IF_NO_SOURCES="yes"
91
18e5347d
ER
92# let get_files skip over files which are present to get those damn files fetched
93SKIP_EXISTING_FILES="no"
94
975d7b23 95TRY_UPGRADE=""
257af81b
ER
96# should the specfile be restored if upgrade failed?
97REVERT_BROKEN_UPGRADE="yes"
98
ab4a2b6e 99if [ -x /usr/bin/rpm-getdeps ]; then
ce40491a 100 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
ab4a2b6e 101else
ce40491a 102 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
ab4a2b6e
ER
103fi
104
cd445739
AM
105# Here we load saved user environment used to
106# predefine options set above, or passed to builder
107# in command line.
108# This one reads global system environment settings:
109if [ -f ~/etc/builderrc ]; then
110 . ~/etc/builderrc
111fi
112# And this one cascades settings using user personal
113# builder settings.
114# Example of ~/.builderrc:
115#
116#UPDATE_POLDEK_INDEXES="yes"
117#FETCH_BUILD_REQUIRES="yes"
118#REMOVE_BUILD_REQUIRES="force"
119#GROUP_BCONDS="yes"
120#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
982e358c 121#TITLECHANGE=no
cd445739 122#
a83e5405 123SU_SUDO=""
cd445739
AM
124if [ -n "$HOME_ETC" ]; then
125 USER_CFG="$HOME_ETC/.builderrc"
126else
127 USER_CFG=~/.builderrc
128fi
129
130[ -f "$USER_CFG" ] && . "$USER_CFG"
131
86aafdbe
ER
132if [ "$SCHEDTOOL" = "auto" ]; then
133 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
134 SCHEDTOOL="schedtool -B -e"
135 else
136 SCHEDTOOL="no"
137 fi
138fi
139
ca2e6c31 140if [ -n "$USE_PROZILLA" ]; then
7e365483
KK
141 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
142 GETURI2="$GETURI"
143 OUTFILEOPT="-O"
ca2e6c31 144elif [ -n "$USE_AXEL" ]; then
cede92b3 145 GETURI="axel -a $AXEL_OPTS"
7e365483
KK
146 GETURI2="$GETURI"
147 OUTFILEOPT="-o"
ca2e6c31 148else
5700ee32
ER
149 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
150 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
151 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
6f9a5d76 152
7e365483
KK
153 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
154 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
155 OUTFILEOPT="-O"
2bc5451f 156fi
11468b23 157
11468b23
AM
158GETLOCAL="cp -a"
159
160if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
161 RPM="rpm"
162 RPMBUILD="rpm"
163else
164 RPM="rpm"
165 RPMBUILD="rpmbuild"
166fi
167
168POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
a83e5405 169POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
11468b23 170
cd445739
AM
171run_poldek()
172{
173 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
174 if [ -n "$LOGFILE" ]; then
175 LOG=`eval echo $LOGFILE`
176 if [ -n "$LASTLOG_FILE" ]; then
177 echo "LASTLOG=$LOG" > $LASTLOG_FILE
178 fi
86aafdbe 179 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
cd445739
AM
180 return $exit_pldk
181 else
86aafdbe 182 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
cd445739
AM
183 return `cat ${RES_FILE}`
184 rm -rf ${RES_FILE}
185 fi
186}
187
cd445739
AM
188#---------------------------------------------
189# functions
da946cd6 190
5a491465 191usage()
192{
cd445739
AM
193 if [ -n "$DEBUG" ]; then set -xv; fi
194 echo "\
195Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
cd445739 196[-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
4efa0b98 197[{-cf|--cvs-force}] [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>]
19dc5591 198[-g|--get] [-h|--help] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
199[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T|--tag <cvstag>]
a7b2951c 200[-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
cd445739 201[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
dfe2cb9a 202[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds]
f19103b5 203[--with/--without <feature>] [--define <macro> <value>] <package>[.spec][:cvstag]
2a5f078d 204
cd445739
AM
205-5, --update-md5 - update md5 comments in spec, implies -nd -ncs
206-a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
207-n5, --no-md5 - ignore md5 comments in spec
9243e80b
ER
208-D, --debug - enable builder script debugging mode,
209-debug - produce rpm debug package (same as --opts -debug)
cd445739
AM
210-V, --version - output builder version
211-a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
212-b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
213 from <package>.spec,
214-bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
215 only package from <package>.spec,
c56807e0
ER
216-bp, --build-prep - execute the %prep phase of <package>.spec,
217-bc - reserved (not implemented)
218-bi reserved (not implemented)
cd445739
AM
219-bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
220 them into src.rpm,
c56807e0 221--short-circuit - reserved (not implemented)
cd445739
AM
222-B, --branch - add branch
223-c, --clean - clean all temporarily created files (in BUILD, SOURCES,
224 SPECS and \$RPM_BUILD_ROOT),
39dcc7de 225-cf, --cvs-force - use -F when tagging (useful when moving branches)
2a5f078d 226-d <cvsroot>, --cvsroot <cvsroot>
cd445739
AM
227 - setup \$CVSROOT,
228--define <macro> <value>
229 - define a macro <macro> with value <value>,
230--nodeps - rpm won't check any dependences
231-g, --get - get <package>.spec and all related files from CVS repo
232 or HTTP/FTP,
233-h, --help - this message,
234--http - use http instead of ftp,
235-l <logfile>, --logtofile <logfile>
236 - log all to file,
237-m, --mr-proper - only remove all files related to spec file and all work
238 resources,
239-nc, --no-cvs - don't download sources from CVS, if source URL is given,
240-ncs, --no-cvs-specs
241 - don't check specs in CVS
242-nd, --no-distfiles - don't download from distfiles
243-nm, --no-mirrors - don't download from mirror, if source URL is given,
244-nu, --no-urls - don't try to download from FTP/HTTP location,
245-ns, --no-srcs - don't download Sources
246-ns0, --no-source0 - don't download Source0
247-nn, --no-net - don't download anything from the net
b572253e 248--no-init - don't initialize builder paths (SPECS and SOURCES)
18e5347d
ER
249-ske,
250--skip-existing-files - skip existing files in get_files
cd445739
AM
251--opts <rpm opts> - additional options for rpm
252-q, --quiet - be quiet,
253--date yyyy-mm-dd - build package using resources from specified CVS date,
254-r <cvstag>, --cvstag <cvstag>
255 - build package using resources from specified CVS tag,
5323fffd 256-A - build package using CVS resources as any sticky tags/date/kopts being reset.
cd445739
AM
257-R, --fetch-build-requires
258 - fetch what is BuildRequired,
259-RB, --remove-build-requires
260 - remove all you fetched with -R or --fetch-build-requires
261 remember, this option requires confirmation,
262-FRB, --force-remove-build-requires
263 - remove all you fetched with -R or --fetch-build-requires
264 remember, this option works without confirmation,
06541433
JR
265-sd, --source-distfiles - list sources available from distfiles (intended for offline
266 operations; does not work when Icon field is present
267 but icon file is absent),
268-sdp, --source-distfiles-paths - list sources available from distfiles -
269 paths relative to distfiles directory (intended for offline
270 operations; does not work when Icon field is present
271 but icon file is absent),
a7eefc54 272-sf, --source-files - list sources - bare filenames (intended for offline
273 operations; does not work when Icon field is present
3621e588 274 but icon file is absent),
a7eefc54 275-sp, --source-paths - list sources - filenames with full local paths (intended for
276 offline operations; does not work when Icon field is present
3621e588 277 but icon file is absent),
2dddf439
ER
278-su, --source-urls - list urls - urls to sources and patches
279 intended for copying urls with spec with lots of macros in urls
cd445739
AM
280-T <cvstag> , --tag <cvstag>
281 - add cvs tag <cvstag> for files,
282-Tvs, --tag-version-stable
094bd95b 283 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
cd445739
AM
284-Ts, --tag-stable
285 - add cvs tag STABLE for files,
cd445739 286-Tv, --tag-version
1691a37b 287 - add cvs tag NAME-VERSION-RELEASE for files,
cd445739
AM
288-Tp, --tag-prefix <prefix>
289 - add <prefix> to NAME-VERSION-RELEASE tags,
290-tt, --test-tag <prefix>
291 - fail if tag is already present,
50321881
JK
292-ir, --integer-release-only
293 - allow only integer and snapshot releases
cd445739
AM
294-v, --verbose - be verbose,
295-u, --try-upgrade - check version, and try to upgrade package
296-un, --try-upgrade-with-float-version
297 - as above, but allow float version
deccc50e 298-U, --update - refetch sources, don't use distfiles, and update md5 comments
cd445739
AM
299-Upi, --update-poldek-indexes
300 - refresh or make poldek package index files.
c890b916 301-np, --nopatch <patchnumber>
bed98670 302 - don't apply <patchnumber>
dfe2cb9a
MK
303--show-bconds - show available conditional builds, which can be used
304 - with --with and/or --without switches.
9b78be50
ER
305--show-bcond-args - show active bconds, from ~/.bcondrc. this is used by
306 ./repackage.sh script. in other words, the output is
307 parseable by scripts.
cd445739
AM
308--with/--without <feature>
309 - conditional build package depending on %_with_<feature>/
310 %_without_<feature> macro switch. You may now use
311 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
312 constructions. Set GROUP_BCONDS to yes to make use of it.
6dd19291 313--target <platform>, --target=<platform>
3621e588
ER
314 - build for platform <platform>.
315--init-rpm-dir - initialize ~/rpm directory structure
5a491465 316"
317}
318
c890b916 319update_shell_title() {
a0d6396b 320 [ -t 1 ] || return
0b65d15e
ER
321 local len=${COLUMNS:-80}
322 local msg=$(echo "$*" | cut -c-$len)
323
e225de91
ER
324 if [ -n "$BE_VERBOSE" ]; then
325 echo >&2 "$(date +%s.%N) $*"
326 fi
327
982e358c 328 if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then
138bbc98
ER
329 local pkg
330 if [ -n "$PACKAGE_NAME" ]; then
331 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
332 else
333 pkg=${SPECFILE}
334 fi
335
336 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
10c1e115 337 msg="$(echo $msg | tr -d '\n\r')"
982e358c
MP
338 case "$TERM" in
339 cygwin|xterm*)
340 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
341 ;;
342 screen*)
343 echo >&2 -ne "\033]0;$msg\007"
344 ;;
345 esac
346 fi
c890b916
ER
347}
348
7e40520f
ER
349# set TARGET from BuildArch: from SPECFILE
350set_spec_target() {
ce40491a
ER
351 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
352 tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
353 if [ "$tmp" ]; then
7e40520f
ER
354 TARGET="$tmp"
355 case "$RPMBUILD" in
356 "rpmbuild")
ce40491a 357 TARGET_SWITCH="--target $TARGET" ;;
7e40520f 358 "rpm")
ce40491a 359 TARGET_SWITCH="--target=$TARGET" ;;
7e40520f 360 esac
ce40491a
ER
361 fi
362 fi
7e40520f
ER
363}
364
cd445739 365cache_rpm_dump () {
d22150da 366 if [ -n "$DEBUG" ]; then
518ff1fb
ER
367 set -x
368 set -v
d22150da 369 fi
7e40520f 370
13974367 371 update_shell_title "cache_rpm_dump"
237bd3f1
ER
372 local rpm_dump
373 rpm_dump=`
d05e8080 374
fa4bf1df 375 # we reset macros not to contain macros.build as all the %() macros are
559d511f 376 # executed here, while none of them are actually needed.
fa4bf1df 377 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
559d511f 378 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
36433112 379 macrofiles="/usr/lib/rpm/macros:$SPECS_DIR/.builder-rpmmacros:~/etc/.rpmmacros:~/.rpmmacros"
237bd3f1 380 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
7cb24972 381 # FIXME: better ideas than .rpmrc?
36433112 382 printf 'include:/usr/lib/rpm/rpmrc\nmacrofiles:%s\n' $macrofiles > .builder-rpmrc
fb198857 383# TODO: move these to /usr/lib/rpm/macros
36433112 384 cat > .builder-rpmmacros <<'EOF'
fb198857
ER
385%requires_releq_kernel_up %{nil}
386%requires_releq_kernel_smp %{nil}
6b8134e3 387%requires_releq() %{nil}
bb01dee9 388%pyrequires_eq() %{nil}
559d511f 389%requires_eq() %{nil}
c13be3d1 390%requires_eq_to() %{nil}
fb198857
ER
391%releq_kernel_up ERROR
392%releq_kernel_smp ERROR
74d9fd14 393%kgcc_package ERROR
237bd3f1 394%_fontsdir ERROR
7141278d 395%ruby_version ERROR
396%ruby_ver_requires_eq() %{nil}
397%ruby_mod_ver_requires_eq() %{nil}
c13be3d1 398%__php_api_requires() %{nil}
7141278d 399%php_major_version ERROR
400%php_api_version ERROR
401%py_ver ERROR
41035426
ER
402%perl_vendorarch ERROR
403%perl_vendorlib ERROR
703ae20b
ER
404# damn. need it here! - copied from /usr/lib/rpm/macros.build
405%tmpdir %(echo "${TMPDIR:-/tmp}")
406%patchset_source(f:b:) %(base=%{-b*}%{!-b*:10000}; start=$((%1 + $base)); end=$((%{?2}%{!?2:%{1}} + $base)); seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1; seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2; paste %{tmpdir}/__ps{1,2}; rm -f %{tmpdir}/__ps{1,2})%{nil}
fb198857 407EOF
cd445739 408 case "$RPMBUILD" in
237bd3f1
ER
409 rpm)
410 ARGS='-bp'
411 ;;
412 rpmbuild)
413 ARGS='--nodigest --nosignature --nobuild'
414 ;;
415 esac
3d12d055
JR
416 if [ "$NOINIT" = "yes" ] ; then
417 cat >> .builder-rpmmacros <<'EOF'
418%_specdir ./
419%_sourcedir ./
420EOF
c039643c
JR
421 fi
422 $RPMBUILD --rcfile .builder-rpmrc $ARGS $ARGDIRS --nodeps --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1
237bd3f1 423 `
fb198857 424 if [ $? -gt 0 ]; then
237bd3f1
ER
425 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
426 echo "$error" >&2
518ff1fb 427 Exit_error err_build_fail
fb198857 428 fi
d05e8080
ER
429
430 # make small dump cache
431 rpm_dump_cache=`echo "$rpm_dump" | awk '
4e8c3089
ER
432 $2 ~ /^SOURCEURL/ {print}
433 $2 ~ /^PATCHURL/ {print}
434 $2 ~ /^nosource/ {print}
435 $2 ~ /^PACKAGE_/ {print}
d05e8080
ER
436 '`
437
13974367 438 update_shell_title "cache_rpm_dump: OK!"
cd445739
AM
439}
440
441rpm_dump () {
442 if [ -z "$rpm_dump_cache" ] ; then
d7b4d36e 443 echo "internal error: cache_rpm_dump not called! (missing %prep?)" 1>&2
cd445739
AM
444 fi
445 echo "$rpm_dump_cache"
446}
447
d05e8080
ER
448get_icons()
449{
450 update_shell_title "get icons"
451 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
452 if [ -z "$ICONS" ]; then
453 return
454 fi
455
975d7b23 456 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
d05e8080
ER
457}
458
59398507 459parse_spec()
460{
af4d5315 461 update_shell_title "parsing specfile"
cd445739 462 if [ -n "$DEBUG" ]; then
518ff1fb
ER
463 set -x
464 set -v
cd445739 465 fi
b2975fc3 466
d05e8080 467 # icons are needed for successful spec parse
518ff1fb 468 get_icons
d05e8080 469
cd445739 470 cd $SPECS_DIR
cd445739 471 cache_rpm_dump
00fcec7e 472
cd445739
AM
473 if [ "$NOSRCS" != "yes" ]; then
474 SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`"
475 fi
7cb24972 476
cd445739
AM
477 if (rpm_dump | grep -qEi ":.*nosource.*1"); then
478 FAIL_IF_NO_SOURCES="no"
479 fi
480
481 PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`"
482 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
fa4bf1df
ER
483 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3}')
484 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3}')
485 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3}')
78eab2a1 486
cd445739
AM
487 if [ -n "$BE_VERBOSE" ]; then
488 echo "- Sources : `nourl $SOURCES`"
489 if [ -n "$PATCHES" ]; then
490 echo "- Patches : `nourl $PATCHES`"
491 else
492 echo "- Patches : *no patches needed*"
493 fi
494 if [ -n "$ICONS" ]; then
495 echo "- Icon : `nourl $ICONS`"
496 else
497 echo "- Icon : *no package icon*"
498 fi
499 echo "- Name : $PACKAGE_NAME"
500 echo "- Version : $PACKAGE_VERSION"
501 echo "- Release : $PACKAGE_RELEASE"
502 fi
13974367
ER
503
504 update_shell_title "parse_spec: OK!"
cd445739
AM
505}
506
507Exit_error()
508{
509 if [ -n "$DEBUG" ]; then
518ff1fb
ER
510 set -x
511 set -v
cd445739
AM
512 fi
513
514 cd "$__PWD"
515
516 case "$1" in
517 "err_no_spec_in_cmdl" )
518 remove_build_requires
518ff1fb 519 echo "ERROR: spec file name not specified."
cd445739
AM
520 exit 2 ;;
521 "err_no_spec_in_repo" )
522 remove_build_requires
518ff1fb 523 echo "Error: spec file not stored in CVS repo."
cd445739
AM
524 exit 3 ;;
525 "err_no_source_in_repo" )
526 remove_build_requires
518ff1fb 527 echo "Error: some source, patch or icon files not stored in CVS repo. ($2)"
cd445739
AM
528 exit 4 ;;
529 "err_build_fail" )
530 remove_build_requires
518ff1fb 531 echo "Error: package build failed. (${2:-no more info})"
cd445739 532 exit 5 ;;
78eab2a1
AM
533 "err_no_package_data" )
534 remove_build_requires
535 echo "Error: couldn't get out package name/version/release from spec file."
536 exit 6 ;;
ce40491a 537 "err_tag_exists" )
50321881 538 remove_build_requires
518ff1fb 539 echo "Tag ${2} already exists (spec release: ${3})."
50321881 540 exit 9 ;;
ce40491a 541 "err_fract_rel" )
50321881 542 remove_build_requires
518ff1fb 543 echo "Release ${2} not integer and not a snapshot."
50321881 544 exit 10 ;;
fb96e0b5
AM
545 "err_branch_exists" )
546 remove_build_requires
518ff1fb 547 echo "Tree branch already exists (${2})."
fb96e0b5 548 exit 11 ;;
50321881 549
cd445739 550 esac
73848362
ER
551 echo "Unknown error."
552 exit 100
cd445739
AM
553}
554
555init_builder()
556{
557 if [ -n "$DEBUG" ]; then
518ff1fb
ER
558 set -x
559 set -v
0dd6320d 560 fi
cd445739 561
4aeb9973 562 if [ "$NOINIT" != "yes" ] ; then
29e90b02
JR
563 SOURCE_DIR="`eval $RPM $RPMOPTS --eval '%{_sourcedir}'`"
564 SPECS_DIR="`eval $RPM $RPMOPTS --eval '%{_specdir}'`"
565 else
566 SOURCE_DIR="."
567 SPECS_DIR="."
568 fi
cd445739
AM
569
570 __PWD="`pwd`"
00fcec7e 571}
572
d6a77ddb 573get_spec()
1471f6d6 574{
c890b916 575
2e5be021 576 update_shell_title "get_spec"
c890b916 577
cd445739 578 if [ -n "$DEBUG" ]; then
518ff1fb
ER
579 set -x
580 set -v
cd445739
AM
581 fi
582
583 cd "$SPECS_DIR"
049ab214 584 if [ ! -f "$SPECFILE" ]; then
518ff1fb 585 SPECFILE="`basename $SPECFILE .spec`.spec"
cd445739
AM
586 fi
587 if [ "$NOCVSSPEC" != "yes" ]; then
cd445739 588
049ab214
ER
589 if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then
590 echo "Warning: No CVS access defined - using local .spec file"
591 NOCVSSPEC="yes"
cd445739
AM
592 fi
593
049ab214 594 cvsup "$SPECFILE" || Exit_error err_no_spec_in_repo
cd445739 595 fi
049ab214 596
cd445739 597 if [ ! -f "$SPECFILE" ]; then
518ff1fb 598 Exit_error err_no_spec_in_repo
cd445739
AM
599 fi
600
601 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
602 chmod $CHMOD_MODE $SPECFILE
603 fi
604 unset OPTIONS
a7eefc54 605 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE
7e40520f 606
ce40491a 607 set_spec_target
cd445739
AM
608}
609
610find_mirror()
611{
612 cd "$SPECS_DIR"
782518da 613 local url="$1"
cd445739
AM
614 if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then
615 cvs update mirrors >&2
616 fi
617
618 IFS="|"
782518da
ER
619 local origin mirror name rest ol prefix
620 while read origin mirror name rest; do
621 # skip comments and empty lines
622 if [ -z "$origin" ] || [[ $origin == \#* ]]; then
623 continue
624 fi
cd445739
AM
625 ol=`echo -n "$origin"|wc -c`
626 prefix="`echo -n "$url" | head -c $ol`"
627 if [ "$prefix" = "$origin" ] ; then
782518da 628 suffix="`echo "$url"|cut -b $((ol+1))-`"
cd445739
AM
629 echo -n "$mirror$suffix"
630 return 0
631 fi
632 done < mirrors
633 echo "$url"
634}
635
e7e0d4ec 636# Warning: unpredictable results if same URL used twice
cd445739
AM
637src_no ()
638{
639 cd $SPECS_DIR
640 rpm_dump | \
641 grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \
642 sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \
643 head -n 1 | xargs
1471f6d6 644}
645
e7e0d4ec 646src_md5()
8ba5cdda 647{
e7e0d4ec 648 [ "$NO5" = "yes" ] && return
cd445739
AM
649 no=$(src_no "$1")
650 [ -z "$no" ] && return
651 cd $SPECS_DIR
e7e0d4ec
ER
652 local md5
653
654 if [ -f additional-md5sums ]; then
655 local spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::)
656 if [ -z "$spec_rev" ]; then
657 spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')"
658 fi
659 local spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')"
660 md5=$(grep -s -v '^#' additional-md5sums | \
661 grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \
662 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
663 grep -E '^[0-9a-f]{32}$')
664
665 if [ "$md5" ]; then
666 if [ $(echo "$md5" | wc -l) != 1 ] ; then
667 echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2
668 fi
669 echo "$md5" | tail -n 1
670 return
671 fi
cd445739 672 fi
e7e0d4ec
ER
673
674 source_md5=`grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
675 if [ -n "$source_md5" ]; then
676 echo $source_md5
cd445739 677 else
e7e0d4ec
ER
678 # we have empty SourceX-md5, but it is still possible
679 # that we have NoSourceX-md5 AND NoSource: X
680 nosource_md5=`grep -i "#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
03db3356 681 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
e7e0d4ec 682 echo $nosource_md5
cd445739 683 fi
cd445739
AM
684 fi
685}
686
06541433
JR
687distfiles_path ()
688{
689 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
690}
691
cd445739
AM
692distfiles_url ()
693{
06541433 694 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
cd445739
AM
695}
696
697distfiles_attic_url ()
698{
06541433 699 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
cd445739
AM
700}
701
702good_md5 ()
703{
704 md5=$(src_md5 "$1")
705 [ "$md5" = "" ] || \
706 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
8ba5cdda
PG
707}
708
a4b50627
AF
709good_size ()
710{
ce40491a
ER
711 size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)"
712 [ -n "$size" -a "$size" -gt 0 ]
a4b50627
AF
713}
714
947025e5 715cvsignore_df ()
716{
717 if [ "$CVSIGNORE_DF" != "yes" ]; then
718 return
719 fi
720 cvsignore=${SOURCE_DIR}/.cvsignore
721 if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then
722 echo "$1" >> $cvsignore
723 fi
724}
725
e7fa3b9f
ER
726cvsup()
727{
ce40491a
ER
728 update_shell_title "cvsup"
729 local OPTIONS="up "
730 if [ -n "$CVSROOT" ]; then
731 OPTIONS="-d $CVSROOT $OPTIONS"
732 fi
b1c6aace 733
ce40491a
ER
734 if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then
735 OPTIONS="$OPTIONS -A"
736 else
737 if [ -n "$CVSDATE" ]; then
738 OPTIONS="$OPTIONS -D $CVSDATE"
739 fi
740 if [ -n "$CVSTAG" ]; then
741 OPTIONS="$OPTIONS -r $CVSTAG"
742 fi
743 fi
e7fa3b9f 744
ce40491a
ER
745 local result=1
746 local retries_counter=0
747 if [ $# = 1 ]; then
748 update_shell_title "cvsup: $*"
749 else
750 update_shell_title "cvsup: $# files"
751 fi
752 while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do
753 retries_counter=$(( $retries_counter + 1 ))
754 output=$(LC_ALL=C cvs $OPTIONS "$@" 2>&1)
755 result=$?
756 [ -n "$output" ] && echo "$output"
757 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
758 echo "Trying again [$*]... ($retries_counter)"
759 update_shell_title "cvsup: retry #$retries_counter"
760 sleep 2
761 continue
762 else
763 break
764 fi
765 done
766 update_shell_title "cvsup: done!"
767 return $result
e7fa3b9f
ER
768}
769
71f8e908
ER
770# returns true if "$1" is ftp, http or https protocol url
771is_url()
772{
773 case "$1" in
774 ftp://*|http://*|https://*)
775 return 0
776 ;;
777 esac
778 return 1
779}
780
ecba6ad5
ER
781update_md5()
782{
783 if [ $# -eq 0 ]; then
784 return
785 fi
786
787 update_shell_title "update md5"
788 if [ -n "$DEBUG" ]; then
518ff1fb
ER
789 set -x
790 set -v
ecba6ad5
ER
791 fi
792
793 cd "$SOURCE_DIR"
794
795 # pass 1: check files to be fetched
796 local todo
797 local need_files
798 for i in "$@"; do
799 local fp=$(nourl "$i")
800 local srcno=$(src_no "$i")
6392b5fd
ER
801 if [ -n "$ADD5" ]; then
802 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
803 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
804 else
805 grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
ecba6ad5
ER
806 fi
807 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
808 need_files="$need_files $i"
809 fi
810 done
811
812 # pass 1a: get needed files
813 if [ "$need_files" ]; then
814 get_files $need_files
815 fi
816
817 # pass 2: proceed with md5 adding or updating
818 for i in "$@"; do
819 local fp=$(nourl "$i")
820 local srcno=$(src_no "$i")
71f8e908
ER
821 local md5=$(grep -iE '^#[ ]*(No)?Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
822 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
823 local tag="Source$srcno-md5"
824 if [[ "$md5" == *NoSource* ]]; then
825 tag="NoSource$srcno-md5"
826 fi
ecba6ad5 827 md5=$(md5sum "$fp" | cut -f1 -d' ')
4efa0b98 828 echo "Updating $tag ($md5: $fp)."
ecba6ad5 829 perl -i -ne '
71f8e908
ER
830 print unless /^\s*#\s*(No)?Source'$srcno'-md5\s*:/i;
831 print "# '$tag':\t'$md5'\n" if /^Source'$srcno'\s*:\s+/;
ecba6ad5
ER
832 ' \
833 $SPECS_DIR/$SPECFILE
834 fi
835 done
836}
837
838check_md5()
839{
840 update_shell_title "check md5"
841
842 for i in "$@"; do
843 if good_md5 "$i" && good_size "$i"; then
844 continue
845 fi
846
847 echo "MD5 sum mismatch or 0 size. Use -U to refetch sources,"
848 echo "or -5 to update md5 sums, if you're sure files are correct."
849 Exit_error err_no_source_in_repo $i
850 done
851}
852
cd445739
AM
853get_files()
854{
7cb24972 855 update_shell_title "get_files"
cd445739
AM
856
857 if [ -n "$DEBUG" ]; then
518ff1fb
ER
858 set -x
859 set -v
cd445739
AM
860 fi
861
f09c0772 862 if [ $# -gt 0 ]; then
cd445739
AM
863 cd "$SOURCE_DIR"
864
b1c6aace 865 if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then
049ab214 866 echo "Warning: No CVS access defined for SOURCES"
b1c6aace
ER
867 NOCVS="yes"
868 fi
869
f2e42a41 870 local nc=0
e7fa3b9f 871 local get_files_cvs=""
3815b69a 872 for i in "$@"; do
f2e42a41 873 nc=$((nc + 1))
dcebdffb 874 local cvsup=0
3815b69a 875 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
f2e42a41 876 update_shell_title "$i"
f09c0772 877 local fp=`nourl "$i"`
ecba6ad5 878 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
ce40491a 879 continue
18e5347d 880 fi
ecba6ad5 881
cd445739 882 FROM_DISTFILES=0
e7e0d4ec 883 local srcmd5=$(src_md5 "$i")
ecba6ad5
ER
884
885 # we know if source/patch is present in cvs/distfiles
886 # - has md5 (in distfiles)
887 # - in cvs... ideas?
888
889 # CHECK: local file didn't exist or always cvs up (first) requested.
f09c0772 890 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
cd445739
AM
891 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
892 echo "Warning: no URL given for $i"
893 fi
894
e7e0d4ec 895 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
a4b50627 896 if good_md5 "$i" && good_size "$i"; then
e7e0d4ec 897 echo "$fp having proper md5sum already exists"
cd445739
AM
898 continue
899 fi
4ea1c265 900 target="$fp"
28b34560
ER
901
902 # prefer mirror over distfiles if there's mirror
903 # TODO: build url list and then try each url from the list
904 if [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
905 url="$im"
906 else
907 url=$(distfiles_url "$i")
908 fi
909
cd445739
AM
910 url_attic=$(distfiles_attic_url "$i")
911 FROM_DISTFILES=1
ecba6ad5
ER
912 # is $url local file?
913 if [[ "$url" = [./]* ]]; then
18a52930 914 update_shell_title "${GETLOCAL%% *}: $url"
cd445739
AM
915 ${GETLOCAL} $url $target
916 else
917 if [ -z "$NOMIRRORS" ]; then
918 url="`find_mirror "$url"`"
919 fi
18a52930 920 update_shell_title "${GETURI%% *}: $url"
ca2e6c31 921 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 922 if [ "`echo $url | grep -E 'ftp://'`" ]; then
18a52930 923 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 924 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739
AM
925 fi
926 fi
ecba6ad5
ER
927
928 # is it empty file?
929 if [ ! -s "$target" ]; then
cd445739
AM
930 rm -f "$target"
931 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
18a52930 932 update_shell_title "${GETLOCAL%% *}: $url_attic"
cd445739
AM
933 ${GETLOCAL} $url_attic $target
934 else
935 if [ -z "$NOMIRRORS" ]; then
936 url_attic="`find_mirror "$url_attic"`"
937 fi
18a52930 938 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 939 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 940 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
ce40491a 941 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 942 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739
AM
943 fi
944 fi
945 fi
ecba6ad5
ER
946
947 if [ -s "$target" ]; then
947025e5 948 cvsignore_df $target
949 else
cd445739
AM
950 rm -f "$target"
951 FROM_DISTFILES=0
952 fi
e7e0d4ec 953 elif [ "$NOCVS" != "yes" -a -z "$srcmd5" ]; then
d05e8080
ER
954 if [ $# -gt 1 ]; then
955 get_files_cvs="$get_files_cvs $fp"
956 update_shell_title "$fp (will cvs up later)"
957 cvsup=1
958 else
959 cvsup $fp
960 fi
cd445739
AM
961 fi
962
f09c0772 963 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
cd445739
AM
964 if [ -z "$NOMIRRORS" ]; then
965 im="`find_mirror "$i"`"
966 else
967 im="$i"
968 fi
ce40491a 969 update_shell_title "${GETURI%% *}: $im"
cd445739 970 ${GETURI} "$im" || \
33da77c4 971 if [ "`echo $im | grep -E 'ftp://'`" ]; then
ce40491a 972 update_shell_title "${GETURI2%% *}: $im"
cd445739 973 ${GETURI2} "$im"
7e365483 974 fi
cd445739
AM
975 fi
976
dcebdffb
ER
977 if [ "$cvsup" = 1 ]; then
978 continue
979 fi
980
cd445739 981 fi
ecba6ad5
ER
982
983 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
f09c0772 984 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
518ff1fb 985 Exit_error err_no_source_in_repo $i
cd445739 986 fi
2a5f078d 987
ecba6ad5 988 # we check md5 here just only to refetch immediately
a4b50627 989 if good_md5 "$i" && good_size "$i"; then
cd445739
AM
990 :
991 elif [ "$FROM_DISTFILES" = 1 ]; then
deccc50e 992 # wrong md5 from distfiles: remove the file and try again
cd445739 993 # but only once ...
deccc50e 994 echo "MD5 sum mismatch. Trying full fetch."
cd445739
AM
995 FROM_DISTFILES=2
996 rm -f $target
18a52930 997 update_shell_title "${GETURI%% *}: $url"
ca2e6c31 998 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 999 if [ "`echo $url | grep -E 'ftp://'`" ]; then
ce40491a 1000 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 1001 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739 1002 fi
ecba6ad5 1003 if [ ! -s "$target" ]; then
cd445739 1004 rm -f "$target"
18a52930 1005 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 1006 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 1007 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
ce40491a 1008 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 1009 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739
AM
1010 fi
1011 fi
1012 test -s "$target" || rm -f "$target"
1013 fi
cd445739 1014 done
e7fa3b9f
ER
1015 SHELL_TITLE_PREFIX=""
1016
1017 if [ "$get_files_cvs" ]; then
ce40491a 1018 cvsup $get_files_cvs
e7fa3b9f 1019 fi
cd445739
AM
1020
1021 if [ "$CHMOD" = "yes" ]; then
3815b69a 1022 CHMOD_FILES="`nourl "$@"`"
cd445739
AM
1023 if [ -n "$CHMOD_FILES" ]; then
1024 chmod $CHMOD_MODE $CHMOD_FILES
1025 fi
1026 fi
cd445739
AM
1027 fi
1028}
1029
1030make_tagver() {
ce40491a 1031 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1032 set -x
1033 set -v
ce40491a 1034 fi
78eab2a1 1035
ce40491a
ER
1036 # Check whether first character of PACKAGE_NAME is legal for tag name
1037 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1038 TAG_PREFIX=tag_
1039 fi
1040 TAGVER=$TAG_PREFIX$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"`
1041 # Remove #kernel.version_release from TAGVER because tagging sources
1042 # could occur with different kernel-headers than kernel-headers used at build time.
1043 TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g')
1044 echo -n "$TAGVER"
cd445739
AM
1045}
1046
1047tag_files()
1048{
1049 TAG_FILES="$@"
1050
1051 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1052 set -x
1053 set -v
cd445739
AM
1054 fi
1055
73ef63d8
ER
1056 echo "Version: $PACKAGE_VERSION"
1057 echo "Release: $PACKAGE_RELEASE"
cd445739 1058
73ef63d8 1059 TAGVER=`make_tagver`
cd445739 1060
73ef63d8
ER
1061 if [ "$TAG_VERSION" = "yes" ]; then
1062 echo "CVS tag: $TAGVER"
1063 fi
1064 if [ -n "$TAG" ]; then
1065 echo "CVS tag: $TAG"
1066 fi
cd445739 1067
39dcc7de 1068 local OPTIONS="tag $CVS_FORCE"
73ef63d8
ER
1069 if [ -n "$CVSROOT" ]; then
1070 OPTIONS="-d $CVSROOT $OPTIONS"
1071 fi
cd445739 1072
73ef63d8
ER
1073 cd "$SOURCE_DIR"
1074 local tag_files
1075 for i in $TAG_FILES; do
1076 # don't tag files stored on distfiles
1077 [ -n "`src_md5 $i`" ] && continue
1078 local fp=`nourl "$i"`
1079 if [ -f "$fp" ]; then
1080 tag_files="$tag_files $fp"
1081 else
1082 Exit_error err_no_source_in_repo $i
03db3356 1083 fi
73ef63d8 1084 done
03db3356 1085
73ef63d8 1086 if [ "$tag_files" ]; then
cd445739 1087 if [ "$TAG_VERSION" = "yes" ]; then
73ef63d8
ER
1088 update_shell_title "tag sources: $TAGVER"
1089 cvs $OPTIONS $TAGVER $tag_files
cd445739
AM
1090 fi
1091 if [ -n "$TAG" ]; then
73ef63d8
ER
1092 update_shell_title "tag sources: $TAG"
1093 cvs $OPTIONS $TAG $tag_files
cd445739 1094 fi
73ef63d8
ER
1095 fi
1096
1097 cd "$SPECS_DIR"
1098 if [ "$TAG_VERSION" = "yes" ]; then
1099 update_shell_title "tag spec: $TAGVER"
1100 cvs $OPTIONS $TAGVER $SPECFILE
1101 fi
1102 if [ -n "$TAG" ]; then
1103 update_shell_title "tag spec: $TAG"
1104 cvs $OPTIONS $TAG $SPECFILE
1105 fi
cd445739
AM
1106}
1107
1108branch_files()
1109{
1110 TAG=$1
1111 echo "CVS branch tag: $TAG"
518ff1fb 1112 shift
cd445739
AM
1113
1114 TAG_FILES="$@"
1115
1116 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1117 set -x
1118 set -v
cd445739
AM
1119 fi
1120
78a5a506
ER
1121 local OPTIONS="tag $CVS_FORCE -b"
1122 if [ -n "$CVSROOT" ]; then
1123 OPTIONS="-d $CVSROOT $OPTIONS"
1124 fi
1125 cd "$SOURCE_DIR"
1126 local tag_files
1127 for i in $TAG_FILES; do
1128 local fp=`nourl "$i"`
1129 if [ -f "$fp" ]; then
1130 tag_files="$tag_files $fp"
1131 else
1132 Exit_error err_no_source_in_repo $i
c10fa4fa 1133 fi
78a5a506
ER
1134 done
1135 if [ "$tag_files" ]; then
1136 cvs $OPTIONS $TAG $tag_files
1137 fi
c10fa4fa 1138
78a5a506
ER
1139 cd "$SPECS_DIR"
1140 cvs $OPTIONS $TAG $SPECFILE
cd445739
AM
1141}
1142
1143
1144
59398507 1145build_package()
1146{
2e5be021 1147 update_shell_title "build_package"
cd445739 1148 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1149 set -x
1150 set -v
cd445739 1151 fi
5a491465 1152
cd445739
AM
1153 cd "$SPECS_DIR"
1154
1155 if [ -n "$TRY_UPGRADE" ]; then
ce40491a 1156 update_shell_title "build_package: try_upgrade"
cd445739 1157 if [ -n "$FLOAT_VERSION" ]; then
cc538c24 1158 TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1
cd445739 1159 else
cc538c24 1160 TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1
cd445739
AM
1161 fi
1162
1163 TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'`
1164
1165 if [ -n "$TNEWVER" ]; then
1166 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1167 echo "New version found, updating spec file to version " $TNEWVER
257af81b
ER
1168 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1169 cp -f $SPECFILE $SPECFILE.bak
1170 fi
cd445739
AM
1171 chmod +w $SPECFILE
1172 eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE"
f7b91886 1173 eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE"
518ff1fb
ER
1174 parse_spec
1175 NODIST="yes" get_files $SOURCES $PATCHES
6392b5fd 1176 update_md5 $SOURCES
975d7b23 1177
cd445739
AM
1178 unset TOLDVER TNEWVER TNOTIFY
1179 fi
1180 fi
1181 cd "$SPECS_DIR"
2a5f078d 1182
cd445739
AM
1183 case "$COMMAND" in
1184 build )
1185 BUILD_SWITCH="-ba" ;;
1186 build-binary )
1187 BUILD_SWITCH="-bb" ;;
1188 build-source )
1189 BUILD_SWITCH="-bs --nodeps" ;;
1190 build-prep )
1191 BUILD_SWITCH="-bp --nodeps" ;;
1192 esac
c890b916 1193
2e5be021 1194 update_shell_title "build_package: $COMMAND"
cd445739
AM
1195 if [ -n "$LOGFILE" ]; then
1196 LOG=`eval echo $LOGFILE`
1197 if [ -d "$LOG" ]; then
1198 echo "Log file $LOG is a directory."
1199 echo "Parse error in the spec?"
518ff1fb 1200 Exit_error err_build_fail
cd445739
AM
1201 fi
1202 if [ -n "$LASTLOG_FILE" ]; then
1203 echo "LASTLOG=$LOG" > $LASTLOG_FILE
1204 fi
1205 RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM
86aafdbe 1206 (time eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG
cd445739
AM
1207 RETVAL=`cat $RES_FILE`
1208 rm $RES_FILE
1209 if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1210 if [ "$RETVAL" -eq "0" ]; then
1211 mv $LOG $LOGDIROK
1212 else
1213 mv $LOG $LOGDIRFAIL
1214 fi
1215 fi
8ba5cdda 1216 else
86aafdbe 1217 eval ${NICE_COMMAND} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND $TARGET_SWITCH $SPECFILE
cd445739 1218 RETVAL=$?
8ba5cdda 1219 fi
cd445739
AM
1220 if [ "$RETVAL" -ne "0" ]; then
1221 if [ -n "$TRY_UPGRADE" ]; then
796a8a95 1222 echo "\n!!! Package with new version cannot be built automagically\n"
257af81b
ER
1223 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1224 mv -f $SPECFILE.bak $SPECFILE
1225 fi
cd445739 1226 fi
518ff1fb 1227 Exit_error err_build_fail
cd445739
AM
1228 fi
1229 unset BUILD_SWITCH
1230}
1231
1232nourl()
1233{
1234 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1235}
1236
cd445739
AM
1237install_required_packages()
1238{
1239 run_poldek -vi $1
1240 return $?
1241}
1242
fa4bf1df
ER
1243find_spec_bcond() {
1244 # taken from find-spec-bcond, but with just getting the list
1245 local SPEC="$1"
1246 # quick revert hint: '$RPMBUILD --bcond $SPEC'
1247 awk -F"\n" '
1248 /^%changelog/ { exit }
1249 /_with(out)?_[_a-zA-Z0-9]+/{
1250 match($0, /_with(out)?_[_a-zA-Z0-9]+/);
1251 print substr($0, RSTART, RLENGTH);
1252 }
1253 /^%bcond_with/{
1254 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
1255 bcond = substr($0, RSTART +5 , RLENGTH -5);
1256 gsub(/[ \t]+/,"_",bcond);
1257 print bcond
1258 }' $SPEC | LC_ALL=C sort -u
1259}
1260
117d9861 1261process_bcondrc() {
301cbfd4
ER
1262 # expand bconds from ~/.bcondrc
1263 # The file structure is like gentoo's package.use:
1264 # ---
1265 # * -selinux
1266 # samba -mysql -pgsql
47a8df12 1267 # w32codec-installer license_agreement
301cbfd4
ER
1268 # php +mysqli
1269 # ---
fa4bf1df 1270 if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then
117d9861
ER
1271 :
1272 else
1273 return
1274 fi
301cbfd4 1275
117d9861 1276 SN=${SPECFILE%%\.spec}
c8a3e2ac 1277
117d9861
ER
1278 local bcondrc=$HOME/.bcondrc
1279 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
301cbfd4 1280
117d9861 1281 local bcond_avail=$(find_spec_bcond $SPECFILE)
301cbfd4 1282
117d9861
ER
1283 while read pkg flags; do
1284 # ignore comments
1285 [[ "$pkg" == \#* ]] && continue
1286
1287 # any package or current package?
1288 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1289 for flag in $flags; do
1290 local opt=${flag#[+-]}
1291
1292 # use only flags which are in this package.
1293 if [[ $bcond_avail = *${opt}* ]]; then
1294 if [[ $flag = -* ]]; then
1295 if [[ $BCOND != *--with?${opt}* ]]; then
1296 BCOND="$BCOND --without $opt"
1297 fi
1298 else
1299 if [[ $BCOND != *--without?${opt}* ]]; then
1300 BCOND="$BCOND --with $opt"
301cbfd4
ER
1301 fi
1302 fi
117d9861
ER
1303 fi
1304 done
1305 fi
1306 done < $bcondrc
1307 update_shell_title "parse ~/.bcondrc: DONE!"
1308}
1309
1310set_bconds_values()
1311{
1312 update_shell_title "set bcond values"
1313
1314 AVAIL_BCONDS_WITHOUT=""
1315 AVAIL_BCONDS_WITH=""
1316 if `grep -q ^%bcond ${SPECFILE}`; then
1317 BCOND_VERSION="NEW"
1318 elif `egrep -q ^#\ *_with ${SPECFILE}`; then
1319 BCOND_VERSION="OLD"
1320 else
1321 return
301cbfd4
ER
1322 fi
1323
117d9861
ER
1324 local bcond_avail=$(find_spec_bcond $SPECFILE)
1325 process_bcondrc "$SPECFILE"
1326
fa4bf1df 1327 update_shell_title "parse bconds"
cd445739 1328 case "${BCOND_VERSION}" in
fa4bf1df 1329 NONE)
7e365483 1330 :
cd445739 1331 ;;
7e365483 1332 OLD)
cd445739 1333 echo "Warning: This spec has old style bconds. Fix it || die."
fa4bf1df 1334 for opt in `echo "$bcond_avail" | grep ^_without_`
cd445739 1335 do
fa4bf1df
ER
1336 AVAIL_BCOND_WITHOUT=${opt#_without_}
1337 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
cd445739
AM
1338 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1339 else
1340 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1341 fi
1342 done
2a5f078d 1343
fa4bf1df 1344 for opt in `echo "$bcond_avail" | grep ^_with_`
cd445739 1345 do
fa4bf1df
ER
1346 AVAIL_BCOND_WITH=${opt#_with_}
1347 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
cd445739
AM
1348 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1349 else
1350 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1351 fi
1352 done
1353 ;;
1354 NEW)
fa4bf1df
ER
1355 local cond_type="" # with || without
1356 for opt in $bcond_avail; do
cd445739
AM
1357 case "$opt" in
1358 _without)
1359 cond_type="without"
1360 ;;
1361 _with)
1362 cond_type="with"
1363 ;;
f8d24cee 1364 _without_*)
fa4bf1df
ER
1365 AVAIL_BCOND_WITHOUT=${opt#_without_}
1366 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
f8d24cee 1367 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1368 else
1369 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1370 fi
1371 ;;
1372 _with_*)
fa4bf1df
ER
1373 AVAIL_BCOND_WITH=${opt#_with_}
1374 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
f8d24cee 1375 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1376 else
1377 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1378 fi
1379 ;;
cd445739
AM
1380 *)
1381 case "$cond_type" in
1382 with)
1383 cond_type=''
1384 AVAIL_BCOND_WITH="$opt"
fa4bf1df 1385 if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then
cd445739
AM
1386 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>"
1387 else
1388 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH"
1389 fi
7e365483 1390 ;;
cd445739
AM
1391 without)
1392 cond_type=''
1393 AVAIL_BCOND_WITHOUT="$opt"
fa4bf1df 1394 if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then
cd445739
AM
1395 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>"
1396 else
1397 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT"
1398 fi
1399 ;;
1400 esac
1401 ;;
1402 esac
1403 done
1404 ;;
1405 esac
1406}
1407
1408run_sub_builder()
1409{
1410 package_name="${1}"
af6b168f 1411 update_shell_title "run_sub_builder $package_name"
cd445739
AM
1412 #
1413