]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- use $RPMOPTS in cache_rpm_dump
[packages/rpm-build-tools.git] / builder.sh
CommitLineData
cd445739
AM
1#!/bin/sh
2# -----------
3# $Id$
4# Exit codes:
2a5f078d 5# 0 - succesful
6# 1 - help displayed
7# 2 - no spec file name in cmdl parameters
8# 3 - spec file not stored in repo
9# 4 - some source, patch or icon files not stored in repo
10# 5 - package build failed
11# 6 - spec file with errors
12# 7 - wrong source in /etc/poldek.conf
13# 8 - Failed installing buildrequirements and subrequirements
14# 9 - Requested tag already exist
15# 10 - Refused to build fractional release
16# 100 - Unknown error (should not happen)
cd445739
AM
17
18# Notes (todo):
f7b91886 19# - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?)
cd445739 20# - when Icon: field is present, -5 and -a5 doesn't work
f3ada241 21# - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice)
931a4acf 22
4003ad8c 23VERSION="\
c9acaed9 24Build package utility from PLD Linux CVS repository
cdb4a820 25v0.15 (C) 1999-2006 Free Penguins".
d6a77ddb 26PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
b03f053b 27
cd445739 28COMMAND="build"
64ea5308 29TARGET=""
cd445739 30
bde1c404 31SPECFILE=""
d287305c 32BE_VERBOSE=""
4003ad8c 33QUIET=""
cd445739
AM
34CLEAN=""
35DEBUG=""
36NOURLS=""
37NOCVS=""
38NOCVSSPEC=""
39NODIST=""
47761337 40NOINIT=""
cd445739
AM
41UPDATE=""
42UPDATE5=""
43ADD5=""
44NO5=""
45ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"}
c8f50498 46CVSROOT=""
cd445739
AM
47
48# It can be used i.e. in log file naming.
49# See LOGFILE example.
50DATE=`date +%Y-%m-%d_%H-%M-%S`
51
52# Example: LOGFILE='../log.$PACKAGE_NAME'
53# Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
54# Yes, you can use variable name! Note _single_ quotes!
55LOGFILE=''
56
57LOGDIR=""
58LOGDIROK=""
59LOGDIRFAIL=""
60LASTLOG_FILE=""
61
62CHMOD="no"
63CHMOD_MODE="0444"
64RPMOPTS=""
d1c5a9a7 65RPMBUILDOPTS=""
cd445739
AM
66BCOND=""
67GROUP_BCONDS="no"
947025e5 68CVSIGNORE_DF="no"
d287305c 69
70PATCHES=""
71SOURCES=""
cd445739 72ICONS=""
d287305c 73PACKAGE_RELEASE=""
74PACKAGE_VERSION=""
75PACKAGE_NAME=""
cd445739
AM
76PROTOCOL="ftp"
77WGET_RETRIES=${MAX_WGET_RETRIES:-0}
78CVS_RETRIES=${MAX_CVS_RETRIES:-1000}
79
80CVSTAG=""
81RES_FILE=""
82
83CVS_SERVER="cvs.pld-linux.org"
84DISTFILES_SERVER="://distfiles.pld-linux.org"
d4730dae 85ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
cd445739 86
36d03934 87DEF_NICE_LEVEL=19
86aafdbe 88SCHEDTOOL="auto"
cd445739
AM
89
90FAIL_IF_NO_SOURCES="yes"
91
18e5347d
ER
92# let get_files skip over files which are present to get those damn files fetched
93SKIP_EXISTING_FILES="no"
94
ab4a2b6e
ER
95if [ -x /usr/bin/rpm-getdeps ]; then
96 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
97else
98 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
99fi
100
cd445739
AM
101# Here we load saved user environment used to
102# predefine options set above, or passed to builder
103# in command line.
104# This one reads global system environment settings:
105if [ -f ~/etc/builderrc ]; then
106 . ~/etc/builderrc
107fi
108# And this one cascades settings using user personal
109# builder settings.
110# Example of ~/.builderrc:
111#
112#UPDATE_POLDEK_INDEXES="yes"
113#FETCH_BUILD_REQUIRES="yes"
114#REMOVE_BUILD_REQUIRES="force"
115#GROUP_BCONDS="yes"
116#LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE'
982e358c 117#TITLECHANGE=no
cd445739 118#
a83e5405 119SU_SUDO=""
cd445739
AM
120if [ -n "$HOME_ETC" ]; then
121 USER_CFG="$HOME_ETC/.builderrc"
122else
123 USER_CFG=~/.builderrc
124fi
125
126[ -f "$USER_CFG" ] && . "$USER_CFG"
127
06f3864d
AM
128wget --help 2>&1 | grep -q ' \-\-no-check\-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
129
86aafdbe
ER
130if [ "$SCHEDTOOL" = "auto" ]; then
131 if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then
132 SCHEDTOOL="schedtool -B -e"
133 else
134 SCHEDTOOL="no"
135 fi
136fi
137
ca2e6c31 138if [ -n "$USE_PROZILLA" ]; then
7e365483
KK
139 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
140 GETURI2="$GETURI"
141 OUTFILEOPT="-O"
ca2e6c31 142elif [ -n "$USE_AXEL" ]; then
cede92b3 143 GETURI="axel -a $AXEL_OPTS"
7e365483
KK
144 GETURI2="$GETURI"
145 OUTFILEOPT="-o"
ca2e6c31 146else
7e365483
KK
147 wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet"
148 wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused"
6f9a5d76 149
7e365483
KK
150 GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS"
151 GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS"
152 OUTFILEOPT="-O"
2bc5451f 153fi
11468b23 154
11468b23
AM
155GETLOCAL="cp -a"
156
157if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then
158 RPM="rpm"
159 RPMBUILD="rpm"
160else
161 RPM="rpm"
162 RPMBUILD="rpmbuild"
163fi
164
165POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/"
a83e5405 166POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
11468b23 167
cd445739
AM
168run_poldek()
169{
170 RES_FILE=~/tmp/poldek-exit-status.$RANDOM
171 if [ -n "$LOGFILE" ]; then
172 LOG=`eval echo $LOGFILE`
173 if [ -n "$LASTLOG_FILE" ]; then
174 echo "LASTLOG=$LOG" > $LASTLOG_FILE
175 fi
86aafdbe 176 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
cd445739
AM
177 return $exit_pldk
178 else
86aafdbe 179 (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null
cd445739
AM
180 return `cat ${RES_FILE}`
181 rm -rf ${RES_FILE}
182 fi
183}
184
cd445739
AM
185#---------------------------------------------
186# functions
da946cd6 187
5a491465 188usage()
189{
cd445739
AM
190 if [ -n "$DEBUG" ]; then set -xv; fi
191 echo "\
192Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
81f85806 193
cd445739
AM
194[-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade]
195[{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get]
196[-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper]
197[-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>]
198[-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest]
199[-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version]
200[{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}]
dfe2cb9a 201[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds]
f19103b5 202[--with/--without <feature>] [--define <macro> <value>] <package>[.spec][:cvstag]
2a5f078d 203
cd445739
AM
204-5, --update-md5 - update md5 comments in spec, implies -nd -ncs
205-a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs
206-n5, --no-md5 - ignore md5 comments in spec
9243e80b
ER
207-D, --debug - enable builder script debugging mode,
208-debug - produce rpm debug package (same as --opts -debug)
cd445739
AM
209-V, --version - output builder version
210-a, --as_anon - get files via pserver as cvs@$CVS_SERVER,
211-b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package
212 from <package>.spec,
213-bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary
214 only package from <package>.spec,
c56807e0
ER
215-bp, --build-prep - execute the %prep phase of <package>.spec,
216-bc - reserved (not implemented)
217-bi reserved (not implemented)
cd445739
AM
218-bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
219 them into src.rpm,
c56807e0 220--short-circuit - reserved (not implemented)
cd445739
AM
221-B, --branch - add branch
222-c, --clean - clean all temporarily created files (in BUILD, SOURCES,
223 SPECS and \$RPM_BUILD_ROOT),
2a5f078d 224-d <cvsroot>, --cvsroot <cvsroot>
cd445739
AM
225 - setup \$CVSROOT,
226--define <macro> <value>
227 - define a macro <macro> with value <value>,
228--nodeps - rpm won't check any dependences
229-g, --get - get <package>.spec and all related files from CVS repo
230 or HTTP/FTP,
231-h, --help - this message,
232--http - use http instead of ftp,
233-l <logfile>, --logtofile <logfile>
234 - log all to file,
235-m, --mr-proper - only remove all files related to spec file and all work
236 resources,
237-nc, --no-cvs - don't download sources from CVS, if source URL is given,
238-ncs, --no-cvs-specs
239 - don't check specs in CVS
240-nd, --no-distfiles - don't download from distfiles
241-nm, --no-mirrors - don't download from mirror, if source URL is given,
242-nu, --no-urls - don't try to download from FTP/HTTP location,
243-ns, --no-srcs - don't download Sources
244-ns0, --no-source0 - don't download Source0
245-nn, --no-net - don't download anything from the net
b572253e 246--no-init - don't initialize builder paths (SPECS and SOURCES)
18e5347d
ER
247-ske,
248--skip-existing-files - skip existing files in get_files
cd445739
AM
249--opts <rpm opts> - additional options for rpm
250-q, --quiet - be quiet,
251--date yyyy-mm-dd - build package using resources from specified CVS date,
252-r <cvstag>, --cvstag <cvstag>
253 - build package using resources from specified CVS tag,
254-R, --fetch-build-requires
255 - fetch what is BuildRequired,
256-RB, --remove-build-requires
257 - remove all you fetched with -R or --fetch-build-requires
258 remember, this option requires confirmation,
259-FRB, --force-remove-build-requires
260 - remove all you fetched with -R or --fetch-build-requires
261 remember, this option works without confirmation,
06541433
JR
262-sd, --source-distfiles - list sources available from distfiles (intended for offline
263 operations; does not work when Icon field is present
264 but icon file is absent),
265-sdp, --source-distfiles-paths - list sources available from distfiles -
266 paths relative to distfiles directory (intended for offline
267 operations; does not work when Icon field is present
268 but icon file is absent),
a7eefc54 269-sf, --source-files - list sources - bare filenames (intended for offline
270 operations; does not work when Icon field is present
3621e588 271 but icon file is absent),
a7eefc54 272-sp, --source-paths - list sources - filenames with full local paths (intended for
273 offline operations; does not work when Icon field is present
3621e588 274 but icon file is absent),
2dddf439
ER
275-su, --source-urls - list urls - urls to sources and patches
276 intended for copying urls with spec with lots of macros in urls
cd445739
AM
277-T <cvstag> , --tag <cvstag>
278 - add cvs tag <cvstag> for files,
279-Tvs, --tag-version-stable
094bd95b 280 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
cd445739 281-Tvn, --tag-version-nest
1691a37b 282 - add cvs tags NEST and NAME-VERSION-RELEASE for files,
cd445739
AM
283-Ts, --tag-stable
284 - add cvs tag STABLE for files,
285-Tn, --tag-nest
286 - add cvs tag NEST for files,
287-Tv, --tag-version
1691a37b 288 - add cvs tag NAME-VERSION-RELEASE for files,
cd445739
AM
289-Tp, --tag-prefix <prefix>
290 - add <prefix> to NAME-VERSION-RELEASE tags,
291-tt, --test-tag <prefix>
292 - fail if tag is already present,
50321881
JK
293-ir, --integer-release-only
294 - allow only integer and snapshot releases
cd445739
AM
295-v, --verbose - be verbose,
296-u, --try-upgrade - check version, and try to upgrade package
297-un, --try-upgrade-with-float-version
298 - as above, but allow float version
deccc50e 299-U, --update - refetch sources, don't use distfiles, and update md5 comments
cd445739
AM
300-Upi, --update-poldek-indexes
301 - refresh or make poldek package index files.
c890b916 302-np, --nopatch <patchnumber>
bed98670 303 - don't apply <patchnumber>
dfe2cb9a
MK
304--show-bconds - show available conditional builds, which can be used
305 - with --with and/or --without switches.
cd445739
AM
306--with/--without <feature>
307 - conditional build package depending on %_with_<feature>/
308 %_without_<feature> macro switch. You may now use
309 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
310 constructions. Set GROUP_BCONDS to yes to make use of it.
6dd19291 311--target <platform>, --target=<platform>
3621e588
ER
312 - build for platform <platform>.
313--init-rpm-dir - initialize ~/rpm directory structure
5a491465 314"
315}
316
c890b916 317update_shell_title() {
a0d6396b 318 [ -t 1 ] || return
0b65d15e
ER
319 local len=${COLUMNS:-80}
320 local msg=$(echo "$*" | cut -c-$len)
321
e225de91
ER
322 if [ -n "$BE_VERBOSE" ]; then
323 echo >&2 "$(date +%s.%N) $*"
324 fi
325
982e358c 326 if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then
138bbc98
ER
327 local pkg
328 if [ -n "$PACKAGE_NAME" ]; then
329 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
330 else
331 pkg=${SPECFILE}
332 fi
333
334 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
10c1e115 335 msg="$(echo $msg | tr -d '\n\r')"
982e358c
MP
336 case "$TERM" in
337 cygwin|xterm*)
338 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
339 ;;
340 screen*)
341 echo >&2 -ne "\033]0;$msg\007"
342 ;;
343 esac
344 fi
c890b916
ER
345}
346
7e40520f
ER
347# set TARGET from BuildArch: from SPECFILE
348set_spec_target() {
349 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
350 tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
351 if [ "$tmp" ]; then
352 TARGET="$tmp"
353 case "$RPMBUILD" in
354 "rpmbuild")
355 TARGET_SWITCH="--target $TARGET" ;;
356 "rpm")
357 TARGET_SWITCH="--target=$TARGET" ;;
358 esac
359 fi
360 fi
361}
362
cd445739 363cache_rpm_dump () {
b2aeec7d
AM
364 if [ -n "$DEBUG" ]; then
365 set -x;
366 set -v;
367 fi
7e40520f 368
13974367 369 update_shell_title "cache_rpm_dump"
237bd3f1
ER
370 local rpm_dump
371 rpm_dump=`
d05e8080 372
fa4bf1df 373 # we reset macros not to contain macros.build as all the %() macros are
559d511f 374 # executed here, while none of them are actually needed.
fa4bf1df 375 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
559d511f 376 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
36433112 377 macrofiles="/usr/lib/rpm/macros:$SPECS_DIR/.builder-rpmmacros:~/etc/.rpmmacros:~/.rpmmacros"
237bd3f1 378 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
7cb24972 379 # FIXME: better ideas than .rpmrc?
36433112 380 printf 'include:/usr/lib/rpm/rpmrc\nmacrofiles:%s\n' $macrofiles > .builder-rpmrc
fb198857 381# TODO: move these to /usr/lib/rpm/macros
36433112 382 cat > .builder-rpmmacros <<'EOF'
fb198857
ER
383%requires_releq_kernel_up %{nil}
384%requires_releq_kernel_smp %{nil}
6b8134e3 385%requires_releq() %{nil}
bb01dee9 386%pyrequires_eq() %{nil}
559d511f 387%requires_eq() %{nil}
c13be3d1 388%requires_eq_to() %{nil}
fb198857
ER
389%releq_kernel_up ERROR
390%releq_kernel_smp ERROR
74d9fd14 391%kgcc_package ERROR
237bd3f1 392%_fontsdir ERROR
7141278d 393%ruby_version ERROR
394%ruby_ver_requires_eq() %{nil}
395%ruby_mod_ver_requires_eq() %{nil}
c13be3d1 396%__php_api_requires() %{nil}
7141278d 397%php_major_version ERROR
398%php_api_version ERROR
399%py_ver ERROR
fb198857 400EOF
cd445739 401 case "$RPMBUILD" in
237bd3f1
ER
402 rpm)
403 ARGS='-bp'
404 ;;
405 rpmbuild)
406 ARGS='--nodigest --nosignature --nobuild'
407 ;;
408 esac
c4cae830 409 $RPMBUILD --rcfile .builder-rpmrc $ARGS --nodeps --define "prep $dump" $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE 2>&1
237bd3f1 410 `
fb198857 411 if [ $? -gt 0 ]; then
237bd3f1
ER
412 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
413 echo "$error" >&2
414 Exit_error err_build_fail;
fb198857 415 fi
d05e8080
ER
416
417 # make small dump cache
418 rpm_dump_cache=`echo "$rpm_dump" | awk '
4e8c3089
ER
419 $2 ~ /^SOURCEURL/ {print}
420 $2 ~ /^PATCHURL/ {print}
421 $2 ~ /^nosource/ {print}
422 $2 ~ /^PACKAGE_/ {print}
d05e8080
ER
423 '`
424
13974367 425 update_shell_title "cache_rpm_dump: OK!"
cd445739
AM
426}
427
428rpm_dump () {
429 if [ -z "$rpm_dump_cache" ] ; then
430 echo "internal error: cache_rpm_dump not called!" 1>&2
431 fi
432 echo "$rpm_dump_cache"
433}
434
d05e8080
ER
435get_icons()
436{
437 update_shell_title "get icons"
438 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
439 if [ -z "$ICONS" ]; then
440 return
441 fi
442
4f5cb659 443