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