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