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