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