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