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