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