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