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