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