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