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