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