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