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