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