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