]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
Print more when rpmbuild fails. Use known/good source dir instead of relying on ...
[packages/rpm-build-tools.git] / builder.sh
CommitLineData
10d92f71 1#!/bin/ksh
44058243 2#
dece74ed
AM
3# This program is free software, distributed under the terms of
4# the GNU General Public License Version 2.
5#
cd445739 6# -----------
cd445739 7# Exit codes:
2a5f078d 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)
67963237 20# 110 - Functions not yet implemented
cd445739 21
f8e50be5 22# Notes (todo/bugs):
f8e50be5
ER
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)
19aa2571 25# - does not respect NoSource: X, and tries to cvs up such files [ example: VirtualBox-bin.spec and its Source0 ]
f8e50be5
ER
26# TODO:
27# - ability to do ./builder -bb foo.spec foo2.spec foo3.spec
1ffcdaff
ER
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
6ca6f876
ZU
31# - builder --help:
32# basename: missing operand
33# Try `basename --help' for more information.
34# -- and the normal usage info --
35
9d99a240
ER
36PROGRAM=${0##*/}
37APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
b1f2a05a 38VERSION="v0.35"
d43959a2 39VERSIONSTRING="\
b71f5024 40Build package utility from PLD Linux Packages repository
7ec99798 41$VERSION (C) 1999-2020 Free Penguins".
d43959a2 42
5cf31543
ER
43# Clean PATH without /usr/local or user paths
44CLEAN_PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin"
b03f053b 45
b7cc0c94
ER
46# required rpm-build-macros
47RPM_MACROS_VER=1.534
48
cd445739 49COMMAND="build"
64ea5308 50TARGET=""
cd445739 51
bde1c404 52SPECFILE=""
d287305c 53BE_VERBOSE=""
4003ad8c 54QUIET=""
cd445739
AM
55CLEAN=""
56DEBUG=""
57NOURLS=""
cd445739
AM
58NOCVSSPEC=""
59NODIST=""
47761337 60NOINIT=""
bc10f694 61PREFMIRRORS=""
cd445739 62UPDATE=""
cd445739
AM
63ADD5=""
64NO5=""
65ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
cd445739 66
6c1b2e7d
PZ
67# use rpm 4.4.6+ digest format instead of comments if non-zero
68USEDIGEST=
69
e3aa6f5e
ER
70# user agent when fetching files
71USER_AGENT="PLD/Builder($VERSION)"
72
cd445739
AM
73# It can be used i.e. in log file naming.
74# See LOGFILE example.
75DATE=`date +%Y-%m-%d_%H-%M-%S`
76
7534a77d
ER
77# target arch, can also be used for log file naming
78TARGET=$(rpm -E %{_target})
79
01d8ce69 80# Note the *single* quotes, this allows using shell variables expanded at build time
cd445739
AM
81# Example: LOGFILE='../log.$PACKAGE_NAME'
82# Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
d280fd97 83# Example: LOGFILE='$PACKAGE_NAME/$PACKAGE_NAME.$DATE.log'
f5687002 84# Example: LOGFILE='$PACKAGE_NAME.$DATE.log'
01d8ce69 85# Example: LOGFILE='.log.$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.$TARGET.$DATE'
cd445739
AM
86LOGFILE=''
87
12da9e3d
ER
88# use teeboth Perl wrapper
89# temporary option to disable if broken
90USE_TEEBOTH=yes
91
cd445739
AM
92LOGDIR=""
93LOGDIROK=""
94LOGDIRFAIL=""
95LASTLOG_FILE=""
96
97CHMOD="no"
1da227e8 98CHMOD_MODE="0644"
cd445739 99RPMOPTS=""
d1c5a9a7 100RPMBUILDOPTS=""
cd445739
AM
101BCOND=""
102GROUP_BCONDS="no"
ccffa567
ER
103
104# create symlinks for tools in PACKAGE_DIR, see get_spec()
2dd0af86 105SYMLINK_TOOLS="no"
d287305c 106
107PATCHES=""
108SOURCES=""
cd445739 109ICONS=""
d287305c 110PACKAGE_RELEASE=""
111PACKAGE_VERSION=""
112PACKAGE_NAME=""
14bead22 113ASSUMED_NAME=""
fd71d65c 114PROTOCOL="http"
6d641507 115IPOPT=""
2060f498
AM
116
117# use lftp by default when available
1d8d84a5 118test -z "${USE_LFTP+x}" && lftp --version > /dev/null 2>&1 && USE_LFTP=yes
d4c8d3a9 119PARALLEL_DOWNLOADS=10
2060f498 120
cd445739 121WGET_RETRIES=${MAX_WGET_RETRIES:-0}
cd445739 122
939f2c12 123CVS_FORCE=""
f123bcb5 124CVSIGNORE_DF="yes"
cd445739 125CVSTAG=""
7446994b
KK
126GIT_SERVER="git://git.pld-linux.org"
127GIT_PUSH="git@git.pld-linux.org"
76636346 128PACKAGES_DIR="packages"
a8f917c2 129HEAD_DETACHED=""
3189511a 130DEPTH=""
3f79cb18 131ALL_BRANCHES=""
608c01a7 132REMOTE_PLD="origin"
406b9ecf 133NEW_REPO=""
939f2c12 134
cd445739
AM
135RES_FILE=""
136
cd445739 137DISTFILES_SERVER="://distfiles.pld-linux.org"
d4730dae 138ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
cd445739 139
36d03934 140DEF_NICE_LEVEL=19
86aafdbe 141SCHEDTOOL="auto"
cd445739
AM
142
143FAIL_IF_NO_SOURCES="yes"
144
18e5347d
ER
145# let get_files skip over files which are present to get those damn files fetched
146SKIP_EXISTING_FILES="no"
147
975d7b23 148TRY_UPGRADE=""
257af81b
ER
149# should the specfile be restored if upgrade failed?
150REVERT_BROKEN_UPGRADE="yes"
151
90baf90b
ER
152if rpm --specsrpm 2>/dev/null; then
153 FETCH_BUILD_REQUIRES_RPMSPECSRPM="yes"
ce40491a 154 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
90baf90b
ER
155else
156 FETCH_BUILD_REQUIRES_RPMSPECSRPM="no"
157 if [ -x /usr/bin/rpm-getdeps ]; then
158 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
159 else
160 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
161 fi
ab4a2b6e
ER
162fi
163
8a390970 164UPDATE_POLDEK_INDEXES_OPTS=""
90baf90b 165
cd445739
AM
166# Here we load saved user environment used to
167# predefine options set above, or passed to builder
168# in command line.
169# This one reads global system environment settings:
170if [ -f ~/etc/builderrc ]; then
171 . ~/etc/builderrc
172fi
173# And this one cascades settings using user personal
174# builder settings.
175# Example of ~/.builderrc:
176#
177#UPDATE_POLDEK_INDEXES="yes"
8a390970 178#UPDATE_POLDEK_INDEXES_OPTS="--mo=nodiff"
cd445739
AM
179#FETCH_BUILD_REQUIRES="yes"
180#REMOVE_BUILD_REQUIRES="force"
181#GROUP_BCONDS="yes"
182#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
982e358c 183#TITLECHANGE=no
aa7e48da
ER
184
185SU_SUDO="sudo"
186
cd445739
AM
187if [ -n "$HOME_ETC" ]; then
188 USER_CFG="$HOME_ETC/.builderrc"
20117088 189 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
cd445739
AM
190else
191 USER_CFG=~/.builderrc
20117088 192 BUILDER_MACROS=~/.builder-rpmmacros
cd445739
AM
193fi
194
195[ -f "$USER_CFG" ] && . "$USER_CFG"
196
86aafdbe
ER
197if [ "$SCHEDTOOL" = "auto" ]; then
198 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
199 SCHEDTOOL="schedtool -B -e"
200 else
201 SCHEDTOOL="no"
202 fi
203fi
204
ca2e6c31 205if [ -n "$USE_PROZILLA" ]; then
6d641507 206 GETURI=download_proz
ca2e6c31 207elif [ -n "$USE_AXEL" ]; then
6d641507 208 GETURI=download_axel
9639be96 209elif [ -n "$USE_LFTP" ]; then
9639be96 210 GETURI=download_lftp
ca2e6c31 211else
6d641507 212 GETURI=download_wget
2bc5451f 213fi
11468b23 214
e0c78ad6 215GETLOCAL=${GETLOCAL:-cp -a}
11468b23 216
ac128191
JR
217RPM="rpm"
218RPMBUILD="rpmbuild"
11468b23 219
c86939e2 220#
221# sanity checks
222#
223if [ -d $HOME/rpm/SOURCES ]; then
224 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
225 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
226 exit 1
227fi
228
a8c9a155 229POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
aa7e48da 230POLDEK_CMD="$SU_SUDO /usr/bin/poldek"
11468b23 231
12da9e3d 232# TODO: add teeboth
aa7e48da 233# TODO: what this function does?
f6711e2a 234run_poldek() {
390d081d 235 RES_FILE=$(tempfile)
cd445739
AM
236 if [ -n "$LOGFILE" ]; then
237 LOG=`eval echo $LOGFILE`
238 if [ -n "$LASTLOG_FILE" ]; then
239 echo "LASTLOG=$LOG" > $LASTLOG_FILE
240 fi
aa7e48da 241 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
12da9e3d 242 # FIXME $exit_pldk undefined
cd445739
AM
243 return $exit_pldk
244 else
aa7e48da 245 (${NICE_COMMAND} ${POLDEK_CMD} --noask `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
cd445739
AM
246 return `cat ${RES_FILE}`
247 rm -rf ${RES_FILE}
248 fi
249}
250
cd445739
AM
251#---------------------------------------------
252# functions
da946cd6 253
6d641507
AM
254download_prozilla() {
255 local outfile=$1 url=$2 retval
256
257 proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS -O "$outfile" "$url"
258 retval=$?
259
260 return $retval
261}
262
263download_axel() {
264 local outfile=$1 url=$2 retval
265
266 axel -a $AXEL_OPTS -o "$outfile" "$url"
267 retval=$?
268
269 return $retval
270}
271
272download_wget() {
20494437 273 local outfile=$1 url=$2 retval wget_help
94750043 274 if [ -z "${WGET_OPTS_SET+x}" ]; then
20494437
JP
275 wget_help="$(wget --help 2>&1)"
276 echo "$wget_help" | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
277 echo "$wget_help" | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
278 echo "$wget_help" | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
279 echo "$wget_help" | grep -q -- ' --no-iri ' && WGET_OPTS="$WGET_OPTS --no-iri"
94750043
JP
280 WGET_OPTS="-c -nd -t$WGET_RETRIES $WGET_OPTS --user-agent=$USER_AGENT $IPOPT --passive-ftp"
281 WGET_OPTS_SET=1
282 fi
6d641507 283
94750043 284 wget $WGET_OPTS -O "$outfile" "$url"
6d641507
AM
285 retval=$?
286 if [ $retval -ne 0 ]; then
287 if [ "`echo $url | grep -E 'ftp://'`" ]; then
288 ${GETURI} -O "$outfile" "$url"
289 retval=$?
290 fi
291 fi
292 return $retval
293}
294
f4bac425 295download_lftp() {
6928bb29 296 local outfile=$1 url=$2 retval tmpfile
72b75eec 297 tmpfile=$(tempfile) || exit 1
4d1fc6ce
AM
298 lftp -c "
299 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
6d641507
AM
300 $([ "$IPOPT" = "-4" ] && echo "set dns:order \"inet\";")
301 $([ "$IPOPT" = "-6" ] && echo "set dns:order \"inet6\";")
78ff632e 302 set ssl:verify-certificate no;
4d1fc6ce
AM
303 set net:max-retries $WGET_RETRIES;
304 set http:user-agent \"$USER_AGENT\";
d4c8d3a9 305 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
4d1fc6ce 306 "
f4bac425
ER
307
308 retval=$?
309 if [ $retval -eq 0 ]; then
310 mv -f "$tmpfile" "$outfile"
311 else
312 rm -f "$tmpfile"
313 fi
314 return $retval
315}
316
f6711e2a 317usage() {
cd445739 318 if [ -n "$DEBUG" ]; then set -xv; fi
647fead0
ER
319# NOTE:
320# to make this output parseable by bash-completion _parse_help()
321# if the line contains short and long option, it will take only the long option
322# but if you want both being completed, put the short option to separate line
cd445739 323 echo "\
3f79cb18 324Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
6594293d 325[-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
0c8e5e9d 326[{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
fd71d65c 327[-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
ccb03bc0 328[-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
a7b2951c 329[-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
b3b584c5 330[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
6594293d 331[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
3009b80d 332[--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
ccb03bc0 333<package>[.spec][:tag]
2a5f078d 334
647fead0
ER
335-4 - force IPv4 when transferring files
336-6 - force IPv6 when transferring files
337-5,
338--update-md5 - update md5 comments in spec, implies -nd -ncs
339-a5,
340--add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
4ca1edbd 341--all-branches - make shallow fetch of all branches; --depth required
cd445739 342-n5, --no-md5 - ignore md5 comments in spec
9243e80b
ER
343-D, --debug - enable builder script debugging mode,
344-debug - produce rpm debug package (same as --opts -debug)
d43959a2
ER
345-V, --version - output builder version string
346--short-version - output builder short version
647fead0
ER
347-a - try add new package to PLD repo.
348-b,
349-ba
350 - get all files from PLD repo or HTTP/FTP and build package
cd445739 351 from <package>.spec,
647fead0 352-bb - get all files from PLD repo or HTTP/FTP and build binary
cd445739 353 only package from <package>.spec,
647fead0 354-bp - execute the %prep phase of <package>.spec,
6594293d
AG
355-bc - execute the %build phase of <package>.spec,
356-bi - execute the %install phase of <package>.spec
4ca1edbd 357-bl - execute the %files phase of <package>.spec
647fead0 358-bs - get all files from PLD repo or HTTP/FTP and only pack
cd445739 359 them into src.rpm,
6594293d 360--short-circuit - short-circuit build
cd445739 361-B, --branch - add branch
647fead0
ER
362-c,
363--clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
387eaf99 364 may be used with building process.
6f10b394 365-m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
4ca1edbd
KK
366 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
367-cf, --cvs-force - use -f when tagging
eccfb714 368--define '<macro> <value>'
cd445739 369 - define a macro <macro> with value <value>,
4ca1edbd 370--depth <number> - make shallow fetch
44058243
ER
371--alt_kernel <kernel>
372 - same as --define 'alt_kernel <kernel>'
cd445739 373--nodeps - rpm won't check any dependences
647fead0
ER
374-g
375--get - get <package>.spec and all related files from PLD repo
cd445739 376-h, --help - this message,
647fead0
ER
377-j N - set %_smp_mflags to propagate concurrent jobs
378--ftp - use FTP protocol to access distfiles server
379--http - use HTTP protocol to access distfiles server
380-l <logfile>, --logtofile=<logfile>
cd445739 381 - log all to file,
cd445739 382-ncs, --no-cvs-specs
ccb03bc0 383 - don't pull from PLD repo
cd445739
AM
384-nd, --no-distfiles - don't download from distfiles
385-nm, --no-mirrors - don't download from mirror, if source URL is given,
386-nu, --no-urls - don't try to download from FTP/HTTP location,
7cbc2d88 387-ns, --no-srcs - don't download Sources/Patches
cd445739
AM
388-ns0, --no-source0 - don't download Source0
389-nn, --no-net - don't download anything from the net
647fead0 390-p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
4ca1edbd
KK
391-pm, --prefer-mirrors
392 - prefer mirrors (if any) over distfiles for SOURCES
b572253e 393--no-init - don't initialize builder paths (SPECS and SOURCES)
18e5347d 394-ske,
4ca1edbd
KK
395--skip-existing-files
396 - skip existing files in get_files
cd445739
AM
397--opts <rpm opts> - additional options for rpm
398-q, --quiet - be quiet,
ccb03bc0
KK
399--date yyyy-mm-dd - build package using resources from specified date,
400-r <tag>, --cvstag <ref>
401 - build package using resources from specified branch/tag,
5053a974 402-A - build package using master branch as any sticky tags/branch/date being reset.
cd445739
AM
403-R, --fetch-build-requires
404 - fetch what is BuildRequired,
405-RB, --remove-build-requires
406 - remove all you fetched with -R or --fetch-build-requires
407 remember, this option requires confirmation,
408-FRB, --force-remove-build-requires
409 - remove all you fetched with -R or --fetch-build-requires
410 remember, this option works without confirmation,
4ca1edbd
KK
411-sd, --source-distfiles
412 - list sources available from distfiles (intended for offline
06541433
JR
413 operations; does not work when Icon field is present
414 but icon file is absent),
4ca1edbd
KK
415-sc, --source-cvs - list sources available from PLD repo
416-sdp, --source-distfiles-paths
417 - list sources available from distfiles -
06541433
JR
418 paths relative to distfiles directory (intended for offline
419 operations; does not work when Icon field is present
420 but icon file is absent),
a7eefc54 421-sf, --source-files - list sources - bare filenames (intended for offline
422 operations; does not work when Icon field is present
3621e588 423 but icon file is absent),
4ca1edbd
KK
424-lsp, --source-paths
425 - list sources - filenames with full local paths (intended for
a7eefc54 426 offline operations; does not work when Icon field is present
3621e588 427 but icon file is absent),
2dddf439
ER
428-su, --source-urls - list urls - urls to sources and patches
429 intended for copying urls with spec with lots of macros in urls
ccb03bc0
KK
430-T <tag> , --tag <tag>
431 - add git tag <tag> for files,
cd445739 432-Tvs, --tag-version-stable
ccb03bc0 433 - add git tags STABLE and NAME-VERSION-RELEASE for files,
cd445739 434-Ts, --tag-stable
ccb03bc0 435 - add git tag STABLE for files,
647fead0
ER
436-Tv,
437--tag-version - add git tag NAME-VERSION-RELEASE for files,
cd445739
AM
438-Tp, --tag-prefix <prefix>
439 - add <prefix> to NAME-VERSION-RELEASE tags,
440-tt, --test-tag <prefix>
441 - fail if tag is already present,
50321881
JK
442-ir, --integer-release-only
443 - allow only integer and snapshot releases
cd445739
AM
444-v, --verbose - be verbose,
445-u, --try-upgrade - check version, and try to upgrade package
446-un, --try-upgrade-with-float-version
447 - as above, but allow float version
4ca1edbd 448 php-pear-Services_Digg/
0907f1eb 449--upgrade-version - upgrade to specified version in try-upgrade
deccc50e 450-U, --update - refetch sources, don't use distfiles, and update md5 comments
cd445739
AM
451-Upi, --update-poldek-indexes
452 - refresh or make poldek package index files.
647fead0
ER
453-sp <patchnumber>,
454--skip-patch <patchnumber>
8bd5e66d 455 - don't apply <patchnumber>. may be repeated.
647fead0
ER
456-np <patchnumber>,
457--nopatch <patchnumber>
8bd5e66d 458 - abort instead of applying patch <patchnumber>
fc8edbe5
ER
459--noinit
460 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
dfe2cb9a
MK
461--show-bconds - show available conditional builds, which can be used
462 - with --with and/or --without switches.
b05205af
BZ
463--show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
464 In other words, the output is parseable by scripts.
24a97174 465--show-avail-bconds - show available bconds
647fead0
ER
466--with <feature>,
467--without <feature>
cd445739
AM
468 - conditional build package depending on %_with_<feature>/
469 %_without_<feature> macro switch. You may now use
470 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
471 constructions. Set GROUP_BCONDS to yes to make use of it.
6dd19291 472--target <platform>, --target=<platform>
a6494cd4 473 - build for platform <platform>.
5eb1d24b
ER
474--init-rpm-dir, --init
475 - initialize ~/rpm directory structure
5a491465 476"
477}
478
e267517f
ER
479is_rpmorg() {
480 local v
481
ae0dd942 482 v=$(LC_ALL=C LANG=C rpm --version 2>&1)
e267517f 483 v=${v#RPM version } # rpm 4
30e78ca0 484 v=${v#rpm \(RPM\) } # rpm 5
e267517f
ER
485
486 case "$v" in
487 4.5|5.*)
488 return 1
489 ;;
490 4.*)
491 return 0;
492 ;;
30e78ca0
JP
493 *)
494 echo "ERROR: unsupported RPM version $v" >&2
495 exit 1
e267517f
ER
496 esac
497}
498
390d081d
ER
499# create tempfile. as secure as possible
500tempfile() {
aa7e48da
ER
501 local prefix=builder.$PACKAGE_NAME${1:+.$1}
502 mktemp --tmpdir -t $prefix.XXXXXX || echo ${TMPDIR:-/tmp}/$prefix.$RANDOM.$$
390d081d
ER
503}
504
397fa865 505tempdir() {
aa7e48da
ER
506 local prefix=builder.$PACKAGE_NAME${1:+.$1}
507 mktemp --tmpdir -d $prefix.XXXXXX
397fa865
KK
508}
509
8cc8f5c0 510# inserts git log instead of %changelog
053a88fc 511# @output directory containing modified specfile
8cc8f5c0 512insert_gitlog() {
397fa865 513 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
8cc8f5c0
ER
514
515 # allow this being customized
516 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
517
518 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
519 # otherwise i'd use --date=iso here
520 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
b34dcd91 521 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
8cc8f5c0
ER
522 # NOTE: changelog date is always in UTC for rpmbuild
523 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
9fd1eb80 524 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
f8704064 525 local logfmt='%B%n'
31f3bc1c
ER
526 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
527 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
9c0fe78c 528 done > $gitlog
9e269b3c
ER
529
530 # add link to full git logs
e93ee6d9 531 local giturl="http://git.pld-linux.org/?p=packages/${SPECFILE%.spec}.git;a=log"
9e269b3c
ER
532 if [ -n "$CVSTAG" ]; then
533 giturl="$giturl;h=$CVSTAG"
534 fi
535 local gitauthor="PLD Linux Team <feedback@pld-linux.org>"
536 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
537 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
538 print;
539 exit
540 }' > $speclog
541
542 LC_ALL=C gawk '/^\* /{printf("* %s %s\n", strftime("%a %b %d %Y", $2), substr($0, length($1)+length($2)+length($3)+4)); next}{print}' $gitlog >> $speclog
8cc8f5c0
ER
543 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
544 a%changelog
545 r $speclog
546 }
397fa865 547 " > $specdir/$SPECFILE
8cc8f5c0 548 rm -f $gitlog $speclog
397fa865 549 echo $specdir
8cc8f5c0
ER
550}
551
12da9e3d
ER
552# @param string logfile
553# @param varargs... commands to execute
554teeboth() {
555 local rc
556 # use teeboth from toys/cleanbuild, if available and enabled
557 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
558 $APPDIR/teeboth "$@"
559 rc=$?
560 else
561 local efile rc logfile=$1; shift
562 if [ "$logfile" ]; then
563 efile=$(tempfile)
806a7b72 564 { "$@" 2>&1; echo $? > $efile; } | tee -a $logfile
12da9e3d
ER
565 rc=$(< $efile)
566 rm -f $efile
567 else
551a62ae 568 "$@"
12da9e3d
ER
569 rc=$?
570 fi
571 fi
572 return $rc
573}
574
31d2bd0b
ER
575# change dependency to specname
576# common changes:
577# - perl(Package::Name) -> perl-Package-Name
578depspecname() {
aa7e48da
ER
579 local DEPS
580
581 if [ $# -gt 0 ]; then
582 DEPS="$@"
583 else
584 DEPS=$(cat)
585 fi
586
587 echo "$DEPS" | tr ' ' '\n' | sed -re '
588 # perl virtual deps
589 /perl\(.*\)/{
590 s/perl\((.*)\)/perl-\1/
591 s/::/-/g
592 }
31d2bd0b 593
aa7e48da
ER
594 s/apache\(EAPI\)-devel/apache-devel/
595
596 s/db-devel/db5.3-devel/
597 s/libjpeg-devel/libjpeg-turbo-devel/
598 '
31d2bd0b
ER
599}
600
c890b916 601update_shell_title() {
6c40c5a2 602 [ -t 2 ] || return
0b65d15e 603 local len=${COLUMNS:-80}
5c795f16 604 local msg="$(echo "$*" | cut -c-$len)"
0b65d15e 605
e225de91
ER
606 if [ -n "$BE_VERBOSE" ]; then
607 echo >&2 "$(date +%s.%N) $*"
608 fi
609
5c795f16 610 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
138bbc98
ER
611 local pkg
612 if [ -n "$PACKAGE_NAME" ]; then
613 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
614 else
615 pkg=${SPECFILE}
616 fi
617
618 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
a8c9a155 619 msg=$(echo $msg | tr -d '\n\r')
982e358c
MP
620 case "$TERM" in
621 cygwin|xterm*)
622 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
623 ;;
624 screen*)
625 echo >&2 -ne "\033]0;$msg\007"
626 ;;
627 esac
628 fi
c890b916
ER
629}
630
7e40520f
ER
631# set TARGET from BuildArch: from SPECFILE
632set_spec_target() {
ce40491a 633 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
8c91ee46 634 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
ce40491a 635 if [ "$tmp" ]; then
8c91ee46 636 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
7e40520f
ER
637 TARGET="$tmp"
638 case "$RPMBUILD" in
639 "rpmbuild")
f9109a96 640 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
7e40520f 641 "rpm")
ce40491a 642 TARGET_SWITCH="--target=$TARGET" ;;
7e40520f 643 esac
ce40491a
ER
644 fi
645 fi
7e40520f
ER
646}
647
ace3fd80
ER
648# runs rpm with minimal macroset
649minirpm() {
ace3fd80 650 # TODO: move these to /usr/lib/rpm/macros
20117088 651 cat > $BUILDER_MACROS <<'EOF'
5b5e5f7f 652%x8664 x86_64 amd64 ia32e
f78a0bb7 653%alt_kernel %{nil}
654%_alt_kernel %{nil}
5ff15c97 655%bootstrap_release() %{1}
407b204b
ER
656%requires_releq_kernel_up(s:n:) %{nil}
657%requires_releq_kernel_smp(s:n:) %{nil}
658%requires_releq_kernel(s:n:) %{nil}
6b8134e3 659%requires_releq() %{nil}
bb01dee9 660%pyrequires_eq() %{nil}
559d511f 661%requires_eq() %{nil}
c13be3d1 662%requires_eq_to() %{nil}
99c05e13 663%requires_ge() %{nil}
500b0eb8
ER
664%requires_ge_to() %{nil}
665%requires_ge() %{nil}
407b204b
ER
666%releq_kernel_up(n:) ERROR
667%releq_kernel_smp(n:) ERROR
668%releq_kernel(n:) ERROR
e94e25f9 669%py_postclean(x:) ERROR
74d9fd14 670%kgcc_package ERROR
237bd3f1 671%_fontsdir ERROR
7141278d 672%ruby_version ERROR
673%ruby_ver_requires_eq() %{nil}
674%ruby_mod_ver_requires_eq() %{nil}
c13be3d1 675%__php_api_requires() %{nil}
7141278d 676%php_major_version ERROR
677%php_api_version ERROR
99f819cf
AM
678%requires_xorg_xserver_extension %{nil}
679%requires_xorg_xserver_xinput %{nil}
680%requires_xorg_xserver_font %{nil}
681%requires_xorg_xserver_videodrv %{nil}
7141278d 682%py_ver ERROR
41035426
ER
683%perl_vendorarch ERROR
684%perl_vendorlib ERROR
703ae20b
ER
685# damn. need it here! - copied from /usr/lib/rpm/macros.build
686%tmpdir %(echo "${TMPDIR:-/tmp}")
1f28fcb7
ER
687%patchset_source(f:b:) %(
688 base=%{-b*}%{!-b*:10000};
689 start=$(expr $base + %1);
690 end=$(expr $base + %{?2}%{!?2:%{1}});
691 # we need to call seq twice as it doesn't allow two formats
692 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
693 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
694 paste %{tmpdir}/__ps{1,2};
695 rm -f %{tmpdir}/__ps{1,2};
696) \
697%{nil}
991f09a5
ER
698%add_etc_shells(p) %{p:<lua>}
699%remove_etc_shells(p) %{p:<lua>}
709995c4
ER
700%lua_add_etc_shells() %{nil}
701%lua_remove_etc_shells() %{nil}
5adfcd17 702%required_jdk jdk
0ca65fa4 703%buildrequires_jdk %{nil}
f9063abe 704%pear_package_print_optionalpackages %{nil}
fb198857 705EOF
3d12d055 706 if [ "$NOINIT" = "yes" ] ; then
20117088 707 cat >> $BUILDER_MACROS <<'EOF'
3d12d055
JR
708%_specdir ./
709%_sourcedir ./
710EOF
c039643c 711 fi
e267517f
ER
712 if ! is_rpmorg; then
713 local safe_macrofiles
ac128191
JR
714 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
715 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
716 else
717 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --load "$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
718 fi
ace3fd80
ER
719}
720
721cache_rpm_dump() {
722 if [ -n "$DEBUG" ]; then
723 set -x
724 set -v
725 fi
726
d1d24c14 727 if [ -x /usr/bin/rpm-specdump ]; then
525bf240 728 update_shell_title "cache_rpm_dump using rpm-specdump command"
646d81cf 729 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
d1d24c14 730 else
525bf240 731 update_shell_title "cache_rpm_dump using rpmbuild command"
d1d24c14
ER
732 local rpm_dump
733 rpm_dump=`
734 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
735 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
736 case "$RPMBUILD" in
737 rpm)
738 ARGS='-bp'
739 ;;
740 rpmbuild)
741 ARGS='--nodigest --nosignature --nobuild'
742 ;;
743 esac
744 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
745 `
746 if [ $? -gt 0 ]; then
747 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
748 echo "$error" >&2
749 Exit_error err_build_fail
750 fi
d05e8080 751
d1d24c14
ER
752 # make small dump cache
753 rpm_dump_cache=`echo "$rpm_dump" | awk '
754 $2 ~ /^SOURCEURL/ {print}
755 $2 ~ /^PATCHURL/ {print}
756 $2 ~ /^nosource/ {print}
757 $2 ~ /^PACKAGE_/ {print}
758 '`
759 fi
d05e8080 760
13974367 761 update_shell_title "cache_rpm_dump: OK!"
cd445739
AM
762}
763
ace3fd80 764rpm_dump() {
cd445739 765 if [ -z "$rpm_dump_cache" ] ; then
45e2a818 766 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
cd445739
AM
767 fi
768 echo "$rpm_dump_cache"
769}
770
f6711e2a 771get_icons() {
d05e8080 772 update_shell_title "get icons"
9d99a240 773 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
d05e8080
ER
774 if [ -z "$ICONS" ]; then
775 return
776 fi
777
975d7b23 778 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
d05e8080
ER
779}
780
f6711e2a 781parse_spec() {
af4d5315 782 update_shell_title "parsing specfile"
cd445739 783 if [ -n "$DEBUG" ]; then
518ff1fb
ER
784 set -x
785 set -v
cd445739 786 fi
b2975fc3 787
d05e8080 788 # icons are needed for successful spec parse
518ff1fb 789 get_icons
d05e8080 790
9c909460 791 cd $PACKAGE_DIR
cd445739 792 cache_rpm_dump
00fcec7e 793
15e34b63 794 if rpm_dump | grep -qEi ":.*nosource.*1"; then
cd445739
AM
795 FAIL_IF_NO_SOURCES="no"
796 fi
797
7cbc2d88
ER
798 if [ "$NOSRCS" != "yes" ]; then
799 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
800 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
801 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
802 fi
803
dfe2b2d9
ER
804 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
805 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
806 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
78eab2a1 807
0b4119a2 808 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
7854d40c 809 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
0b4119a2
JR
810 fi
811
cd445739
AM
812 if [ -n "$BE_VERBOSE" ]; then
813 echo "- Sources : `nourl $SOURCES`"
814 if [ -n "$PATCHES" ]; then
815 echo "- Patches : `nourl $PATCHES`"
816 else
817 echo "- Patches : *no patches needed*"
818 fi
819 if [ -n "$ICONS" ]; then
820 echo "- Icon : `nourl $ICONS`"
821 else
822 echo "- Icon : *no package icon*"
823 fi
824 echo "- Name : $PACKAGE_NAME"
825 echo "- Version : $PACKAGE_VERSION"
826 echo "- Release : $PACKAGE_RELEASE"
827 fi
13974367
ER
828
829 update_shell_title "parse_spec: OK!"
cd445739
AM
830}
831
aa7e48da
ER
832# aborts program abnormally
833die() {
834 local rc=${2:-1}
835 echo >&2 "$PROGRAM: ERROR: $*"
836 exit $rc
837}
838
f6711e2a 839Exit_error() {
cd445739 840 if [ -n "$DEBUG" ]; then
518ff1fb
ER
841 set -x
842 set -v
cd445739
AM
843 fi
844
845 cd "$__PWD"
846
847 case "$1" in
848 "err_no_spec_in_cmdl" )
849 remove_build_requires
45e2a818 850 echo >&2 "ERROR: spec file name not specified."
cd445739 851 exit 2 ;;
a08d92fc 852 "err_invalid_cmdline" )
45e2a818 853 echo >&2 "ERROR: invalid command line arg ($2)."
a08d92fc 854 exit 2 ;;
cd445739
AM
855 "err_no_spec_in_repo" )
856 remove_build_requires
e55ef62b
ER
857 echo >&2 "Error: spec file not stored in repository."
858 if [ -n "$2" ]; then
859 echo >&2 "Tried: $2"
860 fi
861
cd445739
AM
862 exit 3 ;;
863 "err_no_source_in_repo" )
864 remove_build_requires
bba21388 865 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
cd445739 866 exit 4 ;;
703b6deb 867 "err_cvs_add_failed" )
bba21388 868 echo >&2 "Error: failed to add package to PLD repo."
703b6deb 869 exit 4 ;;
cd445739
AM
870 "err_build_fail" )
871 remove_build_requires
45e2a818 872 echo >&2 "Error: package build failed. (${2:-no more info})"
cd445739 873 exit 5 ;;
78eab2a1
AM
874 "err_no_package_data" )
875 remove_build_requires
45e2a818 876 echo >&2 "Error: couldn't get out package name/version/release from spec file."
78eab2a1 877 exit 6 ;;
ce40491a 878 "err_tag_exists" )
50321881 879 remove_build_requires
d2842af2 880 echo >&2 "Tag ${2} already exists"
50321881 881 exit 9 ;;
ce40491a 882 "err_fract_rel" )
50321881 883 remove_build_requires
45e2a818 884 echo >&2 "Release ${2} not integer and not a snapshot."
50321881 885 exit 10 ;;
fb96e0b5
AM
886 "err_branch_exists" )
887 remove_build_requires
45e2a818 888 echo >&2 "Tree branch already exists (${2})."
fb96e0b5 889 exit 11 ;;
cfc497c0
ER
890 "err_acl_deny" )
891 remove_build_requires
45e2a818 892 echo >&2 "Error: conditions reject building this spec (${2})."
cfc497c0 893 exit 12 ;;
406b9ecf
KK
894 "err_remote_problem" )
895 remove_build_requires
896 echo >&2 "Error: problem with remote (${2})"
897 exit 13 ;;
6217f407
KK
898 "err_no_checkut" )
899 echo >&2 "Error: cannot checkout $2"
900 exit 14 ;;
67963237 901 "err_not_implemented" )
779fcca4 902 remove_build_requires
67963237
KK
903 echo >&2 "Error: functionality not yet imlemented"
904 exit 110 ;;
cd445739 905 esac
45e2a818 906 echo >&2 "Unknown error."
73848362 907 exit 100
cd445739
AM
908}
909
f6711e2a 910init_builder() {
cd445739 911 if [ -n "$DEBUG" ]; then
518ff1fb
ER
912 set -x
913 set -v
0dd6320d 914 fi
cd445739 915
4aeb9973 916 if [ "$NOINIT" != "yes" ] ; then
9c909460 917 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
b7cc0c94 918
09bf17c9 919 local macros_ver=$(rpm -E %?rpm_build_macros)
b7cc0c94
ER
920 if [ -z "$macros_ver" ]; then
921 REPO_DIR=$TOP_DIR/packages
922 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
923 else
924 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
925 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
926 exit 1
927 fi
928 REPO_DIR=$TOP_DIR
929 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
930 fi
29e90b02 931 else
d723feca
ER
932 TOP_DIR=$(pwd)
933 PACKAGE_DIR=$TOP_DIR
5c41c44d 934 REPO_DIR=$PACKAGE_DIR
d723feca 935 RPMBUILDOPTS="$RPMBUILDOPTS --define '_topdir $TOP_DIR' --define '_builddir %_topdir' --define '_rpmdir %_topdir' --define '_srcrpmdir %_topdir'"
29e90b02 936 fi
52f3ced3
KK
937 export GIT_WORK_TREE=$PACKAGE_DIR
938 export GIT_DIR=$PACKAGE_DIR/.git
cd445739 939
acd0d41d 940 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
a095de80
KK
941 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
942 CVSTAG=${CVSTAG#refs/heads/}
943 if [ "$CVSTAG" != "master" ]; then
944 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
945 fi
946 else
947 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
948 HEAD_DETACHED="yes"
949 fi
950 elif [ "$CVSTAG" = "HEAD" ]; then
951 # assume -r HEAD is same as -A
952 CVSTAG="master"
953 fi
954
a8c9a155 955 __PWD=$(pwd)
00fcec7e 956}
957
406b9ecf
KK
958create_git_repo() {
959 update_shell_title "add_package"
960
961 if [ -n "$DEBUG" ]; then
962 set -x
963 set -v
964 fi
965
966 cd "$REPO_DIR"
967 SPECFILE=$(basename $SPECFILE)
968 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
969 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
970 exit 101
971 fi
972 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
c6418b06 973 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
d8dbe300
ER
974 (
975 set -e
406b9ecf 976 git init
d8dbe300
ER
977 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
978 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
979
980 git config --local push.default current
981 git config --local branch.master.remote $REMOTE_PLD
982 git config --local branch.master.merge refs/heads/master
983 )
984 test $? = 0 || Exit_error err_remote_problem $REMOTE_PLD
406b9ecf
KK
985}
986
f6711e2a 987get_spec() {
c890b916 988
2e5be021 989 update_shell_title "get_spec"
c890b916 990
cd445739 991 if [ -n "$DEBUG" ]; then
518ff1fb
ER
992 set -x
993 set -v
cd445739
AM
994 fi
995
9c909460 996 cd "$REPO_DIR"
e0ddd96d 997 SPECFILE=$(basename $SPECFILE)
1ef6f5de 998 if [ "$NOCVSSPEC" != "yes" ]; then
3189511a 999 if [ -z "$DEPTH" ]; then
30419e36 1000 if [ -d "$PACKAGE_DIR/.git" ]; then
6d641507 1001 git fetch $IPOPT $REMOTE_PLD || Exit_error err_no_spec_in_repo
3189511a 1002 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
30419e36
ER
1003 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
1004 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
3189511a
KK
1005 exit 101
1006 fi
1007 Exit_error err_not_implemented
1008 else
1009 (
1010 unset GIT_WORK_TREE
6d641507 1011 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
588cb3a9 1012 # softfail if new package, i.e not yet added to PLD rep
30419e36 1013 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
c8c52be7 1014 echo "Warning: package not in Git - assuming new package"
3189511a
KK
1015 NOCVSSPEC="yes"
1016 }
71435fd3
ER
1017 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1018 git config --local --add "remote.$REMOTE_PLD.push" 'refs/notes/*:refs/notes/*'
1019 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1020 git config --local push.default current
eda17ab7 1021 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
3189511a 1022 )
703b6deb 1023 fi
9c909460 1024 else
30419e36
ER
1025 if [ ! -d "$PACKAGE_DIR/.git" ]; then
1026 if [ ! -d "$PACKAGE_DIR" ]; then
1027 install -d $PACKAGE_DIR
3189511a
KK
1028 fi
1029 git init
a153a767 1030 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
71435fd3
ER
1031 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
1032 git config --local --add "remote.$REMOTE_PLD.push" 'refs/heads/*:refs/remotes/origin/*'
1033 git config --local --add "remote.$REMOTE_PLD.push" HEAD
1034 git config --local push.default current
48184c96 1035 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
6a9f8358 1036 CVSTAG=${CVSTAG:-"master"}
3189511a 1037 fi
3f79cb18
KK
1038 local refs=''
1039 if [ -z "$ALL_BRANCHES" ]; then
1040 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
1041 fi
6d641507 1042 git fetch $IPOPT $DEPTH $REMOTE_PLD $refs || {
3189511a
KK
1043 echo >&2 "Error: branch $CVSTAG does not exist"
1044 exit 3
1045 }
703b6deb 1046 fi
6d641507 1047 git fetch $IPOPT $REMOTE_PLD 'refs/notes/*:refs/notes/*'
0c3beb90 1048
0d494abd 1049 cvsignore_df .gitignore
703b6deb 1050
588cb3a9 1051 # add default log format to .gitignore if it is relative to package dir
703b6deb
ER
1052 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
1053 # substitute known "macros" to glob
3870f979 1054 local logfile=$(echo "$LOGFILE" | sed -r -e 's,\$(PACKAGE_(NAME|VERSION|RELEASE)|DATE|TARGET),*,g')
703b6deb
ER
1055 if [ "$logfile" ]; then
1056 cvsignore_df "$logfile"
daeab113 1057 fi
9c909460 1058 fi
703b6deb
ER
1059
1060 # create symlinks for tools
30419e36 1061 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
4ec6d58b 1062 for a in dropin md5 builder {relup,compile,repackage,rsync,pearize}.sh; do
046b715f 1063 # skip tools that don't exist in top dir
703b6deb 1064 [ -f $a ] || continue
046b715f 1065 # skip tools that already exist
30419e36
ER
1066 [ -f $PACKAGE_DIR/$a ] && continue
1067 ln -s ../$a $PACKAGE_DIR
703b6deb
ER
1068 cvsignore_df $a
1069 done
1070 fi
cd445739 1071 fi
049ab214 1072
b0121b45 1073 if [ -n "$CVSTAG" ]; then
c8c52be7 1074 if git rev-parse --verify -q "$CVSTAG" >/dev/null; then
7a83f50c
ER
1075 # checkout only if differs, so this will not trash git reflog
1076 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1077 git checkout "$CVSTAG" --
1078 fi
6217f407
KK
1079 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
1080 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
1081 fi
1082 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
1083 Exit_error "err_no_checkut" "$CVSTAG"
1084 fi
c8c52be7
ER
1085
1086 git merge --ff-only '@{u}'
2226518e 1087 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
52020f4c 1088 if [ -n "$CVSDATE" ]; then
c4c0f339
KK
1089 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
1090 fi
b0121b45
KK
1091 fi
1092
30419e36 1093 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
e55ef62b 1094 Exit_error err_no_spec_in_repo "$PACKAGE_DIR/$SPECFILE"
cd445739
AM
1095 fi
1096
1097 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
30419e36 1098 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
cd445739
AM
1099 fi
1100 unset OPTIONS
30419e36 1101 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
7e40520f 1102
ce40491a 1103 set_spec_target
cd445739
AM
1104}
1105
236af16b
ER
1106# find mirrors in this order. first match wins:
1107# - package dir (~/rpm/packages/foo)
1108# - repository dir (~/rpm/packages)
1109# - tools dir dir (~/rpm/packages/rpm-build-tools)
f6711e2a 1110find_mirror() {
782518da 1111 local url="$1"
cd445739 1112
236af16b
ER
1113 update_shell_title "find_mirror[$url][$REPO_DIR]"
1114
1115 # NOTE: as while loop runs in subshell,
1116 # we use exit 2 to indicate that the match was found
1117 # otherwise we end up outputing mirror url and origin url.
1118
782518da 1119 local origin mirror name rest ol prefix
236af16b
ER
1120 IFS="|"
1121 cat "$PACKAGE_DIR/mirrors" "$REPO_DIR/mirrors" "$REPO_DIR/../rpm-build-tools/mirrors" /dev/null 2>/dev/null | \
782518da
ER
1122 while read origin mirror name rest; do
1123 # skip comments and empty lines
2faa4c32 1124 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
782518da
ER
1125 continue
1126 fi
a8c9a155
ER
1127 ol=$(echo -n "$origin" | wc -c)
1128 prefix=$(echo -n "$url" | head -c $ol)
cd445739 1129 if [ "$prefix" = "$origin" ] ; then
a8c9a155 1130 suffix=$(echo "$url" | cut -b $((ol+1))-)
cd445739 1131 echo -n "$mirror$suffix"
236af16b 1132 exit 2
cd445739 1133 fi
236af16b 1134 done && echo "$url"
cd445739
AM
1135}
1136
e7e0d4ec 1137# Warning: unpredictable results if same URL used twice
f6711e2a 1138src_no() {
8510980a
AM
1139 local file="$1"
1140 # escape some regexp characters if part of file name
298e75e2 1141 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
9c909460 1142 cd $PACKAGE_DIR
cd445739 1143 rpm_dump | \
8510980a 1144 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
647e3d7f
KK
1145 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1146 head -n 1 | tr OURCEATH ourceath | xargs
1471f6d6 1147}
1148
f6711e2a 1149src_md5() {
e7e0d4ec 1150 [ "$NO5" = "yes" ] && return
cd445739
AM
1151 no=$(src_no "$1")
1152 [ -z "$no" ] && return
9c909460 1153 cd $PACKAGE_DIR
e7e0d4ec
ER
1154 local md5
1155
edcaeac2
ER
1156 # use "sources" file from package dir, like vim
1157 if [ -f sources ]; then
1158 md5=$(grep -s -v '^#' sources | \
5fe6b5d9 1159 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
e7e0d4ec
ER
1160 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1161 grep -E '^[0-9a-f]{32}$')
1162
1163 if [ "$md5" ]; then
1164 if [ $(echo "$md5" | wc -l) != 1 ] ; then
edcaeac2 1165 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
e7e0d4ec
ER
1166 fi
1167 echo "$md5" | tail -n 1
1168 return
1169 fi
cd445739 1170 fi
e7e0d4ec 1171
32131a0e 1172 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
e7e0d4ec
ER
1173 if [ -n "$source_md5" ]; then
1174 echo $source_md5
cd445739 1175 else
7805dcb4
PZ
1176 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1177 if [ -n "$source_md5" ]; then
1178 echo $source_md5
1179 else
1180 # we have empty SourceX-md5, but it is still possible
1181 # that we have NoSourceX-md5 AND NoSource: X
647e3d7f 1182 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
7805dcb4
PZ
1183 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1184 echo $nosource_md5
1185 fi
cd445739 1186 fi
cd445739
AM
1187 fi
1188}
1189
f6711e2a 1190distfiles_path() {
06541433
JR
1191 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1192}
1193
f6711e2a 1194distfiles_url() {
06541433 1195 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
cd445739
AM
1196}
1197
f6711e2a 1198distfiles_attic_url() {
06541433 1199 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
cd445739
AM
1200}
1201
f6711e2a 1202good_md5() {
cd445739
AM
1203 md5=$(src_md5 "$1")
1204 [ "$md5" = "" ] || \
1205 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
8ba5cdda
PG
1206}
1207
f6711e2a 1208good_size() {
a8c9a155 1209 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
ce40491a 1210 [ -n "$size" -a "$size" -gt 0 ]
a4b50627
AF
1211}
1212
f6711e2a 1213cvsignore_df() {
947025e5 1214 if [ "$CVSIGNORE_DF" != "yes" ]; then
1215 return
1216 fi
be93ada0 1217 local cvsignore=${PACKAGE_DIR}/.git/info/exclude
7dc8d095
ER
1218
1219 # add only if not yet there
aa189b05 1220 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
947025e5 1221 echo "$1" >> $cvsignore
1222 fi
1223}
1224
71f8e908 1225# returns true if "$1" is ftp, http or https protocol url
f6711e2a 1226is_url() {
71f8e908
ER
1227 case "$1" in
1228 ftp://*|http://*|https://*)
1229 return 0
1230 ;;
1231 esac
1232 return 1
1233}
1234
f6711e2a 1235update_md5() {
ecba6ad5
ER
1236 if [ $# -eq 0 ]; then
1237 return
1238 fi
1239
1240 update_shell_title "update md5"
1241 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1242 set -x
1243 set -v
ecba6ad5
ER
1244 fi
1245
9c909460 1246 cd "$PACKAGE_DIR"
ecba6ad5
ER
1247
1248 # pass 1: check files to be fetched
1249 local todo
1250 local need_files
1251 for i in "$@"; do
1252 local fp=$(nourl "$i")
1253 local srcno=$(src_no "$i")
6392b5fd
ER
1254 if [ -n "$ADD5" ]; then
1255 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
647e3d7f 1256 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
9c909460 1257 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
6392b5fd 1258 else
647e3d7f 1259 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
ecba6ad5
ER
1260 fi
1261 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1262 need_files="$need_files $i"
1263 fi
1264 done
1265
1266 # pass 1a: get needed files
1267 if [ "$need_files" ]; then
1268 get_files $need_files
1269 fi
1270
1271 # pass 2: proceed with md5 adding or updating
1272 for i in "$@"; do
1273 local fp=$(nourl "$i")
1274 local srcno=$(src_no "$i")
647e3d7f 1275 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
e19ad799 1276 if [ -z "$md5" ]; then
9c909460 1277 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
6c1b2e7d 1278 fi
71f8e908 1279 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
647e3d7f 1280 local tag="# $srcno-md5:\t"
71f8e908 1281 if [[ "$md5" == *NoSource* ]]; then
6663e1f3 1282 tag="# No$srcno-md5:\t"
6c1b2e7d
PZ
1283 elif [ -n "$USEDIGEST" ]; then
1284 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
71f8e908 1285 fi
ecba6ad5 1286 md5=$(md5sum "$fp" | cut -f1 -d' ')
647e3d7f 1287 echo "Updating $srcno ($md5: $fp)."
ecba6ad5 1288 perl -i -ne '
647e3d7f
KK
1289 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1290 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
ecba6ad5 1291 ' \
9c909460 1292 $PACKAGE_DIR/$SPECFILE
ecba6ad5
ER
1293 fi
1294 done
1295}
1296
f6711e2a 1297check_md5() {
60499e54 1298 local bad
3fbff8b8
ER
1299 [ "$NO5" = "yes" ] && return
1300
ecba6ad5
ER
1301 update_shell_title "check md5"
1302
1303 for i in "$@"; do
60499e54
AM
1304 bad=0
1305 if ! good_md5 "$i"; then
1306 echo -n "MD5 sum mismatch."
1307 bad=1
1308 fi
1309 if ! good_size "$i"; then
1310 echo -n "0 sized file."
1311 bad=1
ecba6ad5
ER
1312 fi
1313
60499e54
AM
1314 if [ $bad -eq 1 ]; then
1315 echo " Use -U to refetch sources,"
1316 echo "or -5 to update md5 sums, if you're sure files are correct."
1317 Exit_error err_no_source_in_repo $i
1318 fi
ecba6ad5
ER
1319 done
1320}
1321
f6711e2a 1322get_files() {
7cb24972 1323 update_shell_title "get_files"
cd445739
AM
1324
1325 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1326 set -x
1327 set -v
cd445739
AM
1328 fi
1329
f09c0772 1330 if [ $# -gt 0 ]; then
9c909460 1331 cd "$PACKAGE_DIR"
cd445739 1332
f2e42a41 1333 local nc=0
e7fa3b9f 1334 local get_files_cvs=""
3815b69a 1335 for i in "$@"; do
f2e42a41 1336 nc=$((nc + 1))
dcebdffb 1337 local cvsup=0
3815b69a 1338 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
f2e42a41 1339 update_shell_title "$i"
f09c0772 1340 local fp=`nourl "$i"`
ecba6ad5 1341 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
ce40491a 1342 continue
18e5347d 1343 fi
ecba6ad5 1344
cd445739 1345 FROM_DISTFILES=0
e7e0d4ec 1346 local srcmd5=$(src_md5 "$i")
ecba6ad5
ER
1347
1348 # we know if source/patch is present in cvs/distfiles
1349 # - has md5 (in distfiles)
1350 # - in cvs... ideas?
1351
1352 # CHECK: local file didn't exist or always cvs up (first) requested.
f09c0772 1353 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
cd445739
AM
1354 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1355 echo "Warning: no URL given for $i"
1356 fi
08908161 1357 target="$fp"
cd445739 1358
e7e0d4ec 1359 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
a4b50627 1360 if good_md5 "$i" && good_size "$i"; then
e7e0d4ec 1361 echo "$fp having proper md5sum already exists"
cd445739
AM
1362 continue
1363 fi
28b34560 1364
bc10f694 1365 # optionally prefer mirror over distfiles if there's mirror
28b34560 1366 # TODO: build url list and then try each url from the list
bc10f694 1367 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
28b34560
ER
1368 url="$im"
1369 else
1370 url=$(distfiles_url "$i")
1371 fi
1372
cd445739
AM
1373 url_attic=$(distfiles_attic_url "$i")
1374 FROM_DISTFILES=1
ecba6ad5
ER
1375 # is $url local file?
1376 if [[ "$url" = [./]* ]]; then
18a52930 1377 update_shell_title "${GETLOCAL%% *}: $url"
cd445739
AM
1378 ${GETLOCAL} $url $target
1379 else
9e9f8920
ER
1380 local uri=${url}
1381 # make shorter message for distfiles urls
1382 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1383 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1384 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1385 uri="df: $uri"
1386 fi
1387 update_shell_title "${GETURI%% *}: $uri"
6d641507 1388 ${GETURI} "$target" "$url"
cd445739 1389 fi
ecba6ad5
ER
1390
1391 # is it empty file?
1392 if [ ! -s "$target" ]; then
cd445739
AM
1393 rm -f "$target"
1394 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
18a52930 1395 update_shell_title "${GETLOCAL%% *}: $url_attic"
cd445739
AM
1396 ${GETLOCAL} $url_attic $target
1397 else
18a52930 1398 update_shell_title "${GETURI%% *}: $url_attic"
6d641507 1399 ${GETURI} "$target" "$url_attic"
1cd7fc57 1400 test -s "$target" || rm -f "$target"
cd445739
AM
1401 fi
1402 fi
ecba6ad5
ER
1403
1404 if [ -s "$target" ]; then
947025e5 1405 cvsignore_df $target
1406 else
cd445739
AM
1407 rm -f "$target"
1408 FROM_DISTFILES=0
1409 fi
cd445739
AM
1410 fi
1411
f09c0772 1412 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
cd445739 1413 if [ -z "$NOMIRRORS" ]; then
a8c9a155 1414 im=$(find_mirror "$i")
cd445739
AM
1415 else
1416 im="$i"
1417 fi
ce40491a 1418 update_shell_title "${GETURI%% *}: $im"
6d641507 1419 ${GETURI} "$target" "$im"
1cd7fc57 1420 test -s "$target" || rm -f "$target"
cd445739
AM
1421 fi
1422
dcebdffb
ER
1423 if [ "$cvsup" = 1 ]; then
1424 continue
1425 fi
1426
cd445739 1427 fi
ecba6ad5
ER
1428
1429 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
f09c0772 1430 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
b3b584c5 1431 Exit_error err_no_source_in_repo $i
cd445739 1432 fi
2a5f078d 1433
ecba6ad5 1434 # we check md5 here just only to refetch immediately
a4b50627 1435 if good_md5 "$i" && good_size "$i"; then
cd445739
AM
1436 :
1437 elif [ "$FROM_DISTFILES" = 1 ]; then
deccc50e 1438 # wrong md5 from distfiles: remove the file and try again
cd445739 1439 # but only once ...
deccc50e 1440 echo "MD5 sum mismatch. Trying full fetch."
cd445739
AM
1441 FROM_DISTFILES=2
1442 rm -f $target
18a52930 1443 update_shell_title "${GETURI%% *}: $url"
6d641507 1444 ${GETURI} "$target" "$url"
ecba6ad5 1445 if [ ! -s "$target" ]; then
cd445739 1446 rm -f "$target"
18a52930 1447 update_shell_title "${GETURI%% *}: $url_attic"
6d641507 1448 ${GETURI} "$target" "$url_attic"
cd445739
AM
1449 fi
1450 test -s "$target" || rm -f "$target"
1451 fi
cd445739 1452 done
e7fa3b9f
ER
1453 SHELL_TITLE_PREFIX=""
1454
cd445739
AM
1455
1456 if [ "$CHMOD" = "yes" ]; then
a8c9a155 1457 CHMOD_FILES=$(nourl "$@")
cd445739
AM
1458 if [ -n "$CHMOD_FILES" ]; then
1459 chmod $CHMOD_MODE $CHMOD_FILES
1460 fi
1461 fi
cd445739
AM
1462 fi
1463}
1464
7605fe95 1465tag_exist() {
8b6d1795
KK
1466# If tag exists and points to other commit exit with error
1467# If it existsts and points to HEAD return 1
1468# If it doesn't exist return 0
f8bfce7d 1469 local _tag="$1"
8b6d1795 1470 local sha1=$(git rev-parse HEAD)
7605fe95
KK
1471 echo "Searching for tag $_tag..."
1472 if [ -n "$DEPTH" ]; then
8b6d1795 1473 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
7605fe95 1474 else
7baf7b2f 1475 local ref=$(git show-ref -s "refs/tags/$_tag")
7605fe95 1476 fi
8b6d1795
KK
1477 [ -z "$ref" ] && return 0
1478 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1479 return 1
7605fe95
KK
1480}
1481
cd445739 1482make_tagver() {
ce40491a 1483 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1484 set -x
1485 set -v
ce40491a 1486 fi
78eab2a1 1487
ce40491a
ER
1488 # Check whether first character of PACKAGE_NAME is legal for tag name
1489 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1490 TAG_PREFIX=tag_
1491 fi
d712cc12
ER
1492
1493 # NOTE: CVS tags may must not contain the characters `$,.:;@'
8c043136 1494 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
d712cc12 1495
8c043136 1496 # Remove @kernel.version_release from TAGVER because tagging sources
ce40491a 1497 # could occur with different kernel-headers than kernel-headers used at build time.
d712cc12
ER
1498 # besides, %{_kernel_ver_str} is not expanded.
1499
8c043136 1500 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
d712cc12
ER
1501 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1502
8c043136 1503 TAGVER=${TAGVER%@*}
ce40491a 1504 echo -n "$TAGVER"
cd445739
AM
1505}
1506
f6711e2a 1507tag_files() {
cd445739 1508 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1509 set -x
1510 set -v
cd445739
AM
1511 fi
1512
73ef63d8
ER
1513 echo "Version: $PACKAGE_VERSION"
1514 echo "Release: $PACKAGE_RELEASE"
cd445739 1515
c9100f10 1516 local _tag
73ef63d8 1517 if [ "$TAG_VERSION" = "yes" ]; then
c9100f10 1518 _tag=`make_tagver`
73ef63d8
ER
1519 fi
1520 if [ -n "$TAG" ]; then
c9100f10 1521 _tag="$TAG"
73ef63d8 1522 fi
c9100f10 1523 echo "tag: $_tag"
cd445739 1524
39dcc7de 1525 local OPTIONS="tag $CVS_FORCE"
cd445739 1526
9c909460 1527 cd "$PACKAGE_DIR"
03db3356 1528
ace99bc6
KK
1529 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1530 update_shell_title "tag sources: $_tag"
1531 git $OPTIONS $_tag || exit
6d641507 1532 git push $IPOPT $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
ace99bc6
KK
1533 else
1534 echo "Tag $_tag already exists and points to the same commit"
1535 fi
cd445739
AM
1536}
1537
f6711e2a 1538branch_files() {
cd445739 1539 TAG=$1
f663f264 1540 echo "Git branch: $TAG"
518ff1fb 1541 shift
cd445739 1542
cd445739 1543 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1544 set -x
1545 set -v
cd445739
AM
1546 fi
1547
f663f264 1548 local OPTIONS="branch $CVS_FORCE"
c10fa4fa 1549
9c909460 1550 cd "$PACKAGE_DIR"
f663f264 1551 git $OPTIONS $TAG || exit
cd445739
AM
1552}
1553
1554
3009b80d
ER
1555# this function should exit early if package can't be built for this arch
1556# this avoids unneccessary BR filling.
1557check_buildarch() {
1558 local out ret
13c3c336 1559 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
3009b80d
ER
1560 ret=$?
1561 if [ $ret -ne 0 ]; then
1562 echo >&2 "$out"
1563 exit $ret
1564 fi
1565}
1566
9d99a240
ER
1567# from relup.sh
1568set_release() {
1569 local specfile="$1"
1570 local rel="$2"
1571 local newrel="$3"
1572 sed -i -e "
1573 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1574 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1575 " $specfile
1576}
1577
1578set_version() {
1579 local specfile="$1"
bc8502e6
ER
1580 local ver="$2" subver=$ver
1581 local newver="$3" newsubver=$newver
1582
1583 # try handling subver, everything that's not numeric-dotted in version
1584 if grep -Eq '%define\s+subver' $specfile; then
1585 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1586 ver=${ver%$subver}
1587 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1588 newver=${newver%$newsubver}
1589 fi
9d99a240
ER
1590 sed -i -e "
1591 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
bc8502e6 1592 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
9d99a240
ER
1593 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1594 " $specfile
1595}
1596
52a2ef00
ER
1597# try to upgrade .spec to new version
1598# if --upgrade-version is specified, use that as new version, otherwise invoke pldnotify to find new version
1599#
1600# return 1: if .spec was updated
1601# return 0: no changes to .spec
1602# exit 1 in case of error
cacef28c 1603try_upgrade() {
52a2ef00
ER
1604 if [ -z "$TRY_UPGRADE" ]; then
1605 return 0
1606 fi
9d99a240 1607
52a2ef00
ER
1608 local TNOTIFY TNEWVER TOLDVER
1609 update_shell_title "build_package: try_upgrade"
cd445739 1610
52a2ef00 1611 cd "$PACKAGE_DIR"
b9bef5ce 1612
52a2ef00
ER
1613 if [ "$UPGRADE_VERSION" ]; then
1614 TNEWVER=$UPGRADE_VERSION
1615 echo "Updating spec file to version $TNEWVER"
1616 else
1617 if [ -n "$FLOAT_VERSION" ]; then
d1d44ebd 1618 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
52a2ef00 1619 else
d1d44ebd 1620 TNOTIFY=$(pldnotify ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
0907f1eb 1621 fi
cd445739 1622
d1d44ebd 1623 # pldnotify does not set exit codes, but it has match for ERROR
52a2ef00
ER
1624 # in output which means so.
1625 if [[ "$TNOTIFY" = *ERROR* ]]; then
1626 echo >&2 "$TNOTIFY"
1627 exit 1
cd445739 1628 fi
52a2ef00
ER
1629
1630 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
1631 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
1632
1633 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1634 fi
1635
1636 if [ -z "$TNEWVER" ]; then
1637 return 0
1638 fi
1639
1640 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1641 cp -f $SPECFILE $SPECFILE.bak
1642 fi
1643 chmod +w $SPECFILE
1644 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
1645 set_release $SPECFILE $PACKAGE_RELEASE 1
1646 parse_spec
1647 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1648 echo >&2 "Upgrading version failed, you need to update spec yourself"
1649 exit 1
cd445739 1650 fi
52a2ef00 1651 return 1
cacef28c 1652}
1653
1654build_package() {
1655 update_shell_title "build_package"
1656 if [ -n "$DEBUG" ]; then
1657 set -x
1658 set -v
1659 fi
1660
9c909460 1661 cd "$PACKAGE_DIR"
2a5f078d 1662
cd445739
AM
1663 case "$COMMAND" in
1664 build )
1665 BUILD_SWITCH="-ba" ;;
1666 build-binary )
1667 BUILD_SWITCH="-bb" ;;
1668 build-source )
1669 BUILD_SWITCH="-bs --nodeps" ;;
1670 build-prep )
1671 BUILD_SWITCH="-bp --nodeps" ;;
6594293d
AG
1672 build-build )
1673 BUILD_SWITCH="-bc" ;;
1674 build-install )
1675 BUILD_SWITCH="-bi" ;;
1676 build-list )
1677 BUILD_SWITCH="-bl" ;;
1678
cd445739 1679 esac
c890b916 1680
2e5be021 1681 update_shell_title "build_package: $COMMAND"
12da9e3d 1682 local logfile retval
cd445739 1683 if [ -n "$LOGFILE" ]; then
12da9e3d
ER
1684 logfile=`eval echo $LOGFILE`
1685 if [ -d "$logfile" ]; then
1686 echo "Log file $logfile is a directory."
cd445739 1687 echo "Parse error in the spec?"
518ff1fb 1688 Exit_error err_build_fail
cd445739
AM
1689 fi
1690 if [ -n "$LASTLOG_FILE" ]; then
12da9e3d 1691 echo "LASTLOG=$logfile" > $LASTLOG_FILE
cd445739 1692 fi
12da9e3d
ER
1693 fi
1694
bfea86a5
ER
1695 # unset these, should not be exposed to builder shell!
1696 unset GIT_WORK_TREE GIT_DIR
c69e0c61 1697 # these are set by jenkins
bfea86a5 1698 unset GIT_PREVIOUS_COMMIT GIT_URL GIT_PREVIOUS_SUCCESSFUL_COMMIT GIT_BRANCH GIT_COMMIT
256edc2e
ER
1699 # this may be set by user
1700 unset GIT_SSH
4666645f 1701 # may be set by user
6aa9db85 1702 unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_TESTING_PORCELAIN_COMMAND_LIST
bfea86a5
ER
1703 # fail if something still set
1704 env | grep ^GIT_ && Exit_error err_build_fail
1705
12da9e3d 1706 local specdir=$(insert_gitlog $SPECFILE)
4754e795 1707 ulimit -c unlimited
12da9e3d 1708 # FIXME: eval here is exactly why?
6dd8b9cc 1709 PATH=$CLEAN_PATH eval teeboth "'$logfile'" ${TIME_COMMAND} ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE
12da9e3d
ER
1710 retval=$?
1711 rm -r $specdir
1712
1713 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1714 if [ "$retval" -eq "0" ]; then
1715 mv $logfile $LOGDIROK
1716 else
1717 mv $logfile $LOGDIRFAIL
cd445739 1718 fi
8ba5cdda 1719 fi
12da9e3d
ER
1720
1721 if [ "$retval" -ne "0" ]; then
cd445739 1722 if [ -n "$TRY_UPGRADE" ]; then
cacef28c 1723 echo "\nUpgrade package to new version failed."
257af81b 1724 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
cacef28c 1725 echo "Restoring old spec file."
257af81b
ER
1726 mv -f $SPECFILE.bak $SPECFILE
1727 fi
cacef28c 1728 echo ""
cd445739 1729 fi
518ff1fb 1730 Exit_error err_build_fail
cd445739
AM
1731 fi
1732 unset BUILD_SWITCH
1733}
1734
f6711e2a 1735nourl() {
cd445739
AM
1736 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1737}
1738
f6711e2a 1739install_required_packages() {
cd445739
AM
1740 run_poldek -vi $1
1741 return $?
1742}
1743
f6711e2a 1744find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
fa4bf1df 1745 local SPEC="$1"
fa4bf1df
ER
1746 awk -F"\n" '
1747 /^%changelog/ { exit }
fa4bf1df
ER
1748 /^%bcond_with/{
1749 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
8ff97f39
ER
1750 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1751 gsub(/[ \t]+/, "_", bcond);
fa4bf1df
ER
1752 print bcond
1753 }' $SPEC | LC_ALL=C sort -u
1754}
1755
117d9861 1756process_bcondrc() {
301cbfd4
ER
1757 # expand bconds from ~/.bcondrc
1758 # The file structure is like gentoo's package.use:
1759 # ---
1760 # * -selinux
1761 # samba -mysql -pgsql
47a8df12 1762 # w32codec-installer license_agreement
301cbfd4
ER
1763 # php +mysqli
1764 # ---
15e34b63 1765 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
117d9861
ER
1766 :
1767 else
1768 return
1769 fi
301cbfd4 1770
117d9861 1771 SN=${SPECFILE%%\.spec}
c8a3e2ac 1772
117d9861
ER
1773 local bcondrc=$HOME/.bcondrc
1774 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
301cbfd4 1775
117d9861 1776 local bcond_avail=$(find_spec_bcond $SPECFILE)
301cbfd4 1777
117d9861
ER
1778 while read pkg flags; do
1779 # ignore comments
1780 [[ "$pkg" == \#* ]] && continue
1781
1782 # any package or current package?
1783 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1784 for flag in $flags; do
1785 local opt=${flag#[+-]}
1786
1787 # use only flags which are in this package.
1788 if [[ $bcond_avail = *${opt}* ]]; then
1789 if [[ $flag = -* ]]; then
1790 if [[ $BCOND != *--with?${opt}* ]]; then
1791 BCOND="$BCOND --without $opt"
1792 fi
1793 else
1794 if [[ $BCOND != *--without?${opt}* ]]; then
1795 BCOND="$BCOND --with $opt"
301cbfd4
ER
1796 fi
1797 fi
117d9861
ER
1798 fi
1799 done
1800 fi
1801 done < $bcondrc
1802 update_shell_title "parse ~/.bcondrc: DONE!"
1803}
1804
8ff97f39 1805set_bconds_values() {
117d9861
ER
1806 update_shell_title "set bcond values"
1807
1808 AVAIL_BCONDS_WITHOUT=""
1809 AVAIL_BCONDS_WITH=""
8ff97f39 1810
5a28189c 1811 if grep -Eq '^# *_with' ${SPECFILE}; then
8ff97f39
ER
1812 echo >&2 "ERROR: This spec has old style bconds."
1813 exit 1
1814 fi
1815
1816 if ! grep -q '^%bcond' ${SPECFILE}; then
117d9861 1817 return
301cbfd4
ER
1818 fi
1819
117d9861
ER
1820 local bcond_avail=$(find_spec_bcond $SPECFILE)
1821 process_bcondrc "$SPECFILE"
1822
fa4bf1df 1823 update_shell_title "parse bconds"
2a5f078d 1824
8ff97f39
ER
1825 local opt bcond
1826 for opt in $bcond_avail; do
1827 case "$opt" in
1828 without_*)
1829 bcond=${opt#without_}
10d92f71 1830 case "$BCOND" in
b28896b3 1831 *--without?${bcond}\ *|*--without?${bcond})
8ff97f39 1832 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
10d92f71
ER
1833 ;;
1834 *)
8ff97f39 1835 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
10d92f71
ER
1836 ;;
1837 esac
cd445739 1838 ;;
8ff97f39
ER
1839 with_*)
1840 bcond=${opt#with_}
10d92f71 1841 case "$BCOND" in
b28896b3 1842 *--with?${bcond}\ *|*--with?${bcond})
8ff97f39 1843 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
10d92f71
ER
1844 ;;
1845 *)
8ff97f39 1846 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
10d92f71
ER
1847 ;;
1848 esac
cd445739 1849 ;;
8ff97f39
ER
1850 *)
1851 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1852 exit 1
1853 ;;
1854 esac
1855 done
cd445739
AM
1856}
1857
f6711e2a 1858run_sub_builder() {
cd445739 1859 package_name="${1}"
af6b168f 1860 update_shell_title "run_sub_builder $package_name"
cd445739 1861 #
8f64e264
ER
1862 # No i tutaj bym chciał zrobić sztuczną inteligencję, która spróbuje tego
1863 # pakieta zbudować. Aktualnie niewiele dziala, bo generalnie nie widze do
cd445739
AM
1864 # konca algorytmu... Ale damy rade. :) Na razie po prostu sie wyjebie tak samo
1865 # jakby nie bylo tego kawalka kodu.
1866 #
8f64e264
ER
1867 # Update: Poprawiłem parę rzeczy i zaczęło generować pakiety spoza zadanej listy.
1868 # Jednym słowem budowanie niespoldkowanych zależności działa w paru przypadkach.
cd445739
AM
1869 #
1870 #
1871 # y0shi.
a8c9a155 1872 # kurwa. translate that ^^^^
cd445739
AM
1873
1874 parent_spec_name=''
1875
cd445739 1876 # Istnieje taki spec? ${package}.spec
9c909460 1877 if [ -f "${PACKAGE_DIR}/${package}.spec" ]; then
cd445739 1878 parent_spec_name=${package}.spec
9c909460 1879 elif [ -f "${PACKAGE_DIR}/$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec" ]; then
a8c9a155 1880 parent_spec_name="$(echo ${package_name} | sed -e s,-devel.*,,g -e s,-static,,g).spec"
d6a77ddb 1881 else
9c909460 1882 for provides_line in $(grep -r ^Provides:.*$package ${PACKAGE_DIR}); do
cd445739
AM
1883 echo $provides_line
1884 done
1885 fi
1886
1887 if [ "${parent_spec_name}" != "" ]; then
af6b168f 1888 spawn_sub_builder $parent_spec_name
cd445739
AM
1889 fi
1890 NOT_INSTALLED_PACKAGES="$NOT_INSTALLED_PACKAGES $package_name"
1891}
1892
aa7e48da
ER
1893# install package with poldek
1894# @return exit code from poldek
1895#
1896# this requires following sudo rules:
6a9f0e96 1897# - poldek --noask --caplookup -ug
aa7e48da 1898poldek_install() {
ae0dd942 1899 LC_ALL=C LANG=C $POLDEK_CMD --noask --caplookup --uniq -ug "$@"
aa7e48da
ER
1900}
1901
1902# install packages
dd5f5cd7
ER
1903#
1904# this requires following sudo rules:
1905# - poldek -q --update --upa
aa7e48da
ER
1906install_packages() {
1907 # sync poldek indexes once per invocation
1908 if [ -z "$package_indexes_updated" ]; then
1909 update_shell_title "poldek: update indexes"
00f72562 1910 $POLDEK_CMD -q --update --upa --mo=nodesc
aa7e48da
ER
1911 package_indexes_updated=true
1912 fi
1913
1914 update_shell_title "install packages: $*"
1915 poldek_install "$@" && return
1916
1917 # retry install, install packages one by one
1918 # this is slower one
1919 local rc=0 package
1920 for package in $*; do
1921 package=$(depspecname $package)
1922 update_shell_title "install package: $package"
1923 poldek_install "$package" || rc=$?
1924 done
1925 return $rc
1926}
1927
1928uninstall_packages() {
1929 update_shell_title "uninstall packages: $*"
1930 $POLDEK_CMD --noask --nofollow -ev "$@"
1931}
1932
f6711e2a 1933spawn_sub_builder() {
ce40491a
ER
1934 package_name="${1}"
1935 update_shell_title "spawn_sub_builder $package_name"
af6b168f 1936
ce40491a 1937 sub_builder_opts=''
c2d6312c 1938 if [ "${FETCH_BUILD_REQUIRES}" = "yes" ]; then
ce40491a
ER
1939 sub_builder_opts="${sub_builder_opts} -R"
1940 fi
c2d6312c 1941 if [ "${REMOVE_BUILD_REQUIRES}" = "nice" ]; then
ce40491a 1942 sub_builder_opts="${sub_builder_opts} -RB"
c2d6312c 1943 elif [ "${REMOVE_BUILD_REQUIRES}" = "force" ]; then
ce40491a
ER
1944 sub_builder_opts="${sub_builder_opts} -FRB"
1945 fi
c2d6312c 1946 if [ "${UPDATE_POLDEK_INDEXES}" = "yes" ]; then
ce40491a
ER
1947 sub_builder_opts="${sub_builder_opts} -Upi"
1948 fi
af6b168f 1949
9c909460 1950 cd "${PACKAGE_DIR}"
ce40491a 1951 ./builder ${sub_builder_opts} "$@"
af6b168f
ER
1952}
1953
f6711e2a 1954remove_build_requires() {
cd445739
AM
1955 if [ "$INSTALLED_PACKAGES" != "" ]; then
1956 case "$REMOVE_BUILD_REQUIRES" in
1957 "force")
1958 run_poldek --noask -ve $INSTALLED_PACKAGES
1959 ;;
1960 "nice")
1961 run_poldek --ask -ve $INSTALLED_PACKAGES
1962 ;;
1963 *)
1964 echo You may want to manually remove following BuildRequires fetched:
1965 echo $INSTALLED_PACKAGES
90baf90b 1966 echo "Try poldek -e \`cat $(pwd)/.${SPECFILE}_INSTALLED_PACKAGES\`"
cd445739
AM
1967 ;;
1968 esac
1969 fi
1970}
1971
f6711e2a 1972display_bconds() {
8ff97f39
ER
1973 if [ "$AVAIL_BCONDS_WITH" -o "$AVAIL_BCONDS_WITHOUT" ]; then
1974 if [ "$BCOND" ]; then
10d92f71
ER
1975 echo ""
1976 echo "Building $SPECFILE with the following conditional flags:"
1977 echo -n "$BCOND"
cd445739 1978 else
10d92f71
ER
1979 echo ""
1980 echo "No conditional flags passed"
cd445739 1981 fi
10d92f71
ER
1982 echo ""
1983 echo "from available:"
1984 echo "--with :\t$AVAIL_BCONDS_WITH"
1985 echo "--without:\t$AVAIL_BCONDS_WITHOUT"
1986 echo ""
cd445739
AM
1987 fi
1988}
1989
f6711e2a 1990display_branches() {
a0fc9d5b 1991 echo -n "Available branches: "
9fd1eb80 1992 git branch -r 2>/dev/null | grep "^ ${REMOTE_PLD}" | grep -v ${REMOTE_PLD}/HEAD | sed "s#^ *${REMOTE_PLD}/##" | xargs
ec4dbe02
AM
1993}
1994
aa7e48da 1995# checks a given list of packages/files/provides against current rpmdb.
ea26d7fc 1996# outputs all dependencies which current rpmdb doesn't satisfy.
af213c6e 1997# input can be either STDIN or parameters
f6711e2a 1998_rpm_prov_check() {
e99e2f34 1999 local deps out
af213c6e 2000
ea26d7fc 2001 if [ $# -gt 0 ]; then
e99e2f34 2002 deps="$@"
ce40491a 2003 else
e99e2f34 2004 deps=$(cat)
ce40491a 2005 fi
af213c6e 2006
e99e2f34 2007 out=$(LC_ALL=C rpm -q --whatprovides $deps 2>&1)
af213c6e 2008
ce40491a 2009 # packages
e99e2f34 2010 echo "$out" | awk '/^no package provides/ { print $NF }'
af213c6e 2011
ce40491a 2012 # other deps (files)
e99e2f34 2013 echo "$out" | sed -rne 's/file (.*): No such file or directory/\1/p'
af213c6e
ER
2014}
2015
2016# checks if given package/files/provides exists in rpmdb.
ea26d7fc
ER
2017# input can be either stdin or parameters
2018# returns packages which are present in the rpmdb
f6711e2a 2019_rpm_cnfl_check() {
ce40491a 2020 local DEPS
af213c6e 2021
ea26d7fc 2022 if [ $# -gt 0 ]; then
ce40491a
ER
2023 DEPS="$@"
2024 else
2025 DEPS=$(cat)
2026 fi
af213c6e 2027
ae0dd942 2028 LC_ALL=C LANG=C rpm -q --whatprovides $DEPS 2>/dev/null | awk '!/no package provides/ { print }'
af213c6e
ER
2029}
2030
18e0f841
ER
2031# install deps via information from 'rpm-getdeps' or 'rpm --specsrpm'
2032install_build_requires_rpmdeps() {
aa7e48da 2033 local DEPS CNFL
18e0f841
ER
2034 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ]; then
2035 # TODO: Conflicts list doesn't check versions
74ede51d
ER
2036 CNFL=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\-/ { print $3 } ' | _rpm_cnfl_check | xargs)
2037 DEPS=$(eval rpm-getdeps $BCOND $RPMOPTS $SPECFILE 2> /dev/null | awk '/^\+/ { print $3 } ' | _rpm_prov_check | xargs)
18e0f841
ER
2038 fi
2039 if [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
74ede51d
ER
2040 CNFL=$(eval rpm -q --specsrpm --conflicts $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_cnfl_check | xargs)
2041 DEPS=$(eval rpm -q --specsrpm --requires $BCOND $RPMOPTS $SPECFILE | awk '{print $1}' | _rpm_prov_check | xargs)
18e0f841
ER
2042 fi
2043
18e0f841 2044 if [ -n "$CNFL" ]; then
e99e2f34 2045 echo "Uninstall conflicting packages: $CNFL"
aa7e48da
ER
2046 uninstall_packages $CNFL
2047 fi
2048
2049 if [ -n "$DEPS" ]; then
e99e2f34 2050 echo "Install dependencies: $DEPS"
aa7e48da
ER
2051 install_packages $DEPS
2052 fi
18e0f841 2053}
af213c6e 2054
18e0f841
ER
2055fetch_build_requires()
2056{
2057 if [ "${FETCH_BUILD_REQUIRES}" != "yes" ]; then
2058 return
2059 fi
2dddf439 2060
18e0f841
ER
2061 update_shell_title "fetch build requires"
2062 if [ "$FETCH_BUILD_REQUIRES_RPMGETDEPS" = "yes" ] || [ "$FETCH_BUILD_REQUIRES_RPMSPECSRPM" = "yes" ]; then
2063 install_build_requires_rpmdeps
2064 return
2065 fi
2a5f078d 2066
aa7e48da 2067 die "need rpm-getdeps tool"
cd445739
AM
2068}
2069
b0600c6a
KK
2070init_repository() {
2071 local remoterepo=$1
2072 local localrepo=$2
2073
2074 if [ ! -e $localrepo ]; then
6d641507 2075 git clone $IPOPT -o $REMOTE_PLD ${GIT_SERVER}/$remoterepo $localrepo
b0600c6a
KK
2076 git --git-dir=$localrepo/.git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/$remoterepo
2077 fi
2078}
2079
ce5daafb 2080init_rpm_dir() {
0bf6d4a9
ER
2081 local TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
2082 local rpmdir=$(eval $RPM $RPMOPTS --eval '%{_rpmdir}')
2083 local buildir=$(eval $RPM $RPMOPTS --eval '%{_builddir}')
2084 local srpmdir=$(eval $RPM $RPMOPTS --eval '%{_srcrpmdir}')
ceda6f3c 2085 local TEMPLATES=template-specs
0bf6d4a9 2086 local tmp
ce5daafb 2087
0c8e5e9d 2088 echo "Initializing rpm directories to $TOP_DIR from $GIT_SERVER"
0bf6d4a9
ER
2089 mkdir -p $TOP_DIR $rpmdir $buildir $srpmdir
2090
2911d25f 2091 cd "$TOP_DIR"
b0600c6a
KK
2092 init_repository ${PACKAGES_DIR}/rpm-build-tools.git ../rpm-build-tools
2093 init_repository projects/$TEMPLATES ../$TEMPLATES
4ec6d58b 2094 for a in builder fetchsrc_request compile repackage; do
a4161989 2095 ln -sf ../rpm-build-tools/${a}.sh $a
885f2a00 2096 done
6e0b69d5
ER
2097 for a in md5; do
2098 ln -sf ../rpm-build-tools/${a} $a
2099 done
a4161989 2100 ln -sf ../rpm-build-tools/mirrors mirrors
ce5daafb 2101 init_builder
ce5daafb
ER
2102}
2103
6f10b394
ER
2104mr_proper() {
2105 init_builder
2106 NOCVSSPEC="yes"
2107 DONT_PRINT_REVISION="yes"
66a79c87
KK
2108
2109 # remove spec and sources
664084c6 2110 PATH=$CLEAN_PATH $RPMBUILD --clean --rmsource --rmspec --nodeps --define "__urlgetfile() %nil" --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" --define "_builddir $builddir" $PACKAGE_DIR/$SPECFILE
bd71e706 2111 rm -rf $PACKAGE_DIR/{.git,.gitignore}
d37defc1 2112 rmdir --ignore-fail-on-non-empty $PACKAGE_DIR
6f10b394
ER
2113}
2114
cd445739
AM
2115#---------------------------------------------
2116# main()
2117
2d5c07df 2118if [ $# = 0 ]; then
518ff1fb 2119 usage
cd445739
AM
2120 exit 1
2121fi
2122
0b668a05
ER
2123# stuff global $BUILDER_OPTS from env as args
2124if [ "$BUILDER_OPTS" ]; then
2125 set -- "$BUILDER_OPTS" "$@"
2126fi
2127
2d5c07df 2128while [ $# -gt 0 ]; do
cd445739 2129 case "${1}" in
5efcb865 2130 -4|-6)
6d641507 2131 IPOPT="${1}"
5efcb865
ER
2132 shift
2133 ;;
2d5c07df 2134 -5 | --update-md5)
518ff1fb 2135 COMMAND="update_md5"
cd445739
AM
2136 NODIST="yes"
2137 NOCVSSPEC="yes"
cd445739
AM
2138 shift ;;
2139 -a5 | --add-md5 )
518ff1fb 2140 COMMAND="update_md5"
cd445739 2141 NODIST="yes"
cd445739 2142 NOCVSSPEC="yes"
cd445739
AM
2143 ADD5="yes"
2144 shift ;;
2145 -n5 | --no-md5 )
2146 NO5="yes"
2147 shift ;;
2148 -D | --debug )
2149 DEBUG="yes"; shift ;;
2150 -V | --version )
2151 COMMAND="version"; shift ;;
d43959a2
ER
2152 --short-version )
2153 COMMAND="short-version"; shift ;;
db9fdf51
ER
2154 -a | --add_cvs)
2155 COMMAND="add_cvs";
2156 shift ;;
3f79cb18
KK
2157 --all-branches )
2158 ALL_BRANCHES="yes"
2159 shift ;;
cd445739
AM
2160 -b | -ba | --build )
2161 COMMAND="build"; shift ;;
2162 -bb | --build-binary )
2163 COMMAND="build-binary"; shift ;;
6594293d
AG
2164 -bc )
2165 COMMAND="build-build"; shift ;;
2166 -bi )
2167 COMMAND="build-install"; shift ;;
2168 -bl )
2169 COMMAND="build-list"; shift ;;
cd445739
AM
2170 -bp | --build-prep )
2171 COMMAND="build-prep"; shift ;;
6594293d
AG
2172 -bs | --build-source )
2173 COMMAND="build-source"; shift ;;
cd445739
AM
2174 -B | --branch )
2175 COMMAND="branch"; shift; TAG="${1}"; shift;;
2176 -c | --clean )
387eaf99 2177 CLEAN="--clean"; shift ;;
39dcc7de 2178 -cf | --cvs-force )
df1306b5 2179 CVS_FORCE="-f"; shift;;
3189511a
KK
2180 --depth )
2181 DEPTH="--depth=$2"
2182 shift 2
2183 ;;
cd445739
AM
2184 -g | --get )
2185 COMMAND="get"; shift ;;
2186 -h | --help )
2187 COMMAND="usage"; shift ;;
fd71d65c
ER
2188 --ftp )
2189 PROTOCOL="ftp"; shift ;;
cd445739
AM
2190 --http )
2191 PROTOCOL="http"; shift ;;
6c5362e5
ER
2192 -j)
2193 RPMOPTS="${RPMOPTS} --define \"_smp_mflags -j$2\""
2194 shift 2
2195 ;;
2196 -j[0-9]*)
2197 RPMOPTS="${RPMOPTS} --define \"_smp_mflags $1\""
2198 shift
2199 ;;
d4c8d3a9
ER
2200 -p)
2201 PARALLEL_DOWNLOADS=$2
2202 shift 2
2203 ;;
2204 -p[0-9])
2205 PARALLEL_DOWNLOADS=${1#-p}
2206 shift
2207 ;;
cd445739
AM
2208 -l | --logtofile )
2209 shift; LOGFILE="${1}"; shift ;;
2210 -ni| --nice )
2211 shift; DEF_NICE_LEVEL=${1}; shift ;;
18e5347d
ER
2212 -ske | --skip-existing-files)
2213 SKIP_EXISTING_FILES="yes"; shift ;;
cd445739
AM
2214 -m | --mr-proper )
2215 COMMAND="mr-proper"; shift ;;
cd445739
AM
2216 -ncs | --no-cvs-specs )
2217 NOCVSSPEC="yes"; shift ;;
2218 -nd | --no-distfiles )
2219 NODIST="yes"; shift ;;
2220 -nm | --no-mirrors )
2221 NOMIRRORS="yes"; shift ;;
2222 -nu | --no-urls )
2223 NOURLS="yes"; shift ;;
2224 -ns | --no-srcs )
2225 NOSRCS="yes"; shift ;;
2226 -ns0 | --no-source0 )
2227 NOSOURCE0="yes"; shift ;;
2228 -nn | --no-net )
cd445739
AM
2229 NOCVSSPEC="yes"
2230 NODIST="yes"
2231 NOMIRRORS="yes"
2232 NOURLS="yes"
2233 NOSRCS="yes"
f09c0772 2234 ALWAYS_CVSUP="no"
cd445739 2235 shift;;
bc10f694
JB
2236 -pm | --prefer-mirrors )
2237 PREFMIRRORS="yes"
2238 shift;;
89e05bdd 2239 --noinit | --no-init )
29e90b02
JR
2240 NOINIT="yes"
2241 shift;;
cd445739 2242 --opts )
4250a189 2243 shift; RPMOPTS="${RPMOPTS} ${1}"; shift ;;
469e5fd1 2244 --nopatch | -np )
3accf718 2245 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : ignoring patch${1}; exit 1; \""; shift ;;
8bd5e66d
ER
2246 --skip-patch | -sp )
2247 shift; RPMOPTS="${RPMOPTS} --define \"patch${1} : skiping patch${1}\""; shift ;;
dfa39149
ER
2248 --topdir)
2249 RPMOPTS="${RPMOPTS} --define \"_topdir $2\""
2250 shift 2
2251 ;;
cd445739
AM
2252 --with | --without )
2253 case $GROUP_BCONDS in
2254 "yes")
2255 COND=${1}
2256 shift
c2e1d2a2 2257 # XXX: broken: ./builder -bb ucspi-tcp.spec --without mysql
cd445739
AM
2258 while ! `echo ${1}|grep -qE '(^-|spec)'`
2259 do
2260 BCOND="$BCOND $COND $1"
2261 shift
2262 done;;
2263 "no")
d4d1ec20 2264 if [[ "$2" = *,* ]]; then
ce40491a
ER
2265 for a in $(echo "$2" | tr , ' '); do
2266 BCOND="$BCOND $1 $a"
2267 done
d4d1ec20 2268 else
ce40491a 2269 BCOND="$BCOND $1 $2"
d4d1ec20
ER
2270 fi
2271 shift 2 ;;
cd445739
AM
2272 esac
2273 ;;
64ea5308 2274 --target )
2275 shift; TARGET="${1}"; shift ;;
6dd19291 2276 --target=* )
2277 TARGET=$(echo "${1}" | sed 's/^--target=//'); shift ;;
cd445739
AM
2278 -q | --quiet )
2279 QUIET="--quiet"; shift ;;
2280 --date )
d383b191
KK
2281 CVSDATE="${2}"; shift 2
2282 date -d "$CVSDATE" > /dev/null 2>&1 || { echo >&2 "No valid date specified"; exit 3; }
2283 ;;
cd445739 2284 -r | --cvstag )
3ccc5cef
ER
2285 CVSTAG="$2"
2286 shift 2
2287 ;;
5323fffd 2288 -A)
3ccc5cef 2289 shift
aa43ca3e 2290 CVSTAG="master"
3ccc5cef 2291 ;;
cd445739
AM
2292 -R | --fetch-build-requires)
2293 FETCH_BUILD_REQUIRES="yes"
2294 NOT_INSTALLED_PACKAGES=
2295 shift ;;
2296 -RB | --remove-build-requires)
2297 REMOVE_BUILD_REQUIRES="nice"
2298 shift ;;
2299 -FRB | --force-remove-build-requires)
2300 REMOVE_BUILD_REQUIRES="force"
2301 shift ;;
f982c603 2302 -sc | --source-cvs)
e15852ab
JR
2303 COMMAND="list-sources-cvs"
2304 shift ;;
ae58a474 2305 -sd | --source-distfiles)
06541433
JR
2306 COMMAND="list-sources-distfiles"
2307 shift ;;
ae58a474 2308 -sdp | --source-distfiles-paths)
06541433
JR
2309 COMMAND="list-sources-distfiles-paths"
2310 shift ;;
ae58a474 2311 -sf | --source-files)
a7eefc54 2312 COMMAND="list-sources-files"
95ad5bf0 2313 shift ;;
ae58a474 2314 -lsp | --source-paths)
a7eefc54 2315 COMMAND="list-sources-local-paths"
95ad5bf0 2316 shift ;;
ae58a474 2317 -su | --source-urls)
2dddf439
ER
2318 COMMAND="list-sources-urls"
2319 shift ;;
cd445739 2320 -Tvs | --tag-version-stable )
518ff1fb 2321 COMMAND="tag"
cd445739
AM
2322 TAG="STABLE"
2323 TAG_VERSION="yes"
2324 shift;;
cd445739 2325 -Ts | --tag-stable )
518ff1fb 2326 COMMAND="tag"
cd445739
AM
2327 TAG="STABLE"
2328 TAG_VERSION="no"
2329 shift;;
cd445739 2330 -Tv | --tag-version )
518ff1fb 2331 COMMAND="tag"
cd445739
AM
2332 TAG=""
2333 TAG_VERSION="yes"
2334 shift;;
2335 -Tp | --tag-prefix )
2336 TAG_PREFIX="$2"
2337 shift 2;;
2338 -tt | --test-tag )
2339 TEST_TAG="yes"
2340 shift;;
2341 -T | --tag )
518ff1fb 2342 COMMAND="tag"
cd445739
AM
2343 shift
2344 TAG="$1"
2345 TAG_VERSION="no"
2346 shift;;
50321881
JK
2347 -ir | --integer-release-only )
2348 INTEGER_RELEASE="yes"
2349 shift;;
cd445739 2350 -U | --update )
ecba6ad5 2351 COMMAND="update_md5"
cd445739
AM
2352 UPDATE="yes"
2353 NOCVSSPEC="yes"
2354 NODIST="yes"
cd445739
AM
2355 shift ;;
2356 -Upi | --update-poldek-indexes )
2357 UPDATE_POLDEK_INDEXES="yes"
2358 shift ;;
5eb1d24b 2359 --init-rpm-dir|--init)
518ff1fb 2360 COMMAND="init_rpm_dir"
ce5daafb 2361 shift ;;
cd445739
AM
2362 -u | --try-upgrade )
2363 TRY_UPGRADE="1"; shift ;;
0907f1eb
ER
2364 --upgrade-version )
2365 shift; UPGRADE_VERSION="$1"; shift;;
cd445739
AM
2366 -un | --try-upgrade-with-float-version )
2367 TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;;
2368 -v | --verbose )
2369 BE_VERBOSE="1"; shift ;;
2370 --define)
2371 shift
2372 MACRO="${1}"
cf264933 2373 shift
2374 if echo "${MACRO}" | grep -q '\W'; then
2375 RPMOPTS="${RPMOPTS} --define \"${MACRO}\""
2376 else
2377 VALUE="${1}"
2378 shift
2379 RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\""
2380 fi
cd445739 2381 ;;
44058243
ER
2382 --alt_kernel)
2383 shift
5153358c 2384 RPMOPTS="${RPMOPTS} --define \"alt_kernel $1\" --define \"build_kernels $1\""
44058243
ER
2385 shift
2386 ;;
6594293d
AG
2387 --short-circuit)
2388 RPMBUILDOPTS="${RPMBUILDOPTS} --short-circuit"
2389 shift
2390 ;;
dfe2cb9a 2391 --show-bconds | -show-bconds | -print-bconds | --print-bconds | -display-bconds | --display-bconds )
518ff1fb 2392 COMMAND="show_bconds"
dfe2cb9a
MK
2393 shift
2394 ;;
9b78be50
ER
2395 --show-bcond-args)
2396 COMMAND="show_bcond_args"
2397 shift
2398 ;;
24a97174
ER
2399 --show-avail-bconds)
2400 COMMAND="show_avail_bconds"
2401 shift
2402 ;;
cd445739
AM
2403 --nodeps)
2404 shift
2405 RPMOPTS="${RPMOPTS} --nodeps"
2406 ;;
9243e80b 2407 -debug)
a08d92fc
ER
2408 RPMBUILDOPTS="${RPMBUILDOPTS} -debug"; shift
2409 ;;
bb4d488a 2410 -*)
a08d92fc
ER
2411 Exit_error err_invalid_cmdline "$1"
2412 ;;
bb4d488a 2413 *)
76997578 2414 SPECFILE=${1%/}; shift
f19103b5
AG
2415 # check if specname was passed as specname:cvstag
2416 if [ "${SPECFILE##*:}" != "${SPECFILE}" ]; then
518ff1fb
ER
2417 CVSTAG="${SPECFILE##*:}"
2418 SPECFILE="${SPECFILE%%:*}"
f19103b5 2419 fi
8f7946e0
ER
2420 # always have SPECFILE ending with .spec extension
2421 SPECFILE=${SPECFILE%%.spec}.spec
a8c9a155 2422 ASSUMED_NAME=$(basename ${SPECFILE%%.spec})
cd445739
AM
2423 esac
2424done
2425
3ccc5cef
ER
2426if [ "$CVSTAG" ]; then
2427 # pass $CVSTAG used by builder to rpmbuild too, so specs could use it
2428 RPMOPTS="$RPMOPTS --define \"_cvstag $CVSTAG\""
2429fi
2430
3f79cb18
KK
2431if [ -n "$ALL_BRANCHES" -a -z "$DEPTH" ]; then
2432 echo >&2 "--all branches requires --depth <number>"
2433 Exit_error err_invalid_cmdline
2434fi
2435
cd445739 2436if [ -n "$DEBUG" ]; then
518ff1fb
ER
2437 set -x
2438 set -v
cd445739
AM
2439fi
2440
2a5f078d 2441if [ -n "$TARGET" ]; then
2442 case "$RPMBUILD" in
2443 "rpmbuild")
2444 TARGET_SWITCH="--target $TARGET" ;;
2445 "rpm")
2446 TARGET_SWITCH="--target=$TARGET" ;;
2447 esac
2448fi
2449
86aafdbe
ER
2450if [ "$SCHEDTOOL" != "no" ]; then
2451 NICE_COMMAND="$SCHEDTOOL"
2452else
2453 NICE_COMMAND="nice -n ${DEF_NICE_LEVEL}"
2454fi
2455
6dd8b9cc
ER
2456# see time(1) for output format that could be used
2457TIME_COMMAND="time -p"
2458
c890b916 2459update_shell_title "$COMMAND"
cd445739 2460case "$COMMAND" in
117d9861
ER
2461 "show_bconds")
2462 init_builder
8b7889f3
ER
2463 if [ -z "$SPECFILE" ]; then
2464 Exit_error err_no_spec_in_cmdl
117d9861 2465 fi
8b7889f3
ER
2466 get_spec > /dev/null
2467 parse_spec
2468 set_bconds_values
2469 display_bconds
117d9861 2470 ;;
9b78be50
ER
2471 "show_bcond_args")
2472 init_builder
8b7889f3
ER
2473 if [ -z "$SPECFILE" ]; then
2474 Exit_error err_no_spec_in_cmdl
9b78be50 2475 fi
8b7889f3
ER
2476 get_spec > /dev/null
2477 parse_spec
2478 set_bconds_values
2479 echo "$BCOND"
24a97174
ER
2480 ;;
2481 "show_avail_bconds")
2482 init_builder
8b7889f3
ER
2483 if [ -z "$SPECFILE" ]; then
2484 Exit_error err_no_spec_in_cmdl
24a97174
ER
2485 fi
2486
8b7889f3
ER
2487 get_spec > /dev/null
2488 parse_spec
2489 local bcond_avail=$(find_spec_bcond $SPECFILE)
2490 local opt bcond bconds
2491 for opt in $bcond_avail; do
2492 case "$opt" in
2493 without_*)
2494 bcond=${opt#without_}
2495 bconds="$bconds $bcond"
2496 ;;
2497 with_*)
2498 bcond=${opt#with_}
2499 bconds="$bconds $bcond"
2500 ;;
2501 *)
2502 echo >&2 "ERROR: unexpected '$opt' in show_avail_bconds"
2503 exit 1
2504 ;;
2505 esac
2506 done
2507 echo $bconds
2508
9b78be50 2509 ;;
6594293d 2510 "build" | "build-binary" | "build-source" | "build-prep" | "build-build" | "build-install" | "build-list")
117d9861 2511 init_builder
db9fdf51
ER
2512 if [ -z "$SPECFILE" ]; then
2513 Exit_error err_no_spec_in_cmdl
2514 fi
62623fc0 2515
db9fdf51
ER
2516 # display SMP make flags if set
2517 smp_mflags=$(rpm -E %{?_smp_mflags})
2518 if [ "$smp_mflags" ]; then
2519 echo "builder: SMP make flags are set to $smp_mflags"
2520 fi
2521
2522 get_spec
2523 parse_spec
2524 set_bconds_values
2525 display_bconds
2526 display_branches
2527 if [ "$COMMAND" != "build-source" ]; then
2528 check_buildarch
2529 fi
2530 fetch_build_requires
2531 if [ "$INTEGER_RELEASE" = "yes" ]; then
2532 echo "Checking release $PACKAGE_RELEASE..."
2533 if echo $PACKAGE_RELEASE | grep -q '^[^.]*\.[^.]*$' 2>/dev/null ; then
2534 Exit_error err_fract_rel "$PACKAGE_RELEASE"
cd445739 2535 fi
db9fdf51 2536 fi
cd445739 2537
db9fdf51
ER
2538 # ./builder -bs test.spec -r AC-branch -Tp auto-ac- -tt
2539 if [ -n "$TEST_TAG" ]; then
2540 local TAGVER=`make_tagver`
2fc07e25 2541 tag_exist $TAGVER || [ $TAGVER = $CVSTAG ] || Exit_error err_tag_exists $TAGVER
8c043136 2542 # check also tags created in CVS
2fc07e25 2543 local TAGVER_CVS=$(echo $TAGVER | tr '[.@]' '[_#]')
d03404e7
KK
2544 local CVSTAG_CVS=$(echo $CVSTAG | tr '[.@]' '[_#]')
2545 tag_exist $TAGVER_CVS || [ $TAGVER_CVS = $CVSTAG_CVS ] \
2546 || Exit_error err_tag_exists $TAGVER_CVS
db9fdf51 2547 # - do not allow to build from HEAD when XX-branch exists
2200d50e 2548 TREE_PREFIX=$(echo "$TAG_PREFIX" | sed -e 's#^auto/\([a-zA-Z]\+\)/.*#\1#g')
b6c4f6ba 2549 if [ "$TAGVER" != "$CVSTAG" -a "$TAGVER_CVS" != "$CVSTAG" -a "$TREE_PREFIX" != "$TAG_PREFIX" ]; then
db9fdf51 2550 TAG_BRANCH="${TREE_PREFIX}-branch"
f9b0409c
KK
2551 if [ -n "$DEPTH" ]; then
2552 cmd_branches="git ls-remote --heads"
2553 ref_prefix=refs/heads
2554 else
2555 cmd_branches="git show-ref"
2556 ref_prefix=refs/remotes/${REMOTE_PLD}
2557 fi
0c6ce8b5
KK
2558 TAG_STATUS=$($cmd_branches | grep -i "${ref_prefix}/$TAG_BRANCH$" | cut -c'-40')
2559 if [ -n "$TAG_STATUS" -a "$TAG_STATUS" != $(git rev-parse "$CVSTAG") ]; then
db9fdf51 2560 Exit_error err_branch_exists "$TAG_STATUS"
074de301 2561 fi
2a5f078d 2562 fi
2563
cd445739 2564 fi
db9fdf51
ER
2565
2566 if [ -n "$NOSOURCE0" ] ; then
2567 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2568 fi
2569 try_upgrade
2570 case $? in
2571 0)
2572 get_files $SOURCES $PATCHES
d3df4e78 2573 check_md5 $SOURCES $PATCHES
db9fdf51
ER
2574 ;;
2575 *)
2576 NODIST="yes" get_files $SOURCES $PATCHES
647e3d7f 2577 update_md5 $SOURCES $PATCHES
db9fdf51
ER
2578 ;;
2579 esac
2580 build_package
fe7c0a38 2581 if [ "$UPDATE_POLDEK_INDEXES" = "yes" ] && [ "$COMMAND" = "build" -o "$COMMAND" = "build-binary" ]; then
8a390970 2582 run_poldek --sdir="${POLDEK_INDEX_DIR}" ${UPDATE_POLDEK_INDEXES_OPTS} --mkidxz
db9fdf51
ER
2583 fi
2584 remove_build_requires
2a5f078d 2585 ;;
cd445739 2586 "branch" )
518ff1fb 2587 init_builder
db9fdf51 2588 if [ -z "$SPECFILE" ]; then
518ff1fb 2589 Exit_error err_no_spec_in_cmdl
cd445739 2590 fi
db9fdf51
ER
2591
2592 get_spec
2593 parse_spec
f663f264 2594 branch_files $TAG
cd445739 2595 ;;
703b6deb
ER
2596 "add_cvs" )
2597 init_builder
2598 if [ -z "$SPECFILE" ]; then
2599 Exit_error err_no_spec_in_cmdl
2600 fi
2601
406b9ecf
KK
2602 create_git_repo
2603 if [ -n "$NEW_REPO" ]; then
2604 parse_spec
2605 local file
2606 for file in $SOURCES $PATCHES; do
2607 if [ -z $(src_md5 "$file") ]; then
2608 git add $file || Exit_error err_no_source_in_repo $file
2609 else
2610 cvsignore_df `nourl $file`
2611 fi
2612 done
2613 git add $SPECFILE
c9933bf8 2614 echo "When you are ready commit your changes and run git push origin master"
406b9ecf
KK
2615 else
2616 echo "You had already git repository. Push chosen branches to remote: ${REMOTE_PLD}"
703b6deb 2617 fi
703b6deb 2618 ;;
cd445739 2619 "get" )
518ff1fb 2620 init_builder
db9fdf51 2621 if [ -z "$SPECFILE" ]; then
518ff1fb 2622 Exit_error err_no_spec_in_cmdl
ecba6ad5 2623 fi
db9fdf51
ER
2624
2625 get_spec
2626 parse_spec
2627
2628 if [ -n "$NOSOURCE0" ] ; then
2629 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2630 fi
2631 get_files $SOURCES $PATCHES
2632 check_md5 $SOURCES
652dc2d1 2633 fetch_build_requires
ecba6ad5
ER
2634 ;;
2635 "update_md5" )
518ff1fb 2636 init_builder
db9fdf51 2637 if [ -z "$SPECFILE" ]; then
518ff1fb 2638 Exit_error err_no_spec_in_cmdl
cd445739 2639 fi
db9fdf51
ER
2640
2641 get_spec
2642 parse_spec
2643
2644 if [ -n "$NOSOURCE0" ] ; then
2645 SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'`
2646 fi
647e3d7f 2647 update_md5 $SOURCES $PATCHES
cd445739
AM
2648 ;;
2649 "tag" )
2650 NOURLS=1
f7b91886 2651 NODIST="yes"
518ff1fb 2652 init_builder
db9fdf51 2653 if [ -z "$SPECFILE" ]; then
518ff1fb 2654 Exit_error err_no_spec_in_cmdl
cd445739 2655 fi
db9fdf51 2656
db9fdf51 2657 parse_spec
cc4edaf4
KK
2658 if [ ! -d .git ]; then
2659 echo "No git reposiotory" >&2
2660 exit 101
2661 fi
1fb35df5 2662 tag_files
cd445739
AM
2663 ;;
2664 "mr-proper" )
6f10b394 2665 mr_proper
cd445739 2666 ;;
a7eefc54 2667 "list-sources-files" )
2668 init_builder
2669 NOCVSSPEC="yes"
2670 DONT_PRINT_REVISION="yes"
2671 get_spec
2672 parse_spec
ecba6ad5 2673 for SAP in $SOURCES $PATCHES; do
ce40491a 2674 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
a7eefc54 2675 done
2676 ;;
2dddf439 2677 "list-sources-urls" )
fe61ecd4 2678 init_builder >&2
2dddf439
ER
2679 NOCVSSPEC="yes"
2680 DONT_PRINT_REVISION="yes"
fe61ecd4
ER
2681 get_spec >&2
2682 parse_spec >&2
2dddf439 2683 SAPS="$SOURCES $PATCHES"
fe61ecd4 2684 for SAP in $SAPS; do
ce40491a 2685 echo $SAP
2dddf439
ER
2686 done
2687 ;;
a7eefc54 2688 "list-sources-local-paths" )
2689 init_builder
2690 NOCVSSPEC="yes"
2691 DONT_PRINT_REVISION="yes"
2692 get_spec
2693 parse_spec
ecba6ad5 2694 for SAP in $SOURCES $PATCHES; do
9c909460 2695 echo $PACKAGE_DIR/$(echo $SAP | awk '{gsub(/.*\//,"") ; print }')
a7eefc54 2696 done
2697 ;;
06541433
JR
2698 "list-sources-distfiles-paths" )
2699 init_builder
2700 NOCVSSPEC="yes"
2701 DONT_PRINT_REVISION="yes"
2702 get_spec
2703 parse_spec
ecba6ad5 2704 for SAP in $SOURCES $PATCHES; do
06541433
JR
2705 if [ -n "$(src_md5 "$SAP")" ]; then
2706 distfiles_path "$SAP"
2707 fi
2708 done
2709 ;;
2710 "list-sources-distfiles" )
2711 init_builder
2712 NOCVSSPEC="yes"
2713 DONT_PRINT_REVISION="yes"
2714 get_spec
2715 parse_spec
ecba6ad5 2716 for SAP in $SOURCES $PATCHES; do
06541433
JR
2717 if [ -n "$(src_md5 "$SAP")" ]; then
2718 distfiles_url "$SAP"
2719 fi
2720 done
2721 ;;
e15852ab
JR
2722 "list-sources-cvs" )
2723 init_builder
2724# NOCVSSPEC="yes"
2725 DONT_PRINT_REVISION="yes"
2726 get_spec
2727 parse_spec
2728 for SAP in $SOURCES $PATCHES; do
2729 if [ -z "$(src_md5 "$SAP")" ]; then
2730 echo $SAP | awk '{gsub(/.*\//,"") ; print}'
2731 fi
2732 done
2733 ;;
ce5daafb
ER
2734 "init_rpm_dir")
2735 init_rpm_dir
2736 ;;
cd445739 2737 "usage" )
d43959a2
ER
2738 usage
2739 ;;
2740 "short-version" )
2741 echo "$VERSION"
2742 ;;
cd445739 2743 "version" )
d43959a2
ER
2744 echo "$VERSIONSTRING"
2745 ;;
bde1c404 2746esac
31898c61
AM
2747if [ -f "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES" -a "$REMOVE_BUILD_REQUIRES" != "" ]; then
2748 rm "`pwd`/.${SPECFILE}_INSTALLED_PACKAGES"
03d5c71d 2749fi
cd445739
AM
2750cd "$__PWD"
2751
73848362 2752# vi:syntax=sh:ts=4:sw=4:noet
This page took 1.053715 seconds and 4 git commands to generate.