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