]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
v4.6: actually package dropin script; rename pldnotify without "extension"
[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")
cd112f74 38RCSID='$Id: builder,v 1.645 2011/02/13 17:54:10 glen Exp $' r=${RCSID#* * } rev=${r%% *}
b0f031e7 39VERSION="v0.35/$rev"
d43959a2 40VERSIONSTRING="\
b71f5024 41Build package utility from PLD Linux Packages repository
5fe6b5d9 42$VERSION (C) 1999-2013 Free Penguins".
d43959a2 43
670b1ed4 44CLEAN_PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
b03f053b 45
b7cc0c94
ER
46# required rpm-build-macros
47RPM_MACROS_VER=1.534
48
cd445739 49COMMAND="build"
64ea5308 50TARGET=""
cd445739 51
bde1c404 52SPECFILE=""
d287305c 53BE_VERBOSE=""
4003ad8c 54QUIET=""
cd445739
AM
55CLEAN=""
56DEBUG=""
57NOURLS=""
cd445739
AM
58NOCVSSPEC=""
59NODIST=""
47761337 60NOINIT=""
bc10f694 61PREFMIRRORS=""
cd445739 62UPDATE=""
cd445739
AM
63ADD5=""
64NO5=""
65ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
cd445739 66
6c1b2e7d
PZ
67# use rpm 4.4.6+ digest format instead of comments if non-zero
68USEDIGEST=
69
e3aa6f5e
ER
70# user agent when fetching files
71USER_AGENT="PLD/Builder($VERSION)"
72
cd445739
AM
73# It can be used i.e. in log file naming.
74# See LOGFILE example.
75DATE=`date +%Y-%m-%d_%H-%M-%S`
76
7534a77d
ER
77# target arch, can also be used for log file naming
78TARGET=$(rpm -E %{_target})
79
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'
cd445739
AM
84# Yes, you can use variable name! Note _single_ quotes!
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"
2060f498
AM
114
115# use lftp by default when available
f4bac425 116USE_LFTP=
2060f498 117lftp --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
cd445739 183#
a83e5405 184SU_SUDO=""
cd445739
AM
185if [ -n "$HOME_ETC" ]; then
186 USER_CFG="$HOME_ETC/.builderrc"
20117088 187 BUILDER_MACROS="$HOME_ETC/.builder-rpmmacros"
cd445739
AM
188else
189 USER_CFG=~/.builderrc
20117088 190 BUILDER_MACROS=~/.builder-rpmmacros
cd445739
AM
191fi
192
193[ -f "$USER_CFG" ] && . "$USER_CFG"
194
86aafdbe
ER
195if [ "$SCHEDTOOL" = "auto" ]; then
196 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
197 SCHEDTOOL="schedtool -B -e"
198 else
199 SCHEDTOOL="no"
200 fi
201fi
202
ca2e6c31 203if [ -n "$USE_PROZILLA" ]; then
7e365483
KK
204 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
205 GETURI2="$GETURI"
206 OUTFILEOPT="-O"
ca2e6c31 207elif [ -n "$USE_AXEL" ]; then
cede92b3 208 GETURI="axel -a $AXEL_OPTS"
7e365483
KK
209 GETURI2="$GETURI"
210 OUTFILEOPT="-o"
9639be96 211elif [ -n "$USE_LFTP" ]; then
9639be96
AM
212 GETURI=download_lftp
213 GETURI2=$GETURI
214 OUTFILEOPT=""
ca2e6c31 215else
5700ee32
ER
216 wget --help 2>&1 | grep -q -- ' --no-check-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
217 wget --help 2>&1 | grep -q -- ' --inet ' && WGET_OPTS="$WGET_OPTS --inet"
218 wget --help 2>&1 | grep -q -- ' --retry-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
e3aa6f5e 219 WGET_OPTS="$WGET_OPTS --user-agent=$USER_AGENT"
6f9a5d76 220
7e365483
KK
221 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
222 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
223 OUTFILEOPT="-O"
2bc5451f 224fi
11468b23 225
11468b23
AM
226GETLOCAL="cp -a"
227
15e34b63 228if rpm --version 2>&1 | grep -q '4.0.[0-2]'; then
11468b23
AM
229 RPM="rpm"
230 RPMBUILD="rpm"
231else
232 RPM="rpm"
233 RPMBUILD="rpmbuild"
234fi
235
c86939e2 236#
237# sanity checks
238#
239if [ -d $HOME/rpm/SOURCES ]; then
240 echo "ERROR: ~/rpm/{SPECS,SOURCES} structure is obsolete" >&2
241 echo "ERROR: get rid of your ~/rpm/SOURCES" >&2
242 exit 1
243fi
244
a8c9a155 245POLDEK_INDEX_DIR="$($RPM --eval %_rpmdir)/"
a83e5405 246POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
11468b23 247
12da9e3d 248# TODO: add teeboth
f6711e2a 249run_poldek() {
390d081d 250 RES_FILE=$(tempfile)
cd445739
AM
251 if [ -n "$LOGFILE" ]; then
252 LOG=`eval echo $LOGFILE`
253 if [ -n "$LASTLOG_FILE" ]; then
254 echo "LASTLOG=$LOG" > $LASTLOG_FILE
255 fi
86aafdbe 256 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
12da9e3d 257 # FIXME $exit_pldk undefined
cd445739
AM
258 return $exit_pldk
259 else
86aafdbe 260 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
cd445739
AM
261 return `cat ${RES_FILE}`
262 rm -rf ${RES_FILE}
263 fi
264}
265
cd445739
AM
266#---------------------------------------------
267# functions
da946cd6 268
f4bac425 269download_lftp() {
6928bb29 270 local outfile=$1 url=$2 retval tmpfile
f4bac425
ER
271 # TODO: use mktemp
272 tmpfile=$outfile.tmp
4d1fc6ce
AM
273 lftp -c "
274 $([ "$DEBUG" = "yes" ] && echo "debug 5;")
78ff632e 275 set ssl:verify-certificate no;
4d1fc6ce
AM
276 set net:max-retries $WGET_RETRIES;
277 set http:user-agent \"$USER_AGENT\";
d4c8d3a9 278 pget -n $PARALLEL_DOWNLOADS -c \"$url\" -o \"$tmpfile\"
4d1fc6ce 279 "
f4bac425
ER
280
281 retval=$?
282 if [ $retval -eq 0 ]; then
283 mv -f "$tmpfile" "$outfile"
284 else
285 rm -f "$tmpfile"
286 fi
287 return $retval
288}
289
f6711e2a 290usage() {
cd445739 291 if [ -n "$DEBUG" ]; then set -xv; fi
647fead0
ER
292# NOTE:
293# to make this output parseable by bash-completion _parse_help()
294# if the line contains short and long option, it will take only the long option
295# but if you want both being completed, put the short option to separate line
cd445739 296 echo "\
3f79cb18 297Usage: builder [--all-branches] [-D|--debug] [-V|--version] [--short-version] [-a|--add_cvs] [-b|-ba|--build]
6594293d 298[-bb|--build-binary] [-bs|--build-source] [-bc] [-bi] [-bl] [-u|--try-upgrade]
0c8e5e9d 299[{-cf|--cvs-force}] [{-B|--branch} <branch>] [--depth <number>]
fd71d65c 300[-g|--get] [-h|--help] [--ftp] [--http] [{-l|--logtofile} <logfile>] [-m|--mr-proper]
ccb03bc0 301[-q|--quiet] [--date <yyyy-mm-dd> [-r <tag>] [{-T|--tag <tag>]
a7b2951c 302[-Tvs|--tag-version-stable] [-Ts|--tag-stable] [-Tv|--tag-version]
b3b584c5 303[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
6594293d 304[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--short-circuit]
3009b80d 305[--show-bconds] [--with/--without <feature>] [--define <macro> <value>]
ccb03bc0 306<package>[.spec][:tag]
2a5f078d 307
647fead0
ER
308-4 - force IPv4 when transferring files
309-6 - force IPv6 when transferring files
310-5,
311--update-md5 - update md5 comments in spec, implies -nd -ncs
312-a5,
313--add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
4ca1edbd 314--all-branches - make shallow fetch of all branches; --depth required
cd445739 315-n5, --no-md5 - ignore md5 comments in spec
9243e80b
ER
316-D, --debug - enable builder script debugging mode,
317-debug - produce rpm debug package (same as --opts -debug)
d43959a2
ER
318-V, --version - output builder version string
319--short-version - output builder short version
647fead0
ER
320-a - try add new package to PLD repo.
321-b,
322-ba
323 - get all files from PLD repo or HTTP/FTP and build package
cd445739 324 from <package>.spec,
647fead0 325-bb - get all files from PLD repo or HTTP/FTP and build binary
cd445739 326 only package from <package>.spec,
647fead0 327-bp - execute the %prep phase of <package>.spec,
6594293d
AG
328-bc - execute the %build phase of <package>.spec,
329-bi - execute the %install phase of <package>.spec
4ca1edbd 330-bl - execute the %files phase of <package>.spec
647fead0 331-bs - get all files from PLD repo or HTTP/FTP and only pack
cd445739 332 them into src.rpm,
6594293d 333--short-circuit - short-circuit build
cd445739 334-B, --branch - add branch
647fead0
ER
335-c,
336--clean - clean all temporarily created files (in BUILD\$RPM_BUILD_ROOT) after rpmbuild commands.
387eaf99 337 may be used with building process.
6f10b394 338-m, --mr-proper - clean all temporarily created files (in BUILD, SOURCES,
4ca1edbd
KK
339 SPECS and \$RPM_BUILD_ROOT). Doesn't run any rpm building.
340-cf, --cvs-force - use -f when tagging
eccfb714 341--define '<macro> <value>'
cd445739 342 - define a macro <macro> with value <value>,
4ca1edbd 343--depth <number> - make shallow fetch
44058243
ER
344--alt_kernel <kernel>
345 - same as --define 'alt_kernel <kernel>'
cd445739 346--nodeps - rpm won't check any dependences
647fead0
ER
347-g
348--get - get <package>.spec and all related files from PLD repo
cd445739 349-h, --help - this message,
647fead0
ER
350-j N - set %_smp_mflags to propagate concurrent jobs
351--ftp - use FTP protocol to access distfiles server
352--http - use HTTP protocol to access distfiles server
353-l <logfile>, --logtofile=<logfile>
cd445739 354 - log all to file,
cd445739 355-ncs, --no-cvs-specs
ccb03bc0 356 - don't pull from PLD repo
cd445739
AM
357-nd, --no-distfiles - don't download from distfiles
358-nm, --no-mirrors - don't download from mirror, if source URL is given,
359-nu, --no-urls - don't try to download from FTP/HTTP location,
7cbc2d88 360-ns, --no-srcs - don't download Sources/Patches
cd445739
AM
361-ns0, --no-source0 - don't download Source0
362-nn, --no-net - don't download anything from the net
647fead0 363-p N - set PARALLEL_DOWNLOADS to N (default $PARALLEL_DOWNLOADS)
4ca1edbd
KK
364-pm, --prefer-mirrors
365 - prefer mirrors (if any) over distfiles for SOURCES
b572253e 366--no-init - don't initialize builder paths (SPECS and SOURCES)
18e5347d 367-ske,
4ca1edbd
KK
368--skip-existing-files
369 - skip existing files in get_files
cd445739
AM
370--opts <rpm opts> - additional options for rpm
371-q, --quiet - be quiet,
ccb03bc0
KK
372--date yyyy-mm-dd - build package using resources from specified date,
373-r <tag>, --cvstag <ref>
374 - build package using resources from specified branch/tag,
5053a974 375-A - build package using master branch as any sticky tags/branch/date being reset.
cd445739
AM
376-R, --fetch-build-requires
377 - fetch what is BuildRequired,
378-RB, --remove-build-requires
379 - remove all you fetched with -R or --fetch-build-requires
380 remember, this option requires confirmation,
381-FRB, --force-remove-build-requires
382 - remove all you fetched with -R or --fetch-build-requires
383 remember, this option works without confirmation,
4ca1edbd
KK
384-sd, --source-distfiles
385 - list sources available from distfiles (intended for offline
06541433
JR
386 operations; does not work when Icon field is present
387 but icon file is absent),
4ca1edbd
KK
388-sc, --source-cvs - list sources available from PLD repo
389-sdp, --source-distfiles-paths
390 - list sources available from distfiles -
06541433
JR
391 paths relative to distfiles directory (intended for offline
392 operations; does not work when Icon field is present
393 but icon file is absent),
a7eefc54 394-sf, --source-files - list sources - bare filenames (intended for offline
395 operations; does not work when Icon field is present
3621e588 396 but icon file is absent),
4ca1edbd
KK
397-lsp, --source-paths
398 - list sources - filenames with full local paths (intended for
a7eefc54 399 offline operations; does not work when Icon field is present
3621e588 400 but icon file is absent),
2dddf439
ER
401-su, --source-urls - list urls - urls to sources and patches
402 intended for copying urls with spec with lots of macros in urls
ccb03bc0
KK
403-T <tag> , --tag <tag>
404 - add git tag <tag> for files,
cd445739 405-Tvs, --tag-version-stable
ccb03bc0 406 - add git tags STABLE and NAME-VERSION-RELEASE for files,
cd445739 407-Ts, --tag-stable
ccb03bc0 408 - add git tag STABLE for files,
647fead0
ER
409-Tv,
410--tag-version - add git tag NAME-VERSION-RELEASE for files,
cd445739
AM
411-Tp, --tag-prefix <prefix>
412 - add <prefix> to NAME-VERSION-RELEASE tags,
413-tt, --test-tag <prefix>
414 - fail if tag is already present,
50321881
JK
415-ir, --integer-release-only
416 - allow only integer and snapshot releases
cd445739
AM
417-v, --verbose - be verbose,
418-u, --try-upgrade - check version, and try to upgrade package
419-un, --try-upgrade-with-float-version
420 - as above, but allow float version
4ca1edbd 421 php-pear-Services_Digg/
0907f1eb 422--upgrade-version - upgrade to specified version in try-upgrade
deccc50e 423-U, --update - refetch sources, don't use distfiles, and update md5 comments
cd445739
AM
424-Upi, --update-poldek-indexes
425 - refresh or make poldek package index files.
647fead0
ER
426-sp <patchnumber>,
427--skip-patch <patchnumber>
8bd5e66d 428 - don't apply <patchnumber>. may be repeated.
647fead0
ER
429-np <patchnumber>,
430--nopatch <patchnumber>
8bd5e66d 431 - abort instead of applying patch <patchnumber>
fc8edbe5
ER
432--noinit
433 - do not initialize SPECS_DIR and SOURCES_DIR (set them to .)
dfe2cb9a
MK
434--show-bconds - show available conditional builds, which can be used
435 - with --with and/or --without switches.
b05205af
BZ
436--show-bcond-args - show active bconds, from ~/.bcondrc. this is used by ./repackage.sh script.
437 In other words, the output is parseable by scripts.
24a97174 438--show-avail-bconds - show available bconds
647fead0
ER
439--with <feature>,
440--without <feature>
cd445739
AM
441 - conditional build package depending on %_with_<feature>/
442 %_without_<feature> macro switch. You may now use
443 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
444 constructions. Set GROUP_BCONDS to yes to make use of it.
6dd19291 445--target <platform>, --target=<platform>
a6494cd4
ER
446 - build for platform <platform>.
447--init-rpm-dir - initialize ~/rpm directory structure
5a491465 448"
449}
450
390d081d
ER
451# create tempfile. as secure as possible
452tempfile() {
ff5e57ba 453 mktemp --tmpdir -t builder.$PACKAGE_NAME.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
390d081d
ER
454}
455
397fa865 456tempdir() {
ff5e57ba 457 mktemp --tmpdir -d builder.$PACKAGE_NAME.XXXXXX
397fa865
KK
458}
459
8cc8f5c0
ER
460# inserts git log instead of %changelog
461# outputs name of modified file created by tempfile
462insert_gitlog() {
397fa865 463 local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
8cc8f5c0
ER
464
465 # allow this being customized
466 local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
467
468 # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
469 # otherwise i'd use --date=iso here
470 # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
b34dcd91 471 # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
8cc8f5c0
ER
472 # NOTE: changelog date is always in UTC for rpmbuild
473 # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
9fd1eb80 474 git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
f8704064 475 local logfmt='%B%n'
31f3bc1c
ER
476 git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
477 git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
9c0fe78c 478 done > $gitlog
9e269b3c
ER
479
480 # add link to full git logs
481 local giturl="http://git.pld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
482 if [ -n "$CVSTAG" ]; then
483 giturl="$giturl;h=$CVSTAG"
484 fi
485 local gitauthor="PLD Linux Team <feedback@pld-linux.org>"
486 LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
487 printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
488 print;
489 exit
490 }' > $speclog
491
492 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
493 sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
494 a%changelog
495 r $speclog
496 }
397fa865 497 " > $specdir/$SPECFILE
8cc8f5c0 498 rm -f $gitlog $speclog
397fa865 499 echo $specdir
8cc8f5c0
ER
500}
501
12da9e3d
ER
502# @param string logfile
503# @param varargs... commands to execute
504teeboth() {
505 local rc
506 # use teeboth from toys/cleanbuild, if available and enabled
507 if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
508 $APPDIR/teeboth "$@"
509 rc=$?
510 else
511 local efile rc logfile=$1; shift
512 if [ "$logfile" ]; then
513 efile=$(tempfile)
806a7b72 514 { "$@" 2>&1; echo $? > $efile; } | tee -a $logfile
12da9e3d
ER
515 rc=$(< $efile)
516 rm -f $efile
517 else
551a62ae 518 "$@"
12da9e3d
ER
519 rc=$?
520 fi
521 fi
522 return $rc
523}
524
31d2bd0b
ER
525# change dependency to specname
526# common changes:
527# - perl(Package::Name) -> perl-Package-Name
528depspecname() {
529 local package="$1"
530
560c4b1a 531 package=$(echo "$package" | sed -e '/perl(.*)/{s,perl(\(.*\)),perl-\1,;s,::,-,g};' -e 's/-\(devel\|static\)$//' )
31d2bd0b
ER
532 echo "$package"
533}
534
c890b916 535update_shell_title() {
a0d6396b 536 [ -t 1 ] || return
0b65d15e 537 local len=${COLUMNS:-80}
5c795f16 538 local msg="$(echo "$*" | cut -c-$len)"
0b65d15e 539
e225de91
ER
540 if [ -n "$BE_VERBOSE" ]; then
541 echo >&2 "$(date +%s.%N) $*"
542 fi
543
5c795f16 544 if [ "x$TITLECHANGE" = "xyes" -o "x$TITLECHANGE" = "x" ]; then
138bbc98
ER
545 local pkg
546 if [ -n "$PACKAGE_NAME" ]; then
547 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
548 else
549 pkg=${SPECFILE}
550 fi
551
552 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
a8c9a155 553 msg=$(echo $msg | tr -d '\n\r')
982e358c
MP
554 case "$TERM" in
555 cygwin|xterm*)
556 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
557 ;;
558 screen*)
559 echo >&2 -ne "\033]0;$msg\007"
560 ;;
561 esac
562 fi
c890b916
ER
563}
564
7e40520f
ER
565# set TARGET from BuildArch: from SPECFILE
566set_spec_target() {
ce40491a 567 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
8c91ee46 568 local tmp=$(awk '/^BuildArch:/ { print $NF; exit }' $ASSUMED_NAME/$SPECFILE)
ce40491a 569 if [ "$tmp" ]; then
8c91ee46 570 local target_platform=$(rpm -E '%{_target_vendor}-%{_target_os}%{?_gnu}')
7e40520f
ER
571 TARGET="$tmp"
572 case "$RPMBUILD" in
573 "rpmbuild")
f9109a96 574 TARGET_SWITCH="--target ${TARGET}-${target_platform}" ;;
7e40520f 575 "rpm")
ce40491a 576 TARGET_SWITCH="--target=$TARGET" ;;
7e40520f 577 esac
ce40491a
ER
578 fi
579 fi
7e40520f
ER
580}
581
ace3fd80
ER
582# runs rpm with minimal macroset
583minirpm() {
202b825e 584 safe_macrofiles=$(rpm $TARGET_SWITCH --showrc | awk -F: '/^macrofiles/ { gsub(/^macrofiles[ \t]+:/, "", $0); print $0 } ')
ace3fd80
ER
585
586 # TODO: move these to /usr/lib/rpm/macros
20117088 587 cat > $BUILDER_MACROS <<'EOF'
5b5e5f7f 588%x8664 x86_64 amd64 ia32e
f78a0bb7 589%alt_kernel %{nil}
590%_alt_kernel %{nil}
5ff15c97 591%bootstrap_release() %{1}
407b204b
ER
592%requires_releq_kernel_up(s:n:) %{nil}
593%requires_releq_kernel_smp(s:n:) %{nil}
594%requires_releq_kernel(s:n:) %{nil}
6b8134e3 595%requires_releq() %{nil}
bb01dee9 596%pyrequires_eq() %{nil}
559d511f 597%requires_eq() %{nil}
c13be3d1 598%requires_eq_to() %{nil}
99c05e13 599%requires_ge() %{nil}
500b0eb8
ER
600%requires_ge_to() %{nil}
601%requires_ge() %{nil}
407b204b
ER
602%releq_kernel_up(n:) ERROR
603%releq_kernel_smp(n:) ERROR
604%releq_kernel(n:) ERROR
e94e25f9 605%py_postclean(x:) ERROR
74d9fd14 606%kgcc_package ERROR
237bd3f1 607%_fontsdir ERROR
7141278d 608%ruby_version ERROR
609%ruby_ver_requires_eq() %{nil}
610%ruby_mod_ver_requires_eq() %{nil}
c13be3d1 611%__php_api_requires() %{nil}
7141278d 612%php_major_version ERROR
613%php_api_version ERROR
99f819cf
AM
614%requires_xorg_xserver_extension %{nil}
615%requires_xorg_xserver_xinput %{nil}
616%requires_xorg_xserver_font %{nil}
617%requires_xorg_xserver_videodrv %{nil}
7141278d 618%py_ver ERROR
41035426
ER
619%perl_vendorarch ERROR
620%perl_vendorlib ERROR
703ae20b
ER
621# damn. need it here! - copied from /usr/lib/rpm/macros.build
622%tmpdir %(echo "${TMPDIR:-/tmp}")
1f28fcb7
ER
623%patchset_source(f:b:) %(
624 base=%{-b*}%{!-b*:10000};
625 start=$(expr $base + %1);
626 end=$(expr $base + %{?2}%{!?2:%{1}});
627 # we need to call seq twice as it doesn't allow two formats
628 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
629 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
630 paste %{tmpdir}/__ps{1,2};
631 rm -f %{tmpdir}/__ps{1,2};
632) \
633%{nil}
991f09a5
ER
634%add_etc_shells(p) %{p:<lua>}
635%remove_etc_shells(p) %{p:<lua>}
709995c4
ER
636%lua_add_etc_shells() %{nil}
637%lua_remove_etc_shells() %{nil}
0ca65fa4
JK
638%required_jdk %{nil}
639%buildrequires_jdk %{nil}
f9063abe 640%pear_package_print_optionalpackages %{nil}
fb198857 641EOF
3d12d055 642 if [ "$NOINIT" = "yes" ] ; then
20117088 643 cat >> $BUILDER_MACROS <<'EOF'
3d12d055
JR
644%_specdir ./
645%_sourcedir ./
646EOF
c039643c 647 fi
670b1ed4 648 eval PATH=$CLEAN_PATH $RPMBUILD $TARGET_SWITCH --macros "$safe_macrofiles:$BUILDER_MACROS" $QUIET $RPMOPTS $RPMBUILDOPTS $BCOND $* 2>&1
ace3fd80
ER
649}
650
651cache_rpm_dump() {
652 if [ -n "$DEBUG" ]; then
653 set -x
654 set -v
655 fi
656
d1d24c14 657 if [ -x /usr/bin/rpm-specdump ]; then
525bf240 658 update_shell_title "cache_rpm_dump using rpm-specdump command"
646d81cf 659 rpm_dump_cache=$(rpm-specdump $TARGET_SWITCH $BCOND --define "_specdir $PACKAGE_DIR" --define "_sourcedir $PACKAGE_DIR" $PACKAGE_DIR/$SPECFILE)
d1d24c14 660 else
525bf240 661 update_shell_title "cache_rpm_dump using rpmbuild command"
d1d24c14
ER
662 local rpm_dump
663 rpm_dump=`
664 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
665 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
666 case "$RPMBUILD" in
667 rpm)
668 ARGS='-bp'
669 ;;
670 rpmbuild)
671 ARGS='--nodigest --nosignature --nobuild'
672 ;;
673 esac
674 minirpm $ARGS --define "'prep $dump'" --nodeps $SPECFILE
675 `
676 if [ $? -gt 0 ]; then
677 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
678 echo "$error" >&2
679 Exit_error err_build_fail
680 fi
d05e8080 681
d1d24c14
ER
682 # make small dump cache
683 rpm_dump_cache=`echo "$rpm_dump" | awk '
684 $2 ~ /^SOURCEURL/ {print}
685 $2 ~ /^PATCHURL/ {print}
686 $2 ~ /^nosource/ {print}
687 $2 ~ /^PACKAGE_/ {print}
688 '`
689 fi
d05e8080 690
13974367 691 update_shell_title "cache_rpm_dump: OK!"
cd445739
AM
692}
693
ace3fd80 694rpm_dump() {
cd445739 695 if [ -z "$rpm_dump_cache" ] ; then
45e2a818 696 echo >&2 "internal error: cache_rpm_dump not called! (missing %prep?)"
cd445739
AM
697 fi
698 echo "$rpm_dump_cache"
699}
700
f6711e2a 701get_icons() {
d05e8080 702 update_shell_title "get icons"
9d99a240 703 ICONS=$(awk '/^Icon:/ {print $2}' $PACKAGE_DIR/${SPECFILE})
d05e8080
ER
704 if [ -z "$ICONS" ]; then
705 return
706 fi
707
975d7b23 708 rpm_dump_cache="kalasaba" NODIST="yes" get_files $ICONS
d05e8080
ER
709}
710
f6711e2a 711parse_spec() {
af4d5315 712 update_shell_title "parsing specfile"
cd445739 713 if [ -n "$DEBUG" ]; then
518ff1fb
ER
714 set -x
715 set -v
cd445739 716 fi
b2975fc3 717
d05e8080 718 # icons are needed for successful spec parse
518ff1fb 719 get_icons
d05e8080 720
9c909460 721 cd $PACKAGE_DIR
cd445739 722 cache_rpm_dump
00fcec7e 723
15e34b63 724 if rpm_dump | grep -qEi ":.*nosource.*1"; then
cd445739
AM
725 FAIL_IF_NO_SOURCES="no"
726 fi
727
7cbc2d88
ER
728 if [ "$NOSRCS" != "yes" ]; then
729 SOURCES=$(rpm_dump | awk '$2 ~ /^SOURCEURL[0-9]+/ {print substr($2, length("SOURCEURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
730 PATCHES=$(rpm_dump | awk '$2 ~ /^PATCHURL[0-9]+/ {print substr($2, length("PATCHURL") + 1), $3}' | LC_ALL=C sort -n | awk '{print $2}')
731 ICONS=$(awk '/^Icon:/ {print $2}' ${SPECFILE})
732 fi
733
dfe2b2d9
ER
734 PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3; exit}')
735 PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3; exit}')
736 PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3; exit}')
78eab2a1 737
0b4119a2 738 if [ "$PACKAGE_NAME" != "$ASSUMED_NAME" ]; then
7854d40c 739 echo >&2 "WARNING! Spec name ($ASSUMED_NAME) does not agree with package name ($PACKAGE_NAME)"
0b4119a2
JR
740 fi
741
cd445739
AM
742 if [ -n "$BE_VERBOSE" ]; then
743 echo "- Sources : `nourl $SOURCES`"
744 if [ -n "$PATCHES" ]; then
745 echo "- Patches : `nourl $PATCHES`"
746 else
747 echo "- Patches : *no patches needed*"
748 fi
749 if [ -n "$ICONS" ]; then
750 echo "- Icon : `nourl $ICONS`"
751 else
752 echo "- Icon : *no package icon*"
753 fi
754 echo "- Name : $PACKAGE_NAME"
755 echo "- Version : $PACKAGE_VERSION"
756 echo "- Release : $PACKAGE_RELEASE"
757 fi
13974367
ER
758
759 update_shell_title "parse_spec: OK!"
cd445739
AM
760}
761
f6711e2a 762Exit_error() {
cd445739 763 if [ -n "$DEBUG" ]; then
518ff1fb
ER
764 set -x
765 set -v
cd445739
AM
766 fi
767
768 cd "$__PWD"
769
770 case "$1" in
771 "err_no_spec_in_cmdl" )
772 remove_build_requires
45e2a818 773 echo >&2 "ERROR: spec file name not specified."
cd445739 774 exit 2 ;;
a08d92fc 775 "err_invalid_cmdline" )
45e2a818 776 echo >&2 "ERROR: invalid command line arg ($2)."
a08d92fc 777 exit 2 ;;
cd445739
AM
778 "err_no_spec_in_repo" )
779 remove_build_requires
bba21388 780 echo >&2 "Error: spec file not stored in PLD repo."
cd445739
AM
781 exit 3 ;;
782 "err_no_source_in_repo" )
783 remove_build_requires
bba21388 784 echo >&2 "Error: some source, patch or icon files not stored in PLD repo. ($2)"
cd445739 785 exit 4 ;;
703b6deb 786 "err_cvs_add_failed" )
bba21388 787 echo >&2 "Error: failed to add package to PLD repo."
703b6deb 788 exit 4 ;;
cd445739
AM
789 "err_build_fail" )
790 remove_build_requires
45e2a818 791 echo >&2 "Error: package build failed. (${2:-no more info})"
cd445739 792 exit 5 ;;
78eab2a1
AM
793 "err_no_package_data" )
794 remove_build_requires
45e2a818 795 echo >&2 "Error: couldn't get out package name/version/release from spec file."
78eab2a1 796 exit 6 ;;
ce40491a 797 "err_tag_exists" )
50321881 798 remove_build_requires
d2842af2 799 echo >&2 "Tag ${2} already exists"
50321881 800 exit 9 ;;
ce40491a 801 "err_fract_rel" )
50321881 802 remove_build_requires
45e2a818 803 echo >&2 "Release ${2} not integer and not a snapshot."
50321881 804 exit 10 ;;
fb96e0b5
AM
805 "err_branch_exists" )
806 remove_build_requires
45e2a818 807 echo >&2 "Tree branch already exists (${2})."
fb96e0b5 808 exit 11 ;;
cfc497c0
ER
809 "err_acl_deny" )
810 remove_build_requires
45e2a818 811 echo >&2 "Error: conditions reject building this spec (${2})."
cfc497c0 812 exit 12 ;;
406b9ecf
KK
813 "err_remote_problem" )
814 remove_build_requires
815 echo >&2 "Error: problem with remote (${2})"
816 exit 13 ;;
6217f407
KK
817 "err_no_checkut" )
818 echo >&2 "Error: cannot checkout $2"
819 exit 14 ;;
67963237 820 "err_not_implemented" )
779fcca4 821 remove_build_requires
67963237
KK
822 echo >&2 "Error: functionality not yet imlemented"
823 exit 110 ;;
cd445739 824 esac
45e2a818 825 echo >&2 "Unknown error."
73848362 826 exit 100
cd445739
AM
827}
828
f6711e2a 829init_builder() {
cd445739 830 if [ -n "$DEBUG" ]; then
518ff1fb
ER
831 set -x
832 set -v
0dd6320d 833 fi
cd445739 834
4aeb9973 835 if [ "$NOINIT" != "yes" ] ; then
9c909460 836 TOP_DIR=$(eval $RPM $RPMOPTS --eval '%{_topdir}')
b7cc0c94 837
09bf17c9 838 local macros_ver=$(rpm -E %?rpm_build_macros)
b7cc0c94
ER
839 if [ -z "$macros_ver" ]; then
840 REPO_DIR=$TOP_DIR/packages
841 PACKAGE_DIR=$TOP_DIR/packages/$ASSUMED_NAME
842 else
843 if awk "BEGIN{exit($macros_ver>=$RPM_MACROS_VER)}"; then
844 echo >&2 "builder requires rpm-build-macros >= $RPM_MACROS_VER"
845 exit 1
846 fi
847 REPO_DIR=$TOP_DIR
848 PACKAGE_DIR=$REPO_DIR/$ASSUMED_NAME
849 fi
29e90b02 850 else
5c41c44d
ER
851 PACKAGE_DIR=$(pwd)
852 REPO_DIR=$PACKAGE_DIR
29e90b02 853 fi
52f3ced3
KK
854 export GIT_WORK_TREE=$PACKAGE_DIR
855 export GIT_DIR=$PACKAGE_DIR/.git
cd445739 856
acd0d41d 857 if [ -d "$GIT_DIR" ] && [ -z "$CVSTAG" ] && git rev-parse --verify -q HEAD > /dev/null; then
a095de80
KK
858 if CVSTAG=$(GIT_DIR=$GIT_DIR git symbolic-ref HEAD) 2>/dev/null; then
859 CVSTAG=${CVSTAG#refs/heads/}
860 if [ "$CVSTAG" != "master" ]; then
861 echo >&2 "builder: Active branch $CVSTAG. Use -r BRANCHNAME to override"
862 fi
863 else
864 echo >&2 "On detached HEAD. Use -r BRANCHNAME to override"
865 HEAD_DETACHED="yes"
866 fi
867 elif [ "$CVSTAG" = "HEAD" ]; then
868 # assume -r HEAD is same as -A
869 CVSTAG="master"
870 fi
871
a8c9a155 872 __PWD=$(pwd)
00fcec7e 873}
874
406b9ecf
KK
875create_git_repo() {
876 update_shell_title "add_package"
877
878 if [ -n "$DEBUG" ]; then
879 set -x
880 set -v
881 fi
882
883 cd "$REPO_DIR"
884 SPECFILE=$(basename $SPECFILE)
885 if [ ! -f "$ASSUMED_NAME/$SPECFILE" ]; then
886 echo "ERROR: No package to add ($ASSUMED_NAME/$SPECFILE)" >&2
887 exit 101
888 fi
889 [ -d "$ASSUMED_NAME/.git" ] || NEW_REPO=yes
c6418b06 890 ssh $GIT_PUSH create ${ASSUMED_NAME} || Exit_error err_cvs_add_failed
406b9ecf 891 git init
eda17ab7
KK
892 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git && \
893 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME} \
894 || Exit_error err_remote_problem $REMOTE_PLD
406b9ecf
KK
895}
896
f6711e2a 897get_spec() {
c890b916 898
2e5be021 899 update_shell_title "get_spec"
c890b916 900
cd445739 901 if [ -n "$DEBUG" ]; then
518ff1fb
ER
902 set -x
903 set -v
cd445739
AM
904 fi
905
9c909460 906 cd "$REPO_DIR"
e0ddd96d 907 SPECFILE=$(basename $SPECFILE)
1ef6f5de 908 if [ "$NOCVSSPEC" != "yes" ]; then
3189511a 909 if [ -z "$DEPTH" ]; then
30419e36 910 if [ -d "$PACKAGE_DIR/.git" ]; then
608c01a7 911 git fetch $REMOTE_PLD || Exit_error err_no_spec_in_repo
3189511a 912 elif [ "$ADD_PACKAGE_CVS" = "yes" ]; then
30419e36
ER
913 if [ ! -r "$PACKAGE_DIR/$SPECFILE" ]; then
914 echo "ERROR: No package to add ($PACKAGE_DIR/$SPECFILE)" >&2
3189511a
KK
915 exit 101
916 fi
917 Exit_error err_not_implemented
918 else
919 (
920 unset GIT_WORK_TREE
eda17ab7 921 git clone -o $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git || {
588cb3a9 922 # softfail if new package, i.e not yet added to PLD rep
30419e36 923 [ ! -f "$PACKAGE_DIR/$SPECFILE" ] && Exit_error err_no_spec_in_repo
3189511a
KK
924 echo "Warning: package not in CVS - assuming new package"
925 NOCVSSPEC="yes"
926 }
dd30f9c8 927 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
eda17ab7 928 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
3189511a 929 )
703b6deb 930 fi
9c909460 931 else
30419e36
ER
932 if [ ! -d "$PACKAGE_DIR/.git" ]; then
933 if [ ! -d "$PACKAGE_DIR" ]; then
934 install -d $PACKAGE_DIR
3189511a
KK
935 fi
936 git init
a153a767 937 git remote add $REMOTE_PLD ${GIT_SERVER}/${PACKAGES_DIR}/${ASSUMED_NAME}.git
dd30f9c8 938 git config --local --add "remote.$REMOTE_PLD.fetch" 'refs/notes/*:refs/notes/*'
48184c96 939 git remote set-url --push $REMOTE_PLD ssh://${GIT_PUSH}/${PACKAGES_DIR}/${ASSUMED_NAME}
6a9f8358 940 CVSTAG=${CVSTAG:-"master"}
3189511a 941 fi
3f79cb18
KK
942 local refs=''
943 if [ -z "$ALL_BRANCHES" ]; then
944 refs="${CVSTAG}:remotes/${REMOTE_PLD}/${CVSTAG}"
945 fi
946 git fetch $DEPTH $REMOTE_PLD $refs || {
3189511a
KK
947 echo >&2 "Error: branch $CVSTAG does not exist"
948 exit 3
949 }
703b6deb 950 fi
f343238b 951 git fetch $REMOTE_PLD 'refs/notes/*:refs/notes/*'
0c3beb90 952
0d494abd 953 cvsignore_df .gitignore
703b6deb 954
588cb3a9 955 # add default log format to .gitignore if it is relative to package dir
703b6deb
ER
956 if [ -n "$LOGFILE" -a "$LOGFILE" = "${LOGFILE##*/}" ]; then
957 # substitute known "macros" to glob
52aad137 958 local logfile=$(echo "$LOGFILE" | sed -e 's,\$\(PACKAGE_NAME\|DATE\|TARGET\),*,g')
703b6deb
ER
959 if [ "$logfile" ]; then
960 cvsignore_df "$logfile"
daeab113 961 fi
9c909460 962 fi
703b6deb
ER
963
964 # create symlinks for tools
30419e36 965 if [ "$SYMLINK_TOOLS" != "no" -a -d "$PACKAGE_DIR" ]; then
2a8bedf9 966 for a in dropin md5 adapter builder {relup,compile,repackage,rsync,pearize}.sh pldnotify.awk; do
046b715f 967 # skip tools that don't exist in top dir
703b6deb 968 [ -f $a ] || continue
046b715f 969 # skip tools that already exist
30419e36
ER
970 [ -f $PACKAGE_DIR/$a ] && continue
971 ln -s ../$a $PACKAGE_DIR
703b6deb
ER
972 cvsignore_df $a
973 done
974 fi
cd445739 975 fi
049ab214 976
b0121b45 977 if [ -n "$CVSTAG" ]; then
6217f407
KK
978 if git rev-parse --verify -q "$CVSTAG"; then
979 git checkout "$CVSTAG" --
980 elif git rev-parse --verify -q "refs/remotes/${REMOTE_PLD}/$CVSTAG"; then
981 git checkout -t "refs/remotes/${REMOTE_PLD}/$CVSTAG" > /dev/null
982 fi
983 if [ $(git rev-parse "$CVSTAG") != $(git rev-parse HEAD) ]; then
984 Exit_error "err_no_checkut" "$CVSTAG"
985 fi
ef4c7d3d 986 git merge --ff-only '@{u}'
2226518e 987 git symbolic-ref -q HEAD > /dev/null && [ "$NOCVSSPEC" != "yes" ] &&
52020f4c 988 if [ -n "$CVSDATE" ]; then
c4c0f339
KK
989 git checkout $(git rev-list -n1 --before="'$CVSDATE'" $CVSTAG) || exit 1
990 fi
b0121b45
KK
991 fi
992
30419e36 993 if [ ! -f "$PACKAGE_DIR/$SPECFILE" ]; then
518ff1fb 994 Exit_error err_no_spec_in_repo
cd445739
AM
995 fi
996
997 if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then
30419e36 998 chmod $CHMOD_MODE $PACKAGE_DIR/$SPECFILE
cd445739
AM
999 fi
1000 unset OPTIONS
30419e36 1001 [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $PACKAGE_DIR/$SPECFILE
7e40520f 1002
ce40491a 1003 set_spec_target
cd445739
AM
1004}
1005
f6711e2a 1006find_mirror() {
9c909460 1007 cd "$REPO_DIR"
782518da 1008 local url="$1"
3526abd9 1009 if [ ! -f "mirrors" ] ; then
b11920fb 1010 ln -s ../rpm-build-tools/mirrors .
cd445739
AM
1011 fi
1012
1013 IFS="|"
782518da
ER
1014 local origin mirror name rest ol prefix
1015 while read origin mirror name rest; do
1016 # skip comments and empty lines
2faa4c32 1017 if [ -z "$origin" ] || [ "${origin#\#}" != "$origin" ]; then
782518da
ER
1018 continue
1019 fi
a8c9a155
ER
1020 ol=$(echo -n "$origin" | wc -c)
1021 prefix=$(echo -n "$url" | head -c $ol)
cd445739 1022 if [ "$prefix" = "$origin" ] ; then
a8c9a155 1023 suffix=$(echo "$url" | cut -b $((ol+1))-)
cd445739
AM
1024 echo -n "$mirror$suffix"
1025 return 0
1026 fi
1027 done < mirrors
1028 echo "$url"
1029}
1030
e7e0d4ec 1031# Warning: unpredictable results if same URL used twice
f6711e2a 1032src_no() {
8510980a
AM
1033 local file="$1"
1034 # escape some regexp characters if part of file name
298e75e2 1035 file=$(echo "$file" | sed -e 's#\([\+\*\.\&\#\?]\)#\\\1#g')
9c909460 1036 cd $PACKAGE_DIR
cd445739 1037 rpm_dump | \
8510980a 1038 grep -E "(SOURCE|PATCH)URL[0-9]*[ ]*${file}""[ ]*$" | \
647e3d7f
KK
1039 sed -e 's/.*\(SOURCE\|PATCH\)URL\([0-9][0-9]*\).*/\1\2/' | \
1040 head -n 1 | tr OURCEATH ourceath | xargs
1471f6d6 1041}
1042
f6711e2a 1043src_md5() {
e7e0d4ec 1044 [ "$NO5" = "yes" ] && return
cd445739
AM
1045 no=$(src_no "$1")
1046 [ -z "$no" ] && return
9c909460 1047 cd $PACKAGE_DIR
e7e0d4ec
ER
1048 local md5
1049
edcaeac2
ER
1050 # use "sources" file from package dir, like vim
1051 if [ -f sources ]; then
1052 md5=$(grep -s -v '^#' sources | \
5fe6b5d9 1053 grep -E "[ *]$(basename "$1")([ ,]|\$)" | \
e7e0d4ec
ER
1054 sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \
1055 grep -E '^[0-9a-f]{32}$')
1056
1057 if [ "$md5" ]; then
1058 if [ $(echo "$md5" | wc -l) != 1 ] ; then
edcaeac2 1059 echo "$SPECFILE: more then one entry in sources for $1" 1>&2
e7e0d4ec
ER
1060 fi
1061 echo "$md5" | tail -n 1
1062 return
1063 fi
cd445739 1064 fi
e7e0d4ec 1065
32131a0e 1066 source_md5=$(grep -iE "^#[ ]*(No)?$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://')
e7e0d4ec
ER
1067 if [ -n "$source_md5" ]; then
1068 echo $source_md5
cd445739 1069 else
7805dcb4
PZ
1070 source_md5=`grep -i "BuildRequires:[ ]*digest(%SOURCE$no)[ ]*=" $SPECFILE | sed -e 's/.*=//'`
1071 if [ -n "$source_md5" ]; then
1072 echo $source_md5
1073 else
1074 # we have empty SourceX-md5, but it is still possible
1075 # that we have NoSourceX-md5 AND NoSource: X
647e3d7f 1076 nosource_md5=`grep -i "^#[ ]*No$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'`
7805dcb4
PZ
1077 if [ -n "$nosource_md5" -a -n "`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" ] ; then
1078 echo $nosource_md5
1079 fi
cd445739 1080 fi
cd445739
AM
1081 fi
1082}
1083
f6711e2a 1084distfiles_path() {
06541433
JR
1085 echo "by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")"
1086}
1087
f6711e2a 1088distfiles_url() {
06541433 1089 echo "$PROTOCOL$DISTFILES_SERVER/distfiles/$(distfiles_path "$1")"
cd445739
AM
1090}
1091
f6711e2a 1092distfiles_attic_url() {
06541433 1093 echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/$(distfiles_path "$1")"
cd445739
AM
1094}
1095
f6711e2a 1096good_md5() {
cd445739
AM
1097 md5=$(src_md5 "$1")
1098 [ "$md5" = "" ] || \
1099 [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ]
8ba5cdda
PG
1100}
1101
f6711e2a 1102good_size() {
a8c9a155 1103 size=$(find $(nourl "$1") -printf "%s" 2>/dev/null)
ce40491a 1104 [ -n "$size" -a "$size" -gt 0 ]
a4b50627
AF
1105}
1106
f6711e2a 1107cvsignore_df() {
947025e5 1108 if [ "$CVSIGNORE_DF" != "yes" ]; then
1109 return
1110 fi
0d494abd 1111 cvsignore=${PACKAGE_DIR}/.gitignore
7dc8d095
ER
1112
1113 # add only if not yet there
aa189b05 1114 if ! awk -vf="$1" -vc=1 '$0 == f { c = 0 } END { exit c }' $cvsignore 2>/dev/null; then
947025e5 1115 echo "$1" >> $cvsignore
1116 fi
1117}
1118
71f8e908 1119# returns true if "$1" is ftp, http or https protocol url
f6711e2a 1120is_url() {
71f8e908
ER
1121 case "$1" in
1122 ftp://*|http://*|https://*)
1123 return 0
1124 ;;
1125 esac
1126 return 1
1127}
1128
f6711e2a 1129update_md5() {
ecba6ad5
ER
1130 if [ $# -eq 0 ]; then
1131 return
1132 fi
1133
1134 update_shell_title "update md5"
1135 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1136 set -x
1137 set -v
ecba6ad5
ER
1138 fi
1139
9c909460 1140 cd "$PACKAGE_DIR"
ecba6ad5
ER
1141
1142 # pass 1: check files to be fetched
1143 local todo
1144 local need_files
1145 for i in "$@"; do
1146 local fp=$(nourl "$i")
1147 local srcno=$(src_no "$i")
6392b5fd
ER
1148 if [ -n "$ADD5" ]; then
1149 [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
647e3d7f 1150 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE && continue
9c909460 1151 grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE && continue
6392b5fd 1152 else
647e3d7f 1153 grep -qiE '^#[ ]*'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE || grep -qiE '^BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE || continue
ecba6ad5
ER
1154 fi
1155 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
1156 need_files="$need_files $i"
1157 fi
1158 done
1159
1160 # pass 1a: get needed files
1161 if [ "$need_files" ]; then
1162 get_files $need_files
1163 fi
1164
1165 # pass 2: proceed with md5 adding or updating
1166 for i in "$@"; do
1167 local fp=$(nourl "$i")
1168 local srcno=$(src_no "$i")
647e3d7f 1169 local md5=$(grep -iE '^#[ ]*(No)?'$srcno'-md5[ ]*:' $PACKAGE_DIR/$SPECFILE )
e19ad799 1170 if [ -z "$md5" ]; then
9c909460 1171 md5=$(grep -iE '^[ ]*BuildRequires:[ ]*digest[(]%SOURCE'$srcno'[)][ ]*=' $PACKAGE_DIR/$SPECFILE )
6c1b2e7d 1172 fi
71f8e908 1173 if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
647e3d7f 1174 local tag="# $srcno-md5:\t"
71f8e908 1175 if [[ "$md5" == *NoSource* ]]; then
6663e1f3 1176 tag="# No$srcno-md5:\t"
6c1b2e7d
PZ
1177 elif [ -n "$USEDIGEST" ]; then
1178 tag="BuildRequires:\tdigest(%SOURCE$srcno) = "
71f8e908 1179 fi
ecba6ad5 1180 md5=$(md5sum "$fp" | cut -f1 -d' ')
647e3d7f 1181 echo "Updating $srcno ($md5: $fp)."
ecba6ad5 1182 perl -i -ne '
647e3d7f
KK
1183 print unless (/^\s*#\s*(No)?'$srcno'-md5\s*:/i or /^\s*BuildRequires:\s*digest\(%SOURCE'$srcno'\)/i);
1184 print "'"$tag$md5"'\n" if /^'$srcno'\s*:\s+/i;
ecba6ad5 1185 ' \
9c909460 1186 $PACKAGE_DIR/$SPECFILE
ecba6ad5
ER
1187 fi
1188 done
1189}
1190
f6711e2a 1191check_md5() {
60499e54 1192 local bad
3fbff8b8
ER
1193 [ "$NO5" = "yes" ] && return
1194
ecba6ad5
ER
1195 update_shell_title "check md5"
1196
1197 for i in "$@"; do
60499e54
AM
1198 bad=0
1199 if ! good_md5 "$i"; then
1200 echo -n "MD5 sum mismatch."
1201 bad=1
1202 fi
1203 if ! good_size "$i"; then
1204 echo -n "0 sized file."
1205 bad=1
ecba6ad5
ER
1206 fi
1207
60499e54
AM
1208 if [ $bad -eq 1 ]; then
1209 echo " Use -U to refetch sources,"
1210 echo "or -5 to update md5 sums, if you're sure files are correct."
1211 Exit_error err_no_source_in_repo $i
1212 fi
ecba6ad5
ER
1213 done
1214}
1215
f6711e2a 1216get_files() {
7cb24972 1217 update_shell_title "get_files"
cd445739
AM
1218
1219 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1220 set -x
1221 set -v
cd445739
AM
1222 fi
1223
f09c0772 1224 if [ $# -gt 0 ]; then
9c909460 1225 cd "$PACKAGE_DIR"
cd445739 1226
f2e42a41 1227 local nc=0
e7fa3b9f 1228 local get_files_cvs=""
3815b69a 1229 for i in "$@"; do
f2e42a41 1230 nc=$((nc + 1))
dcebdffb 1231 local cvsup=0
3815b69a 1232 SHELL_TITLE_PREFIX="get_files[$nc/$#]"
f2e42a41 1233 update_shell_title "$i"
f09c0772 1234 local fp=`nourl "$i"`
ecba6ad5 1235 if [ "$SKIP_EXISTING_FILES" = "yes" ] && [ -f "$fp" ]; then
ce40491a 1236 continue
18e5347d 1237 fi
ecba6ad5 1238
cd445739 1239 FROM_DISTFILES=0
e7e0d4ec 1240 local srcmd5=$(src_md5 "$i")
ecba6ad5
ER
1241
1242 # we know if source/patch is present in cvs/distfiles
1243 # - has md5 (in distfiles)
1244 # - in cvs... ideas?
1245
1246 # CHECK: local file didn't exist or always cvs up (first) requested.
f09c0772 1247 if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
cd445739
AM
1248 if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then
1249 echo "Warning: no URL given for $i"
1250 fi
08908161 1251 target="$fp"
cd445739 1252
e7e0d4ec 1253 if [ -z "$NODIST" ] && [ -n "$srcmd5" ]; then
a4b50627 1254 if good_md5 "$i" && good_size "$i"; then
e7e0d4ec 1255 echo "$fp having proper md5sum already exists"
cd445739
AM
1256 continue
1257 fi
28b34560 1258
bc10f694 1259 # optionally prefer mirror over distfiles if there's mirror
28b34560 1260 # TODO: build url list and then try each url from the list
bc10f694 1261 if [ -n "$PREFMIRRORS" ] && [ -z "$NOMIRRORS" ] && im=$(find_mirror "$i") && [ "$im" != "$i" ]; then
28b34560
ER
1262 url="$im"
1263 else
1264 url=$(distfiles_url "$i")
1265 fi
1266
cd445739
AM
1267 url_attic=$(distfiles_attic_url "$i")
1268 FROM_DISTFILES=1
ecba6ad5
ER
1269 # is $url local file?
1270 if [[ "$url" = [./]* ]]; then
18a52930 1271 update_shell_title "${GETLOCAL%% *}: $url"
cd445739
AM
1272 ${GETLOCAL} $url $target
1273 else
9e9f8920
ER
1274 local uri=${url}
1275 # make shorter message for distfiles urls
1276 if [[ "$uri" = ${PROTOCOL}${DISTFILES_SERVER}* ]] || [[ "$uri" = ${PROTOCOL}${ATTICDISTFILES_SERVER}* ]]; then
1277 uri=${uri#${PROTOCOL}${DISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1278 uri=${uri#${PROTOCOL}${ATTICDISTFILES_SERVER}/distfiles/by-md5/?/?/*/}
1279 uri="df: $uri"
1280 fi
1281 update_shell_title "${GETURI%% *}: $uri"
ca2e6c31 1282 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 1283 if [ "`echo $url | grep -E 'ftp://'`" ]; then
18a52930 1284 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 1285 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739
AM
1286 fi
1287 fi
ecba6ad5
ER
1288
1289 # is it empty file?
1290 if [ ! -s "$target" ]; then
cd445739
AM
1291 rm -f "$target"
1292 if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then
18a52930 1293 update_shell_title "${GETLOCAL%% *}: $url_attic"
cd445739
AM
1294 ${GETLOCAL} $url_attic $target
1295 else
18a52930 1296 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 1297 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 1298 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
ce40491a 1299 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 1300 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739 1301 fi
1cd7fc57 1302 test -s "$target" || rm -f "$target"
cd445739
AM
1303 fi
1304 fi
ecba6ad5
ER
1305
1306 if [ -s "$target" ]; then
947025e5 1307 cvsignore_df $target
1308 else
cd445739
AM
1309 rm -f "$target"
1310 FROM_DISTFILES=0
1311 fi
cd445739
AM
1312 fi
1313
f09c0772 1314 if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then
cd445739 1315 if [ -z "$NOMIRRORS" ]; then
a8c9a155 1316 im=$(find_mirror "$i")
cd445739
AM
1317 else
1318 im="$i"
1319 fi
ce40491a 1320 update_shell_title "${GETURI%% *}: $im"
99b8f51f 1321 ${GETURI} ${OUTFILEOPT} "$target" "$im" || \
33da77c4 1322 if [ "`echo $im | grep -E 'ftp://'`" ]; then
ce40491a 1323 update_shell_title "${GETURI2%% *}: $im"
99b8f51f 1324 ${GETURI2} ${OUTFILEOPT} "$target" "$im"
7e365483 1325 fi
1cd7fc57 1326 test -s "$target" || rm -f "$target"
cd445739
AM
1327 fi
1328
dcebdffb
ER
1329 if [ "$cvsup" = 1 ]; then
1330 continue
1331 fi
1332
cd445739 1333 fi
ecba6ad5
ER
1334
1335 # the md5 check must be moved elsewhere as if we've called from update_md5 the md5 is wrong.
f09c0772 1336 if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then
b3b584c5 1337 Exit_error err_no_source_in_repo $i
cd445739 1338 fi
2a5f078d 1339
ecba6ad5 1340 # we check md5 here just only to refetch immediately
a4b50627 1341 if good_md5 "$i" && good_size "$i"; then
cd445739
AM
1342 :
1343 elif [ "$FROM_DISTFILES" = 1 ]; then
deccc50e 1344 # wrong md5 from distfiles: remove the file and try again
cd445739 1345 # but only once ...
deccc50e 1346 echo "MD5 sum mismatch. Trying full fetch."
cd445739
AM
1347 FROM_DISTFILES=2
1348 rm -f $target
18a52930 1349 update_shell_title "${GETURI%% *}: $url"
ca2e6c31 1350 ${GETURI} ${OUTFILEOPT} "$target" "$url" || \
33da77c4 1351 if [ "`echo $url | grep -E 'ftp://'`" ]; then
ce40491a 1352 update_shell_title "${GETURI2%% *}: $url"
ca2e6c31 1353 ${GETURI2} ${OUTFILEOPT} "$target" "$url"
cd445739 1354 fi
ecba6ad5 1355 if [ ! -s "$target" ]; then
cd445739 1356 rm -f "$target"
18a52930 1357 update_shell_title "${GETURI%% *}: $url_attic"
ca2e6c31 1358 ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \
33da77c4 1359 if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then
ce40491a 1360 update_shell_title "${GETURI2%% *}: $url_attic"
ca2e6c31 1361 ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic"
cd445739
AM
1362 fi
1363 fi
1364 test -s "$target" || rm -f "$target"
1365 fi
cd445739 1366 done
e7fa3b9f
ER
1367 SHELL_TITLE_PREFIX=""
1368
cd445739
AM
1369
1370 if [ "$CHMOD" = "yes" ]; then
a8c9a155 1371 CHMOD_FILES=$(nourl "$@")
cd445739
AM
1372 if [ -n "$CHMOD_FILES" ]; then
1373 chmod $CHMOD_MODE $CHMOD_FILES
1374 fi
1375 fi
cd445739
AM
1376 fi
1377}
1378
7605fe95 1379tag_exist() {
8b6d1795
KK
1380# If tag exists and points to other commit exit with error
1381# If it existsts and points to HEAD return 1
1382# If it doesn't exist return 0
f8bfce7d 1383 local _tag="$1"
8b6d1795 1384 local sha1=$(git rev-parse HEAD)
7605fe95
KK
1385 echo "Searching for tag $_tag..."
1386 if [ -n "$DEPTH" ]; then
8b6d1795 1387 local ref=$(git ls-remote $REMOTE_PLD "refs/tags/$_tag" | cut -c -40)
7605fe95 1388 else
7baf7b2f 1389 local ref=$(git show-ref -s "refs/tags/$_tag")
7605fe95 1390 fi
8b6d1795
KK
1391 [ -z "$ref" ] && return 0
1392 [ "$ref" = "$sha1" ] || Exit_error err_tag_exists "$_tag"
1393 return 1
7605fe95
KK
1394}
1395
cd445739 1396make_tagver() {
ce40491a 1397 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1398 set -x
1399 set -v
ce40491a 1400 fi
78eab2a1 1401
ce40491a
ER
1402 # Check whether first character of PACKAGE_NAME is legal for tag name
1403 if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then
1404 TAG_PREFIX=tag_
1405 fi
d712cc12
ER
1406
1407 # NOTE: CVS tags may must not contain the characters `$,.:;@'
8c043136 1408 TAGVER=$(echo $TAG_PREFIX$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE)
d712cc12 1409
8c043136 1410 # Remove @kernel.version_release from TAGVER because tagging sources
ce40491a 1411 # could occur with different kernel-headers than kernel-headers used at build time.
d712cc12
ER
1412 # besides, %{_kernel_ver_str} is not expanded.
1413
8c043136 1414 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1@%{_kernel_ver_str}
d712cc12
ER
1415 # TAGVER=auto-ac-madwifi-ng-0-0_20070225_1
1416
8c043136 1417 TAGVER=${TAGVER%@*}
ce40491a 1418 echo -n "$TAGVER"
cd445739
AM
1419}
1420
f6711e2a 1421tag_files() {
cd445739 1422 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1423 set -x
1424 set -v
cd445739
AM
1425 fi
1426
73ef63d8
ER
1427 echo "Version: $PACKAGE_VERSION"
1428 echo "Release: $PACKAGE_RELEASE"
cd445739 1429
c9100f10 1430 local _tag
73ef63d8 1431 if [ "$TAG_VERSION" = "yes" ]; then
c9100f10 1432 _tag=`make_tagver`
73ef63d8
ER
1433 fi
1434 if [ -n "$TAG" ]; then
c9100f10 1435 _tag="$TAG"
73ef63d8 1436 fi
c9100f10 1437 echo "tag: $_tag"
cd445739 1438
39dcc7de 1439 local OPTIONS="tag $CVS_FORCE"
cd445739 1440
9c909460 1441 cd "$PACKAGE_DIR"
03db3356 1442
ace99bc6
KK
1443 if tag_exist $_tag || [ -n "$CVS_FORCE" ]; then
1444 update_shell_title "tag sources: $_tag"
1445 git $OPTIONS $_tag || exit
1446 git push $CVS_FORCE $REMOTE_PLD tag $_tag || Exit_error err_remote_problem $REMOTE_PLD
1447 else
1448 echo "Tag $_tag already exists and points to the same commit"
1449 fi
cd445739
AM
1450}
1451
f6711e2a 1452branch_files() {
cd445739 1453 TAG=$1
f663f264 1454 echo "Git branch: $TAG"
518ff1fb 1455 shift
cd445739 1456
cd445739 1457 if [ -n "$DEBUG" ]; then
518ff1fb
ER
1458 set -x
1459 set -v
cd445739
AM
1460 fi
1461
f663f264 1462 local OPTIONS="branch $CVS_FORCE"
c10fa4fa 1463
9c909460 1464 cd "$PACKAGE_DIR"
f663f264 1465 git $OPTIONS $TAG || exit
cd445739
AM
1466}
1467
1468
3009b80d
ER
1469# this function should exit early if package can't be built for this arch
1470# this avoids unneccessary BR filling.
1471check_buildarch() {
1472 local out ret
13c3c336 1473 out=$(minirpm --short-circuit -bp --define "'prep exit 0'" --nodeps $SPECFILE 2>&1)
3009b80d
ER
1474 ret=$?
1475 if [ $ret -ne 0 ]; then
1476 echo >&2 "$out"
1477 exit $ret
1478 fi
1479}
1480
9d99a240
ER
1481# from relup.sh
1482set_release() {
1483 local specfile="$1"
1484 local rel="$2"
1485 local newrel="$3"
1486 sed -i -e "
1487 s/^\(%define[ \t]\+_\?rel[ \t]\+\)$rel\$/\1$newrel/
1488 s/^\(Release:[ \t]\+\)$rel\$/\1$newrel/
1489 " $specfile
1490}
1491
1492set_version() {
1493 local specfile="$1"
bc8502e6
ER
1494 local ver="$2" subver=$ver
1495 local newver="$3" newsubver=$newver
1496
1497 # try handling subver, everything that's not numeric-dotted in version
1498 if grep -Eq '%define\s+subver' $specfile; then
1499 subver=$(echo "$ver" | sed -re 's,^[0-9.]+,,')
1500 ver=${ver%$subver}
1501 newsubver=$(echo "$newver" | sed -re 's,^[0-9.]+,,')
1502 newver=${newver%$newsubver}
1503 fi
9d99a240
ER
1504 sed -i -e "
1505 s/^\(%define[ \t]\+_\?ver[ \t]\+\)$ver\$/\1$newver/
bc8502e6 1506 s/^\(%define[ \t]\+subver[ \t]\+\)$subver\$/\1$newsubver/
9d99a240
ER
1507 s/^\(Version:[ \t]\+\)$ver\$/\1$newver/
1508 " $specfile
1509}
1510
cacef28c 1511try_upgrade() {
cd445739 1512 if [ -n "$TRY_UPGRADE" ]; then
9d99a240 1513 local TNOTIFY TNEWVER TOLDVER
ce40491a 1514 update_shell_title "build_package: try_upgrade"
9d99a240 1515
cacef28c 1516 cd "$PACKAGE_DIR"
1517
0907f1eb
ER
1518 if [ "$UPGRADE_VERSION" ]; then
1519 TNEWVER=$UPGRADE_VERSION
cd445739 1520 else
0907f1eb
ER
1521 if [ -n "$FLOAT_VERSION" ]; then
1522 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE -n) || exit 1
1523 else
1524 TNOTIFY=$($APPDIR/pldnotify.awk ${BE_VERBOSE:+-vDEBUG=1} $SPECFILE) || exit 1
1525 fi
cd445739 1526
b9bef5ce
ER
1527 # pldnotify.awk does not set exit codes, but it has match for ERROR
1528 # in output which means so.
1529 if [[ "$TNOTIFY" = *ERROR* ]]; then
1530 echo >&2 "$TNOTIFY"
1531 exit 1
1532 fi
1533
0907f1eb
ER
1534 TNEWVER=$(echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }')
1535 fi
cd445739
AM
1536
1537 if [ -n "$TNEWVER" ]; then
1538 TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'`
9d99a240 1539 echo "New version found, updating spec file from $TOLDVER to version $TNEWVER"
257af81b
ER
1540 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
1541 cp -f $SPECFILE $SPECFILE.bak
1542 fi
cd445739 1543 chmod +w $SPECFILE
cacef28c 1544 set_release $SPECFILE $PACKAGE_RELEASE 1
9d99a240 1545 set_version $SPECFILE $PACKAGE_VERSION $TNEWVER
518ff1fb 1546 parse_spec
6decb793
ER
1547 if [ "$PACKAGE_VERSION" != "$TNEWVER" ]; then
1548 echo >&2 "Upgrading version failed, you need to update spec yourself"
1549 exit 1
1550 fi
cacef28c 1551 return 1
cd445739
AM
1552 fi
1553 fi
cacef28c 1554 return 0
1555}
1556
1557build_package() {
1558 update_shell_title "build_package"
1559 if [ -n "$DEBUG" ]; then
1560 set -x
1561 set -v
1562 fi
1563
9c909460 1564 cd "$PACKAGE_DIR"
2a5f078d 1565
cd445739
AM
1566 case "$COMMAND" in
1567 build )
1568 BUILD_SWITCH="-ba" ;;
1569 build-binary )
1570 BUILD_SWITCH="-bb" ;;
1571 build-source )
1572 BUILD_SWITCH="-bs --nodeps" ;;
1573 build-prep )
1574 BUILD_SWITCH="-bp --nodeps" ;;
6594293d
AG
1575 build-build )
1576 BUILD_SWITCH="-bc" ;;
1577 build-install )
1578 BUILD_SWITCH="-bi" ;;
1579 build-list )
1580 BUILD_SWITCH="-bl" ;;
1581
cd445739 1582 esac
c890b916 1583
2e5be021 1584 update_shell_title "build_package: $COMMAND"
12da9e3d 1585 local logfile retval
cd445739 1586 if [ -n "$LOGFILE" ]; then
12da9e3d
ER
1587 logfile=`eval echo $LOGFILE`
1588 if [ -d "$logfile" ]; then
1589 echo "Log file $logfile is a directory."
cd445739 1590 echo "Parse error in the spec?"
518ff1fb 1591 Exit_error err_build_fail
cd445739
AM
1592 fi
1593 if [ -n "$LASTLOG_FILE" ]; then
12da9e3d 1594 echo "LASTLOG=$logfile" > $LASTLOG_FILE
cd445739 1595 fi
12da9e3d
ER
1596 fi
1597
1598 local specdir=$(insert_gitlog $SPECFILE)
1599 # FIXME: eval here is exactly why?
1600 PATH=$CLEAN_PATH eval teeboth "'$logfile'" ${NICE_COMMAND} $RPMBUILD $TARGET_SWITCH $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $RPMBUILDOPTS $BCOND --define \'_specdir $PACKAGE_DIR\' --define \'_sourcedir $PACKAGE_DIR\' $specdir/$SPECFILE
1601 retval=$?
1602 rm -r $specdir
1603
1604 if [ -n "$logfile" ] && [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then
1605 if [ "$retval" -eq "0" ]; then
1606 mv $logfile $LOGDIROK
1607 else
1608 mv $logfile $LOGDIRFAIL
cd445739 1609 fi
8ba5cdda 1610 fi
12da9e3d
ER
1611
1612 if [ "$retval" -ne "0" ]; then
cd445739 1613 if [ -n "$TRY_UPGRADE" ]; then
cacef28c 1614 echo "\nUpgrade package to new version failed."
257af81b 1615 if [ "$REVERT_BROKEN_UPGRADE" = "yes" ]; then
cacef28c 1616 echo "Restoring old spec file."
257af81b
ER
1617 mv -f $SPECFILE.bak $SPECFILE
1618 fi
cacef28c 1619 echo ""
cd445739 1620 fi
518ff1fb 1621 Exit_error err_build_fail
cd445739
AM
1622 fi
1623 unset BUILD_SWITCH
1624}
1625
f6711e2a 1626nourl() {
cd445739
AM
1627 echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g'
1628}
1629
f6711e2a 1630install_required_packages() {
cd445739
AM
1631 run_poldek -vi $1
1632 return $?
1633}
1634
f6711e2a 1635find_spec_bcond() { # originally from /usr/lib/rpm/find-spec-bcond
fa4bf1df 1636 local SPEC="$1"
fa4bf1df
ER
1637 awk -F"\n" '
1638 /^%changelog/ { exit }
fa4bf1df
ER
1639 /^%bcond_with/{
1640 match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/);
8ff97f39
ER
1641 bcond = substr($0, RSTART + 6, RLENGTH - 6);
1642 gsub(/[ \t]+/, "_", bcond);
fa4bf1df
ER
1643 print bcond
1644 }' $SPEC | LC_ALL=C sort -u
1645}
1646
117d9861 1647process_bcondrc() {
301cbfd4
ER
1648 # expand bconds from ~/.bcondrc
1649 # The file structure is like gentoo's package.use:
1650 # ---
1651 # * -selinux
1652 # samba -mysql -pgsql
47a8df12 1653 # w32codec-installer license_agreement
301cbfd4
ER
1654 # php +mysqli
1655 # ---
15e34b63 1656 if [ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ]); then
117d9861
ER
1657 :
1658 else
1659 return
1660 fi
301cbfd4 1661
117d9861 1662 SN=${SPECFILE%%\.spec}
c8a3e2ac 1663
117d9861
ER
1664 local bcondrc=$HOME/.bcondrc
1665 [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc
301cbfd4 1666
117d9861 1667 local bcond_avail=$(find_spec_bcond $SPECFILE)
301cbfd4 1668
117d9861
ER
1669 while read pkg flags; do
1670 # ignore comments
1671 [[ "$pkg" == \#* ]] && continue
1672
1673 # any package or current package?
1674 if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then
1675 for flag in $flags; do
1676 local opt=${flag#[+-]}
1677
1678 # use only flags which are in this package.
1679 if [[ $bcond_avail = *${opt}* ]]; then
1680 if [[ $flag = -* ]]; then
1681 if [[ $BCOND != *--with?${opt}* ]]; then
1682 BCOND="$BCOND --without $opt"
1683 fi
1684 else
1685 if [[ $BCOND != *--without?${opt}* ]]; then
1686 BCOND="$BCOND --with $opt"
301cbfd4
ER
1687 fi
1688 fi
117d9861
ER
1689 fi
1690 done
1691 fi
1692 done < $bcondrc
1693 update_shell_title "parse ~/.bcondrc: DONE!"
1694}
1695
8ff97f39 1696set_bconds_values() {
117d9861
ER
1697 update_shell_title "set bcond values"
1698
1699 AVAIL_BCONDS_WITHOUT=""
1700 AVAIL_BCONDS_WITH=""
8ff97f39 1701
5a28189c 1702 if grep -Eq '^# *_with' ${SPECFILE}; then
8ff97f39
ER
1703 echo >&2 "ERROR: This spec has old style bconds."
1704 exit 1
1705 fi
1706
1707 if ! grep -q '^%bcond' ${SPECFILE}; then
117d9861 1708 return
301cbfd4
ER
1709 fi
1710
117d9861
ER
1711 local bcond_avail=$(find_spec_bcond $SPECFILE)
1712 process_bcondrc "$SPECFILE"
1713
fa4bf1df 1714 update_shell_title "parse bconds"
2a5f078d 1715
8ff97f39
ER
1716 local opt bcond
1717 for opt in $bcond_avail; do
1718 case "$opt" in
1719 without_*)
1720 bcond=${opt#without_}
10d92f71
ER
1721 case "$BCOND" in
1722 *--without?${bcond}*)
8ff97f39 1723 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$bcond>"
10d92f71
ER
1724 ;;
1725 *)
8ff97f39 1726 AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $bcond"
10d92f71
ER
1727 ;;
1728 esac
cd445739 1729 ;;
8ff97f39
ER
1730 with_*)
1731 bcond=${opt#with_}
10d92f71
ER
1732 case "$BCOND" in
1733 *--with?${bcond}*)
8ff97f39 1734 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$bcond>"
10d92f71
ER
1735 ;;
1736 *)
8ff97f39 1737 AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $bcond"
10d92f71
ER
1738 ;;
1739 esac
cd445739 1740 ;;
8ff97f39
ER
1741 *)
1742 echo >&2 "ERROR: unexpected '$opt' in set_bconds_values"
1743 exit 1
1744 ;;
1745 esac
1746 done
cd445739
AM
1747}
1748
f6711e2a 1749run_sub_builder() {
cd445739 1750 package_name="${1}"
af6b168f 1751 update_shell_title "run_sub_builder $package_name"
cd445739
AM
1752 #
1753