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