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