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