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