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