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