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