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