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