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