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