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