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