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