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