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