]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - builder.sh
- drop Icon:
[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
ebaff775 25v0.14 (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=""
64BCOND=""
65GROUP_BCONDS="no"
947025e5 66CVSIGNORE_DF="no"
d287305c 67
68PATCHES=""
69SOURCES=""
cd445739 70ICONS=""
d287305c 71PACKAGE_RELEASE=""
72PACKAGE_VERSION=""
73PACKAGE_NAME=""
cd445739
AM
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"
d4730dae 83ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org"
cd445739 84
36d03934 85DEF_NICE_LEVEL=19
cd445739
AM
86
87FAIL_IF_NO_SOURCES="yes"
88
18e5347d
ER
89# let get_files skip over files which are present to get those damn files fetched
90SKIP_EXISTING_FILES="no"
91
ab4a2b6e
ER
92if [ -x /usr/bin/rpm-getdeps ]; then
93 FETCH_BUILD_REQUIRES_RPMGETDEPS="yes"
94else
95 FETCH_BUILD_REQUIRES_RPMGETDEPS="no"
96fi
97
cd445739
AM
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#
a83e5405 115SU_SUDO=""
cd445739
AM
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
06f3864d
AM
124wget --help 2>&1 | grep -q ' \-\-no-check\-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate"
125
ca2e6c31 126if [ -n "$USE_PROZILLA" ]; then
7e365483
KK
127 GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS"
128 GETURI2="$GETURI"
129 OUTFILEOPT="-O"
ca2e6c31 130elif [ -n "$USE_AXEL" ]; then
cede92b3 131 GETURI="axel -a $AXEL_OPTS"
7e365483
KK
132 GETURI2="$GETURI"
133 OUTFILEOPT="-o"
ca2e6c31 134else
7e365483
KK
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"
6f9a5d76 137
7e365483
KK
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"
2bc5451f 141fi
11468b23 142
11468b23
AM
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`/"
a83e5405 154POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask"
11468b23 155
cd445739
AM
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
040282bb 164 (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG
cd445739
AM
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
cd445739
AM
173#---------------------------------------------
174# functions
da946cd6 175
5a491465 176usage()
177{
cd445739
AM
178 if [ -n "$DEBUG" ]; then set -xv; fi
179 echo "\
180Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build]
81f85806 181
cd445739
AM
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}]
dfe2cb9a 189[-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds]
f19103b5 190[--with/--without <feature>] [--define <macro> <value>] <package>[.spec][:cvstag]
2a5f078d 191
cd445739
AM
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
9243e80b
ER
195-D, --debug - enable builder script debugging mode,
196-debug - produce rpm debug package (same as --opts -debug)
cd445739
AM
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,
c56807e0
ER
203-bp, --build-prep - execute the %prep phase of <package>.spec,
204-bc - reserved (not implemented)
205-bi reserved (not implemented)
cd445739
AM
206-bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack
207 them into src.rpm,
c56807e0 208--short-circuit - reserved (not implemented)
cd445739
AM
209-B, --branch - add branch
210-c, --clean - clean all temporarily created files (in BUILD, SOURCES,
211 SPECS and \$RPM_BUILD_ROOT),
2a5f078d 212-d <cvsroot>, --cvsroot <cvsroot>
cd445739
AM
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
18e5347d
ER
234-ske,
235--skip-existing-files - skip existing files in get_files
cd445739
AM
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,
a7eefc54 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),
2dddf439
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
cd445739
AM
257-T <cvstag> , --tag <cvstag>
258 - add cvs tag <cvstag> for files,
259-Tvs, --tag-version-stable
094bd95b 260 - add cvs tags STABLE and NAME-VERSION-RELEASE for files,
cd445739 261-Tvn, --tag-version-nest
1691a37b 262 - add cvs tags NEST and NAME-VERSION-RELEASE for files,
cd445739
AM
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
1691a37b 268 - add cvs tag NAME-VERSION-RELEASE for files,
cd445739
AM
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,
50321881
JK
273-ir, --integer-release-only
274 - allow only integer and snapshot releases
cd445739
AM
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
deccc50e 279-U, --update - refetch sources, don't use distfiles, and update md5 comments
cd445739
AM
280-Upi, --update-poldek-indexes
281 - refresh or make poldek package index files.
c890b916 282-np, --nopatch <patchnumber>
bed98670 283 - don't apply <patchnumber>
dfe2cb9a
MK
284--show-bconds - show available conditional builds, which can be used
285 - with --with and/or --without switches.
cd445739
AM
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.
6dd19291 291--target <platform>, --target=<platform>
64ea5308 292 - build for platform <platform>.
5a491465 293"
294}
295
c890b916 296update_shell_title() {
a0d6396b 297 [ -t 1 ] || return
0b65d15e
ER
298 local len=${COLUMNS:-80}
299 local msg=$(echo "$*" | cut -c-$len)
300
e225de91
ER
301 if [ -n "$BE_VERBOSE" ]; then
302 echo >&2 "$(date +%s.%N) $*"
303 fi
304
f2e42a41 305 msg="builder[$SPECFILE] ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg"
c890b916
ER
306 case "$TERM" in
307 cygwin|xterm*)
2dddf439 308 echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007"
c890b916
ER
309 ;;
310 screen*)
2dddf439 311 echo >&2 -ne "\033]0;$msg\007"
c890b916
ER
312 ;;
313 esac
314}
315
7e40520f
ER
316# set TARGET from BuildArch: from SPECFILE
317set_spec_target() {
318 if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then
319 tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE)
320 if [ "$tmp" ]; then
321 TARGET="$tmp"
322 case "$RPMBUILD" in
323 "rpmbuild")
324 TARGET_SWITCH="--target $TARGET" ;;
325 "rpm")
326 TARGET_SWITCH="--target=$TARGET" ;;
327 esac
328 fi
329 fi
330}
331
cd445739 332cache_rpm_dump () {
b2aeec7d
AM
333 if [ -n "$DEBUG" ]; then
334 set -x;
335 set -v;
336 fi
7e40520f 337
13974367 338 update_shell_title "cache_rpm_dump"
d05e8080
ER
339 local rpm_dump=`
340
fa4bf1df
ER
341 # we reset macros not to contain macros.build as all the %() macros are
342 # executed here, while none of them are actually needed
343 # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES.
344 # macros.build + macros contained at the time of this writing 70 %() macros
7f41e74f 345 local macrofiles="/usr/lib/rpm/macros:$SPECS_DIR/.rpmmacros:~/etc/.rpmmacros:~/.rpmmacros"
ebaff775 346 local dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump'
7cb24972
ER
347 # FIXME: better ideas than .rpmrc?
348 printf 'include:/usr/lib/rpm/rpmrc\nmacrofiles:%s\n' $macrofiles > .rpmrc
fb198857
ER
349# TODO: move these to /usr/lib/rpm/macros
350 cat > .rpmmacros <<'EOF'
351%requires_releq_kernel_up %{nil}
352%requires_releq_kernel_smp %{nil}
bb01dee9 353%pyrequires_eq() %{nil}
fb198857
ER
354%releq_kernel_up ERROR
355%releq_kernel_smp ERROR
356EOF
cd445739
AM
357 case "$RPMBUILD" in
358 rpm )
7cb24972 359 rpm --rcfile .rpmrc -bp --nodeps --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1
cd445739
AM
360 ;;
361 rpmbuild )
c94b1395 362 rpmbuild --rcfile .rpmrc --nodigest --nodeps --nosignature --nobuild --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1
cd445739
AM
363 ;;
364 esac`
fb198857 365 if [ $? -gt 0 ]; then
d05e8080
ER
366 error=$(echo "$rpm_dump_cache" | sed -ne '/^error:/,$p')
367
368 # ignore error if it contains "Unable to open icon"
369 if [[ $error != *error:?Unable?to?open?icon* ]]; then
370 echo "$error" >&2
371 Exit_error err_build_fail;
372 fi
fb198857 373 fi
d05e8080
ER
374
375 # make small dump cache
376 rpm_dump_cache=`echo "$rpm_dump" | awk '
4e8c3089
ER
377 $2 ~ /^SOURCEURL/ {print}
378 $2 ~ /^PATCHURL/ {print}
379 $2 ~ /^nosource/ {print}
380 $2 ~ /^PACKAGE_/ {print}
d05e8080
ER
381 '`
382
13974367 383 update_shell_title "cache_rpm_dump: OK!"
cd445739
AM
384}
385
386rpm_dump () {
387 if [ -z "$rpm_dump_cache" ] ; then
388 echo "internal error: cache_rpm_dump not called!" 1>&2
389 fi
390 echo "$rpm_dump_cache"
391}
392
d05e8080
ER
393get_icons()
394{
395 update_shell_title "get icons"
396 ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
397 if [ -z "$ICONS" ]; then
398 return
399 fi
400
401