]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- added -ni (--no-init) option to not initialize
[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
29e90b02 245-ni, --no-init - don't initialize builder paths (SPECS and SOURCES)
18e5347d
ER
246-ske,
247--skip-existing-files - skip existing files in get_files
cd445739
AM
248--opts <rpm opts> - additional options for rpm
249-q, --quiet - be quiet,
250--date yyyy-mm-dd - build package using resources from specified CVS date,
251-r <cvstag>, --cvstag <cvstag>
252 - build package using resources from specified CVS tag,
253-R, --fetch-build-requires
254 - fetch what is BuildRequired,
255-RB, --remove-build-requires
256 - remove all you fetched with -R or --fetch-build-requires
257 remember, this option requires confirmation,
258-FRB, --force-remove-build-requires
259 - remove all you fetched with -R or --fetch-build-requires
260 remember, this option works without confirmation,
06541433
JR
261-sd, --source-distfiles - list sources available from distfiles (intended for offline
262 operations; does not work when Icon field is present
263 but icon file is absent),
264-sdp, --source-distfiles-paths - list sources available from distfiles -
265 paths relative to distfiles directory (intended for offline
266 operations; does not work when Icon field is present
267 but icon file is absent),
a7eefc54 268-sf, --source-files - list sources - bare filenames (intended for offline
269 operations; does not work when Icon field is present
3621e588 270 but icon file is absent),
a7eefc54 271-sp, --source-paths - list sources - filenames with full local paths (intended for
272 offline operations; does not work when Icon field is present
3621e588 273 but icon file is absent),
2dddf439
ER
274-su, --source-urls - list urls - urls to sources and patches
275 intended for copying urls with spec with lots of macros in urls
cd445739
AM
276-T <cvstag> , --tag <cvstag>
277 - add cvs tag <cvstag> for files,
278-Tvs, --tag-version-stable
094bd95b 279 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
cd445739 280-Tvn, --tag-version-nest
1691a37b 281 - add cvs tags NEST and NAME-VERSION-RELEASE for files,
cd445739
AM
282-Ts, --tag-stable
283 - add cvs tag STABLE for files,
284-Tn, --tag-nest
285 - add cvs tag NEST for files,
286-Tv, --tag-version
1691a37b 287 - add cvs tag NAME-VERSION-RELEASE for files,
cd445739
AM
288-Tp, --tag-prefix <prefix>
289 - add <prefix> to NAME-VERSION-RELEASE tags,
290-tt, --test-tag <prefix>
291 - fail if tag is already present,
50321881
JK
292-ir, --integer-release-only
293 - allow only integer and snapshot releases
cd445739
AM
294-v, --verbose - be verbose,
295-u, --try-upgrade - check version, and try to upgrade package
296-un, --try-upgrade-with-float-version
297 - as above, but allow float version
deccc50e 298-U, --update - refetch sources, don't use distfiles, and update md5 comments
cd445739
AM
299-Upi, --update-poldek-indexes
300 - refresh or make poldek package index files.
c890b916 301-np, --nopatch <patchnumber>
bed98670 302 - don't apply <patchnumber>
dfe2cb9a
MK
303--show-bconds - show available conditional builds, which can be used
304 - with --with and/or --without switches.
cd445739
AM
305--with/--without <feature>
306 - conditional build package depending on %_with_<feature>/
307 %_without_<feature> macro switch. You may now use
308 --with feat1 feat2 feat3 --without feat4 feat5 --with feat6
309 constructions. Set GROUP_BCONDS to yes to make use of it.
6dd19291 310--target <platform>, --target=<platform>
3621e588
ER
311 - build for platform <platform>.
312--init-rpm-dir - initialize ~/rpm directory structure
5a491465 313"
314}
315
c890b916 316update_shell_title() {
a0d6396b 317 [ -t 1 ] || return
0b65d15e
ER
318 local len=${COLUMNS:-80}
319 local msg=$(echo "$*" | cut -c-$len)
320
e225de91
ER
321 if [ -n "$BE_VERBOSE" ]; then
322 echo >&2 "$(date +%s.%N) $*"
323 fi
324
982e358c 325 if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then
138bbc98
ER
326 local pkg
327 if [ -n "$PACKAGE_NAME" ]; then
328 pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}
329 else
330 pkg=${SPECFILE}
331 fi
332
333 msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
982e358c
MP
334 case "$TERM" in
335 cygwin|xterm*)
336 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
337 ;;
338 screen*)
339 echo >&2 -ne "\033]0;$msg\007"
340 ;;
341 esac
342 fi
c890b916
ER
343}
344
7e40520f
ER
345# set TARGET from BuildArch: from SPECFILE
346set_spec_target() {
347 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
348 tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
349 if [ "$tmp" ]; then
350 TARGET="$tmp"
351 case "$RPMBUILD" in
352 "rpmbuild")
353 TARGET_SWITCH="--target $TARGET" ;;
354 "rpm")
355 TARGET_SWITCH="--target=$TARGET" ;;
356 esac
357 fi
358 fi
359}
360
cd445739 361cache_rpm_dump () {
b2aeec7d
AM
362 if [ -n "$DEBUG" ]; then
363 set -x;
364 set -v;
365 fi
7e40520f 366
13974367 367 update_shell_title "cache_rpm_dump"
237bd3f1
ER
368 local rpm_dump
369 rpm_dump=`
d05e8080 370
fa4bf1df 371 # we reset macros not to contain macros.build as all the %() macros are
559d511f 372 # executed here, while none of them are actually needed.
fa4bf1df 373 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
559d511f 374 # at the time of this writing macros.build + macros contained 70 "%(...)" macros.
36433112 375 macrofiles="/usr/lib/rpm/macros:$SPECS_DIR/.builder-rpmmacros:~/etc/.rpmmacros:~/.rpmmacros"
237bd3f1 376 dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
7cb24972 377 # FIXME: better ideas than .rpmrc?
36433112 378 printf 'include:/usr/lib/rpm/rpmrc\nmacrofiles:%s\n' $macrofiles > .builder-rpmrc
fb198857 379# TODO: move these to /usr/lib/rpm/macros
36433112 380 cat > .builder-rpmmacros <<'EOF'
fb198857
ER
381%requires_releq_kernel_up %{nil}
382%requires_releq_kernel_smp %{nil}
6b8134e3 383%requires_releq() %{nil}
bb01dee9 384%pyrequires_eq() %{nil}
559d511f 385%requires_eq() %{nil}
c13be3d1 386%requires_eq_to() %{nil}
fb198857
ER
387%releq_kernel_up ERROR
388%releq_kernel_smp ERROR
74d9fd14 389%kgcc_package ERROR
237bd3f1 390%_fontsdir ERROR
7141278d 391%ruby_version ERROR
392%ruby_ver_requires_eq() %{nil}
393%ruby_mod_ver_requires_eq() %{nil}
c13be3d1 394%__php_api_requires() %{nil}
7141278d 395%php_major_version ERROR
396%php_api_version ERROR
397%py_ver ERROR
fb198857 398EOF
cd445739 399 case "$RPMBUILD" in
237bd3f1
ER
400 rpm)
401 ARGS='-bp'
402 ;;
403 rpmbuild)
404 ARGS='--nodigest --nosignature --nobuild'
405 ;;
406 esac
36433112 407 $RPMBUILD --rcfile .builder-rpmrc $ARGS --nodeps --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1
237bd3f1 408 `
fb198857 409 if [ $? -gt 0 ]; then
237bd3f1
ER
410 error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p')
411 echo "$error" >&2
412 Exit_error err_build_fail;
fb198857 413 fi
d05e8080
ER
414
415 # make small dump cache
416 rpm_dump_cache=`echo "$rpm_dump" | awk '
4e8c3089
ER
417 $2 ~ /^SOURCEURL/ {print}
418 $2 ~ /^PATCHURL/ {print}
419 $2 ~ /^nosource/ {print}
420 $2 ~ /^PACKAGE_/ {print}
d05e8080
ER
421 '`
422
13974367 423 update_shell_title "cache_rpm_dump: OK!"
cd445739
AM
424}
425
426rpm_dump () {
427 if [ -z "$rpm_dump_cache" ] ; then
428 echo "internal error: cache_rpm_dump not called!" 1>&2
429 fi
430 echo "$rpm_dump_cache"
431}
432
d05e8080
ER
433get_icons()
434{
435 update_shell_title "get icons"
436 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
437 if [ -z "$ICONS" ]; then
438 return
439 fi
440
29e90b02 441