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