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