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