]>
Commit | Line | Data |
---|---|---|
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): | |
19 | # - builder -u fetches current version first | |
20 | # - tries to get new version from distfiles without new md5 | |
21 | # - after fetching new version doesn't update md5 | |
22 | # - doesn't get sources for specs with %include /usr/lib/rpm/macros.python | |
23 | # when there's no rpm-pythonprov (rpm's fault, but it's ugly anyway) | |
24 | # - as above with %include /usr/lib/rpm/macros.perl and no rpm-perlprov | |
25 | # - when Icon: field is present, -5 and -a5 doesn't work | |
931a4acf | 26 | |
4003ad8c | 27 | VERSION="\ |
28 | Build package utility from PLD CVS repository | |
7304d35c | 29 | V 0.13 (C) 1999-2005 Free Penguins". |
d6a77ddb | 30 | PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin" |
b03f053b | 31 | |
cd445739 | 32 | COMMAND="build" |
64ea5308 | 33 | TARGET="" |
cd445739 | 34 | |
bde1c404 | 35 | SPECFILE="" |
d287305c | 36 | BE_VERBOSE="" |
4003ad8c | 37 | QUIET="" |
cd445739 AM |
38 | CLEAN="" |
39 | DEBUG="" | |
40 | NOURLS="" | |
41 | NOCVS="" | |
42 | NOCVSSPEC="" | |
43 | NODIST="" | |
44 | UPDATE="" | |
45 | UPDATE5="" | |
46 | ADD5="" | |
47 | NO5="" | |
f5985980 | 48 | ADAPTERIZE="" |
cd445739 | 49 | ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"} |
c8f50498 | 50 | CVSROOT="" |
cd445739 AM |
51 | |
52 | # It can be used i.e. in log file naming. | |
53 | # See LOGFILE example. | |
54 | DATE=`date +%Y-%m-%d_%H-%M-%S` | |
55 | ||
56 | # Example: LOGFILE='../log.$PACKAGE_NAME' | |
57 | # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE' | |
58 | # Yes, you can use variable name! Note _single_ quotes! | |
59 | LOGFILE='' | |
60 | ||
61 | LOGDIR="" | |
62 | LOGDIROK="" | |
63 | LOGDIRFAIL="" | |
64 | LASTLOG_FILE="" | |
65 | ||
66 | CHMOD="no" | |
67 | CHMOD_MODE="0444" | |
68 | RPMOPTS="" | |
69 | BCOND="" | |
70 | GROUP_BCONDS="no" | |
947025e5 | 71 | CVSIGNORE_DF="no" |
d287305c | 72 | |
73 | PATCHES="" | |
74 | SOURCES="" | |
cd445739 | 75 | ICONS="" |
d287305c | 76 | PACKAGE_RELEASE="" |
77 | PACKAGE_VERSION="" | |
78 | PACKAGE_NAME="" | |
cd445739 AM |
79 | PROTOCOL="ftp" |
80 | WGET_RETRIES=${MAX_WGET_RETRIES:-0} | |
81 | CVS_RETRIES=${MAX_CVS_RETRIES:-1000} | |
82 | ||
83 | CVSTAG="" | |
84 | RES_FILE="" | |
85 | ||
86 | CVS_SERVER="cvs.pld-linux.org" | |
87 | DISTFILES_SERVER="://distfiles.pld-linux.org" | |
d4730dae | 88 | ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org" |
cd445739 | 89 | |
36d03934 | 90 | DEF_NICE_LEVEL=19 |
cd445739 AM |
91 | |
92 | FAIL_IF_NO_SOURCES="yes" | |
93 | ||
ab4a2b6e ER |
94 | if [ -x /usr/bin/rpm-getdeps ]; then |
95 | FETCH_BUILD_REQUIRES_RPMGETDEPS="yes" | |
96 | else | |
97 | FETCH_BUILD_REQUIRES_RPMGETDEPS="no" | |
98 | fi | |
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: | |
104 | if [ -f ~/etc/builderrc ]; then | |
105 | . ~/etc/builderrc | |
106 | fi | |
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' | |
116 | # | |
a83e5405 | 117 | SU_SUDO="" |
cd445739 AM |
118 | if [ -n "$HOME_ETC" ]; then |
119 | USER_CFG="$HOME_ETC/.builderrc" | |
120 | else | |
121 | USER_CFG=~/.builderrc | |
122 | fi | |
123 | ||
124 | [ -f "$USER_CFG" ] && . "$USER_CFG" | |
125 | ||
06f3864d AM |
126 | wget --help 2>&1 | grep -q ' \-\-no-check\-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate" |
127 | ||
ca2e6c31 | 128 | if [ -n "$USE_PROZILLA" ]; then |
7e365483 KK |
129 | GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS" |
130 | GETURI2="$GETURI" | |
131 | OUTFILEOPT="-O" | |
ca2e6c31 | 132 | elif [ -n "$USE_AXEL" ]; then |
cede92b3 | 133 | GETURI="axel -a $AXEL_OPTS" |
7e365483 KK |
134 | GETURI2="$GETURI" |
135 | OUTFILEOPT="-o" | |
ca2e6c31 | 136 | else |
7e365483 KK |
137 | wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet" |
138 | wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused" | |
6f9a5d76 | 139 | |
7e365483 KK |
140 | GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS" |
141 | GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS" | |
142 | OUTFILEOPT="-O" | |
2bc5451f | 143 | fi |
11468b23 | 144 | |
11468b23 AM |
145 | GETLOCAL="cp -a" |
146 | ||
147 | if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then | |
148 | RPM="rpm" | |
149 | RPMBUILD="rpm" | |
150 | else | |
151 | RPM="rpm" | |
152 | RPMBUILD="rpmbuild" | |
153 | fi | |
154 | ||
155 | POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/" | |
a83e5405 | 156 | POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask" |
11468b23 | 157 | |
cd445739 AM |
158 | run_poldek() |
159 | { | |
160 | RES_FILE=~/tmp/poldek-exit-status.$RANDOM | |
161 | if [ -n "$LOGFILE" ]; then | |
162 | LOG=`eval echo $LOGFILE` | |
163 | if [ -n "$LASTLOG_FILE" ]; then | |
164 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
165 | fi | |
040282bb | 166 | (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG |
cd445739 AM |
167 | return $exit_pldk |
168 | else | |
169 | (nice -n ${DEF_NICE_LEVEL} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null | |
170 | return `cat ${RES_FILE}` | |
171 | rm -rf ${RES_FILE} | |
172 | fi | |
173 | } | |
174 | ||
cd445739 AM |
175 | #--------------------------------------------- |
176 | # functions | |
da946cd6 | 177 | |
5a491465 | 178 | usage() |
179 | { | |
cd445739 AM |
180 | if [ -n "$DEBUG" ]; then set -xv; fi |
181 | echo "\ | |
182 | Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build] | |
81f85806 | 183 | |
cd445739 AM |
184 | [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade] |
185 | [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get] | |
186 | [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper] | |
187 | [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>] | |
188 | [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest] | |
189 | [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version] | |
190 | [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] | |
191 | [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] | |
192 | [--with/--without <feature>] [--define <macro> <value>] <package>[.spec] | |
2a5f078d | 193 | |
cd445739 | 194 | -5, --update-md5 - update md5 comments in spec, implies -nd -ncs |
15caef33 | 195 | --adapter[ize] - run adapter.awk on SPECFILE |
cd445739 AM |
196 | -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs |
197 | -n5, --no-md5 - ignore md5 comments in spec | |
9243e80b ER |
198 | -D, --debug - enable builder script debugging mode, |
199 | -debug - produce rpm debug package (same as --opts -debug) | |
cd445739 AM |
200 | -V, --version - output builder version |
201 | -a, --as_anon - get files via pserver as cvs@$CVS_SERVER, | |
202 | -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package | |
203 | from <package>.spec, | |
204 | -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary | |
205 | only package from <package>.spec, | |
206 | -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack | |
207 | them into src.rpm, | |
208 | -bp, --build-prep - execute the %prep phase of <package>.spec, | |
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 | |
234 | --opts <rpm opts> - additional options for rpm | |
235 | -q, --quiet - be quiet, | |
236 | --date yyyy-mm-dd - build package using resources from specified CVS date, | |
237 | -r <cvstag>, --cvstag <cvstag> | |
238 | - build package using resources from specified CVS tag, | |
239 | -R, --fetch-build-requires | |
240 | - fetch what is BuildRequired, | |
241 | -RB, --remove-build-requires | |
242 | - remove all you fetched with -R or --fetch-build-requires | |
243 | remember, this option requires confirmation, | |
244 | -FRB, --force-remove-build-requires | |
245 | - remove all you fetched with -R or --fetch-build-requires | |
246 | remember, this option works without confirmation, | |
a7eefc54 | 247 | -sf, --source-files - list sources - bare filenames (intended for offline |
248 | operations; does not work when Icon field is present | |
249 | but icon file is absent), | |
250 | -sp, --source-paths - list sources - filenames with full local paths (intended for | |
251 | offline operations; does not work when Icon field is present | |
252 | but icon file is absent), | |
cd445739 AM |
253 | -T <cvstag> , --tag <cvstag> |
254 | - add cvs tag <cvstag> for files, | |
255 | -Tvs, --tag-version-stable | |
094bd95b | 256 | - add cvs tags STABLE and NAME-VERSION-RELEASE for files, |
cd445739 | 257 | -Tvn, --tag-version-nest |
1691a37b | 258 | - add cvs tags NEST and NAME-VERSION-RELEASE for files, |
cd445739 AM |
259 | -Ts, --tag-stable |
260 | - add cvs tag STABLE for files, | |
261 | -Tn, --tag-nest | |
262 | - add cvs tag NEST for files, | |
263 | -Tv, --tag-version | |
1691a37b | 264 | - add cvs tag NAME-VERSION-RELEASE for files, |
cd445739 AM |
265 | -Tp, --tag-prefix <prefix> |
266 | - add <prefix> to NAME-VERSION-RELEASE tags, | |
267 | -tt, --test-tag <prefix> | |
268 | - fail if tag is already present, | |
50321881 JK |
269 | -ir, --integer-release-only |
270 | - allow only integer and snapshot releases | |
cd445739 AM |
271 | -v, --verbose - be verbose, |
272 | -u, --try-upgrade - check version, and try to upgrade package | |
273 | -un, --try-upgrade-with-float-version | |
274 | - as above, but allow float version | |
deccc50e | 275 | -U, --update - refetch sources, don't use distfiles, and update md5 comments |
cd445739 AM |
276 | -Upi, --update-poldek-indexes |
277 | - refresh or make poldek package index files. | |
278 | --with/--without <feature> | |
279 | - conditional build package depending on %_with_<feature>/ | |
280 | %_without_<feature> macro switch. You may now use | |
281 | --with feat1 feat2 feat3 --without feat4 feat5 --with feat6 | |
282 | constructions. Set GROUP_BCONDS to yes to make use of it. | |
6dd19291 | 283 | --target <platform>, --target=<platform> |
64ea5308 | 284 | - build for platform <platform>. |
5a491465 | 285 | " |
286 | } | |
287 | ||
7e40520f ER |
288 | # set TARGET from BuildArch: from SPECFILE |
289 | set_spec_target() { | |
290 | if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then | |
291 | tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE) | |
292 | if [ "$tmp" ]; then | |
293 | TARGET="$tmp" | |
294 | case "$RPMBUILD" in | |
295 | "rpmbuild") | |
296 | TARGET_SWITCH="--target $TARGET" ;; | |
297 | "rpm") | |
298 | TARGET_SWITCH="--target=$TARGET" ;; | |
299 | esac | |
300 | fi | |
301 | fi | |
302 | } | |
303 | ||
cd445739 | 304 | cache_rpm_dump () { |
b2aeec7d AM |
305 | if [ -n "$DEBUG" ]; then |
306 | set -x; | |
307 | set -v; | |
308 | fi | |
7e40520f | 309 | |
cd445739 AM |
310 | rpm_dump_cache=` |
311 | case "$RPMBUILD" in | |
312 | rpm ) | |
2a5f078d | 313 | rpm -bp --nodeps --define 'prep %dump' $BCOND $TARGET_SWITCH $SPECFILE 2>&1 |
cd445739 AM |
314 | ;; |
315 | rpmbuild ) | |
7e40520f | 316 | # FIXME: no $TARGET_SWITCH here needed? |
cd445739 AM |
317 | rpmbuild --nodigest --nosignature --define 'prep %dump' $BCOND $SPECFILE 2>&1 |
318 | ;; | |
319 | esac` | |
320 | } | |
321 | ||
322 | rpm_dump () { | |
323 | if [ -z "$rpm_dump_cache" ] ; then | |
324 | echo "internal error: cache_rpm_dump not called!" 1>&2 | |
325 | fi | |
326 | echo "$rpm_dump_cache" | |
327 | } | |
328 | ||
59398507 | 329 | parse_spec() |
330 | { | |
cd445739 AM |
331 | if [ -n "$DEBUG" ]; then |
332 | set -x; | |
333 | set -v; | |
334 | fi | |
b2975fc3 | 335 | |
cd445739 | 336 | cd $SPECS_DIR |
4ca52257 | 337 | |
cd445739 | 338 | cache_rpm_dump |
00fcec7e | 339 | |
cd445739 AM |
340 | if [ "$NOSRCS" != "yes" ]; then |
341 | SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`" | |
342 | fi | |
343 | if (rpm_dump | grep -qEi ":.*nosource.*1"); then | |
344 | FAIL_IF_NO_SOURCES="no" | |
345 | fi | |
346 | ||
347 | PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`" | |
348 | ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`" | |
349 | PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`" | |
350 | PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -n 1`" | |
351 | PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -n 1`" | |
352 | ||
341603cf | 353 | # These variables may be unset after first cache_rpm_dump call |
354 | # (because of not-yet-retrieved icon file) | |
355 | # | |
356 | # if [ -z "$PACKAGE_NAME" -o -z "$PACKAGE_VERSION" -o -z "$PACKAGE_RELEASE" ]; then | |
357 | # Exit_error err_no_package_data; | |
358 | # fi | |
78eab2a1 | 359 | |
cd445739 AM |
360 | if [ -n "$BE_VERBOSE" ]; then |
361 | echo "- Sources : `nourl $SOURCES`" | |
362 | if [ -n "$PATCHES" ]; then | |
363 | echo "- Patches : `nourl $PATCHES`" | |
364 | else | |
365 | echo "- Patches : *no patches needed*" | |
366 | fi | |
367 | if [ -n "$ICONS" ]; then | |
368 | echo "- Icon : `nourl $ICONS`" | |
369 | else | |
370 | echo "- Icon : *no package icon*" | |
371 | fi | |
372 | echo "- Name : $PACKAGE_NAME" | |
373 | echo "- Version : $PACKAGE_VERSION" | |
374 | echo "- Release : $PACKAGE_RELEASE" | |
375 | fi | |
376 | } | |
377 | ||
378 | Exit_error() | |
379 | { | |
380 | if [ -n "$DEBUG" ]; then | |
381 | set -x; | |
382 | set -v; | |
383 | fi | |
384 | ||
385 | cd "$__PWD" | |
386 | ||
387 | case "$1" in | |
388 | "err_no_spec_in_cmdl" ) | |
389 | remove_build_requires | |
390 | echo "ERROR: spec file name not specified."; | |
391 | exit 2 ;; | |
392 | "err_no_spec_in_repo" ) | |
393 | remove_build_requires | |
394 | echo "Error: spec file not stored in CVS repo."; | |
395 | exit 3 ;; | |
396 | "err_no_source_in_repo" ) | |
397 | remove_build_requires | |
398 | echo "Error: some source, patch or icon files not stored in CVS repo. ($2)"; | |
399 | exit 4 ;; | |
400 | "err_build_fail" ) | |
401 | remove_build_requires | |
402 | echo "Error: package build failed. (${2:-no more info})"; | |
403 | exit 5 ;; | |
78eab2a1 AM |
404 | "err_no_package_data" ) |
405 | remove_build_requires | |
406 | echo "Error: couldn't get out package name/version/release from spec file." | |
407 | exit 6 ;; | |
50321881 JK |
408 | "err_tag_exists" ) |
409 | remove_build_requires | |
410 | echo "Tag ${2} already exists (spec release: ${3})."; | |
411 | exit 9 ;; | |
412 | "err_fract_rel" ) | |
413 | remove_build_requires | |
414 | echo "Release ${2} not integer and not a snapshot."; | |
415 | exit 10 ;; | |
fb96e0b5 AM |
416 | "err_branch_exists" ) |
417 | remove_build_requires | |
418 | echo "Tree branch already exists (${2})."; | |
419 | exit 11 ;; | |
50321881 | 420 | |
cd445739 | 421 | esac |
50321881 | 422 | echo "Unknown error." |
2a5f078d | 423 | exit 100 |
cd445739 AM |
424 | } |
425 | ||
426 | init_builder() | |
427 | { | |
428 | if [ -n "$DEBUG" ]; then | |
429 | set -x; | |
430 | set -v; | |
0dd6320d | 431 | fi |
cd445739 AM |
432 | |
433 | SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`" | |
434 | SPECS_DIR="`$RPM --eval '%{_specdir}'`" | |
435 | ||
436 | __PWD="`pwd`" | |
00fcec7e | 437 | } |
438 | ||
d6a77ddb | 439 | get_spec() |
1471f6d6 | 440 | { |
cd445739 AM |
441 | if [ -n "$DEBUG" ]; then |
442 | set -x; | |
443 | set -v; | |
444 | fi | |
445 | ||
446 | cd "$SPECS_DIR" | |
447 | if [ \! -f "$SPECFILE" ]; then | |
448 | SPECFILE="`basename $SPECFILE .spec`.spec"; | |
449 | fi | |
450 | if [ "$NOCVSSPEC" != "yes" ]; then | |
451 | OPTIONS="up " | |
452 | ||
453 | if [ -n "$CVSROOT" ]; then | |
454 | OPTIONS="-d $CVSROOT $OPTIONS" | |
455 | else | |
456 | if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then | |
457 | echo "warning: No cvs access defined - using local .spec file" | |
458 | NOCVSSPEC="yes" | |
459 | fi | |
460 | fi | |
461 | ||
462 | if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then | |
463 | OPTIONS="$OPTIONS -A" | |
464 | else | |
465 | if [ -n "$CVSDATE" ]; then | |
466 | OPTIONS="$OPTIONS -D $CVSDATE" | |
467 | fi | |
468 | if [ -n "$CVSTAG" ]; then | |
469 | OPTIONS="$OPTIONS -r $CVSTAG" | |
470 | fi | |
471 | fi | |
472 | ||
473 | result=1 | |
474 | retries_counter=0 | |
475 | while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ] | |
476 | do | |
477 | retries_counter=$(( $retries_counter + 1 )) | |
478 | output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1) | |
479 | result=$? | |
480 | [ -n "$output" ] && echo "$output" | |
481 | if [ "$result" -ne "0" ]; then | |
482 | if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then | |
483 | echo "Trying again [$SPECFILE]... ($retries_counter)" | |
484 | sleep 2 | |
485 | continue | |
486 | fi | |
487 | Exit_error err_no_spec_in_repo; | |
488 | fi | |
489 | done | |
490 | fi | |
491 | if [ ! -f "$SPECFILE" ]; then | |
492 | Exit_error err_no_spec_in_repo; | |
493 | fi | |
494 | ||
495 | if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then | |
496 | chmod $CHMOD_MODE $SPECFILE | |
497 | fi | |
498 | unset OPTIONS | |
a7eefc54 | 499 | [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE |
7e40520f ER |
500 | |
501 | set_spec_target | |
cd445739 AM |
502 | } |
503 | ||
504 | find_mirror() | |
505 | { | |
506 | cd "$SPECS_DIR" | |
507 | url="$1" | |
508 | if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then | |
509 | cvs update mirrors >&2 | |
510 | fi | |
511 | ||
512 | IFS="|" | |
513 | while read origin mirror name rest | |
514 | do | |
515 | ol=`echo -n "$origin"|wc -c` | |
516 | prefix="`echo -n "$url" | head -c $ol`" | |
517 | if [ "$prefix" = "$origin" ] ; then | |
518 | suffix="`echo "$url"|cut -b $ol-`" | |
519 | echo -n "$mirror$suffix" | |
520 | return 0 | |
521 | fi | |
522 | done < mirrors | |
523 | echo "$url" | |
524 | } | |
525 | ||
526 | src_no () | |
527 | { | |
528 | cd $SPECS_DIR | |
529 | rpm_dump | \ | |
530 | grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \ | |
531 | sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \ | |
532 | head -n 1 | xargs | |
1471f6d6 | 533 | } |
534 | ||
cd445739 | 535 | src_md5 () |
8ba5cdda | 536 | { |
cd445739 AM |
537 | [ X"$NO5" = X"yes" ] && return |
538 | no=$(src_no "$1") | |
539 | [ -z "$no" ] && return | |
540 | cd $SPECS_DIR | |
47a8df12 | 541 | spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::) |
cd445739 AM |
542 | if [ -z "$spec_rev" ]; then |
543 | spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')" | |
544 | fi | |
545 | spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')" | |
546 | md5=$(grep -s -v '^#' additional-md5sums | \ | |
547 | grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \ | |
548 | sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \ | |
549 | grep -E '^[0-9a-f]{32}$') | |
550 | if [ X"$md5" = X"" ] ; then | |
6203ea52 AG |
551 | source_md5=`grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` |
552 | if [ ! -z "$source_md5" ] ; then | |
7e365483 | 553 | echo $source_md5; |
6203ea52 | 554 | else |
7e365483 KK |
555 | # we have empty SourceX-md5, but it is still possible |
556 | # that we have NoSourceX-md5 AND NoSource: X | |
557 | nosource_md5=`grep -i "#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` | |
558 | if [ ! -z "$nosource_md5" -a ! X"`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" = X"" ] ; then | |
559 | echo $nosource_md5; | |
560 | fi; | |
6203ea52 | 561 | fi; |
cd445739 AM |
562 | else |
563 | if [ $(echo "$md5" | wc -l) != 1 ] ; then | |
564 | echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2 | |
565 | fi | |
566 | echo "$md5" | tail -n 1 | |
567 | fi | |
568 | } | |
569 | ||
570 | distfiles_url () | |
571 | { | |
1246dc2a | 572 | echo "$PROTOCOL$DISTFILES_SERVER/distfiles/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")" |
cd445739 AM |
573 | } |
574 | ||
575 | distfiles_attic_url () | |
576 | { | |
1246dc2a | 577 | echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")" |
cd445739 AM |
578 | } |
579 | ||
580 | good_md5 () | |
581 | { | |
582 | md5=$(src_md5 "$1") | |
583 | [ "$md5" = "" ] || \ | |
584 | [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ] | |
8ba5cdda PG |
585 | } |
586 | ||
a4b50627 AF |
587 | good_size () |
588 | { | |
deccc50e AM |
589 | size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)" |
590 | [ -n "$size" -a "$size" -gt 0 ] | |
a4b50627 AF |
591 | } |
592 | ||
947025e5 | 593 | cvsignore_df () |
594 | { | |
595 | if [ "$CVSIGNORE_DF" != "yes" ]; then | |
596 | return | |
597 | fi | |
598 | cvsignore=${SOURCE_DIR}/.cvsignore | |
599 | if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then | |
600 | echo "$1" >> $cvsignore | |
601 | fi | |
602 | } | |
603 | ||
cd445739 AM |
604 | get_files() |
605 | { | |
606 | GET_FILES="$@" | |
607 | ||
608 | if [ -n "$DEBUG" ]; then | |
609 | set -x; | |
610 | set -v; | |
611 | fi | |
612 | ||
613 | if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then | |
614 | cd "$SOURCE_DIR" | |
615 | ||
616 | OPTIONS="up " | |
617 | if [ -n "$CVSROOT" ]; then | |
618 | OPTIONS="-d $CVSROOT $OPTIONS" | |
619 | else | |
620 | if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then | |
621 | echo "warning: No cvs access defined for SOURCES" | |
622 | NOCVS="yes" | |
623 | fi | |
624 | fi | |
625 | if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then | |
626 | OPTIONS="$OPTIONS -A" | |
627 | else | |
628 | if [ -n "$CVSDATE" ]; then | |
629 | OPTIONS="$OPTIONS -D $CVSDATE" | |
630 | fi | |
631 | if [ -n "$CVSTAG" ]; then | |
632 | OPTIONS="$OPTIONS -r $CVSTAG" | |
633 | fi | |
634 | fi | |
635 | for i in $GET_FILES | |
636 | do | |
637 | if [ -n "$UPDATE5" ]; then | |
638 | if [ -n "$ADD5" ]; then | |
639 | [ `nourl $i` = "$i" ] && continue | |
640 | grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue | |
641 | else | |
642 | grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue | |
643 | fi | |
644 | fi | |
645 | FROM_DISTFILES=0 | |
646 | if [ ! -f `nourl $i` ] || [ $ALWAYS_CVSUP = "yes" ]; then | |
647 | if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then | |
648 | echo "Warning: no URL given for $i" | |
649 | fi | |
650 | ||
651 | if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then | |
a4b50627 | 652 | if good_md5 "$i" && good_size "$i"; then |
deccc50e | 653 | echo "$(nourl "$i") having proper md5sum already exists" |
cd445739 AM |
654 | continue |
655 | fi | |
656 | target=$(nourl "$i") | |
657 | url=$(distfiles_url "$i") | |
658 | url_attic=$(distfiles_attic_url "$i") | |
659 | FROM_DISTFILES=1 | |
660 | if [ `echo $url | grep -E '^(\.|/)'` ]; then | |
661 | ${GETLOCAL} $url $target | |
662 | else | |
663 | if [ -z "$NOMIRRORS" ]; then | |
664 | url="`find_mirror "$url"`" | |
665 | fi | |
ca2e6c31 | 666 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
cd445739 | 667 | if [ `echo $url | grep -E 'ftp://'` ]; then |
ca2e6c31 | 668 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 AM |
669 | fi |
670 | fi | |
671 | if ! test -s "$target"; then | |
672 | rm -f "$target" | |
673 | if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then | |
674 | ${GETLOCAL} $url_attic $target | |
675 | else | |
676 | if [ -z "$NOMIRRORS" ]; then | |
677 | url_attic="`find_mirror "$url_attic"`" | |
678 | fi | |
ca2e6c31 | 679 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
cd445739 | 680 | if [ `echo $url_attic | grep -E 'ftp://'` ]; then |
ca2e6c31 | 681 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 AM |
682 | fi |
683 | fi | |
684 | fi | |
947025e5 | 685 | if test -s "$target"; then |
686 | cvsignore_df $target | |
687 | else | |
cd445739 AM |
688 | rm -f "$target" |
689 | FROM_DISTFILES=0 | |
690 | fi | |
691 | elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then | |
692 | # ( echo $i | grep -qvE '(ftp|http|https)://' ); -- if CVS should be used, but URLs preferred | |
693 | result=1 | |
694 | retries_counter=0 | |
695 | while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ] | |
696 | do | |
697 | retries_counter=$(( $retries_counter + 1 )) | |
698 | output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1) | |
699 | result=$? | |
700 | [ -n "$output" ] && echo "$output" | |
701 | if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out|Unknown host)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then | |
702 | echo "Trying again [`nourl $i`]... ($retries_counter)" | |
703 | sleep 2 | |
704 | continue | |
705 | else | |
706 | break | |
707 | fi | |
708 | done | |
709 | fi | |
710 | ||
711 | if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then | |
712 | if [ -z "$NOMIRRORS" ]; then | |
713 | im="`find_mirror "$i"`" | |
714 | else | |
715 | im="$i" | |
716 | fi | |
717 | ${GETURI} "$im" || \ | |
718 | if [ `echo $im | grep -E 'ftp://'` ]; then | |
719 | ${GETURI2} "$im" | |
7e365483 | 720 | fi |
cd445739 AM |
721 | fi |
722 | ||
723 | fi | |
724 | srcno=$(src_no $i) | |
725 | if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then | |
726 | Exit_error err_no_source_in_repo $i; | |
727 | elif [ -n "$UPDATE5" ] && \ | |
728 | ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \ | |
729 | [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \ | |
730 | grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE ) | |
731 | then | |
deccc50e | 732 | echo "Updating source-$srcno md5." |
cd445739 AM |
733 | md5=$(md5sum `nourl $i` | cut -f1 -d' ') |
734 | perl -i -ne ' | |
deccc50e AM |
735 | print unless /^\s*#\s*Source'$srcno'-md5\s*:/i; |
736 | print "# Source'$srcno'-md5:\t'$md5'\n" | |
cd445739 AM |
737 | if /^Source'$srcno'\s*:\s+/; |
738 | ' \ | |
739 | $SPECS_DIR/$SPECFILE | |
740 | fi | |
2a5f078d | 741 | |
a4b50627 | 742 | if good_md5 "$i" && good_size "$i"; then |
cd445739 AM |
743 | : |
744 | elif [ "$FROM_DISTFILES" = 1 ]; then | |
deccc50e | 745 | # wrong md5 from distfiles: remove the file and try again |
cd445739 | 746 | # but only once ... |
deccc50e | 747 | echo "MD5 sum mismatch. Trying full fetch." |
cd445739 AM |
748 | FROM_DISTFILES=2 |
749 | rm -f $target | |
ca2e6c31 | 750 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
cd445739 | 751 | if [ `echo $url | grep -E 'ftp://'` ]; then |
ca2e6c31 | 752 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 AM |
753 | fi |
754 | if ! test -s "$target"; then | |
755 | rm -f "$target" | |
ca2e6c31 | 756 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
cd445739 | 757 | if [ `echo $url_attic | grep -E 'ftp://'` ]; then |
ca2e6c31 | 758 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 AM |
759 | fi |
760 | fi | |
761 | test -s "$target" || rm -f "$target" | |
762 | fi | |
763 | ||
a4b50627 | 764 | if good_md5 "$i" && good_size "$i" ; then |
cd445739 AM |
765 | : |
766 | else | |
deccc50e AM |
767 | echo "MD5 sum mismatch or 0 size. Use -U to refetch sources," |
768 | echo "or -5 to update md5 sums, if you're sure files are correct." | |
cd445739 AM |
769 | Exit_error err_no_source_in_repo $i |
770 | fi | |
771 | done | |
772 | ||
773 | if [ "$CHMOD" = "yes" ]; then | |
774 | CHMOD_FILES="`nourl $GET_FILES`" | |
775 | if [ -n "$CHMOD_FILES" ]; then | |
776 | chmod $CHMOD_MODE $CHMOD_FILES | |
777 | fi | |
778 | fi | |
779 | unset OPTIONS | |
780 | fi | |
781 | } | |
782 | ||
783 | make_tagver() { | |
78eab2a1 AM |
784 | |
785 | if [ -n "$DEBUG" ]; then | |
786 | set -x; | |
787 | set -v; | |
788 | fi | |
2a5f078d | 789 | |
cd445739 AM |
790 | # Check whether first character of PACKAGE_NAME is legal for tag name |
791 | if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then | |
792 | TAG_PREFIX=tag_ | |
793 | fi | |
794 | TAGVER=$TAG_PREFIX$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"` | |
795 | # Remove #kernel.version_release from TAGVER because tagging sources | |
796 | # could occur with different kernel-headers than kernel-headers used at build time. | |
797 | TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g') | |
798 | echo -n "$TAGVER" | |
799 | } | |
800 | ||
801 | tag_files() | |
802 | { | |
803 | TAG_FILES="$@" | |
804 | ||
805 | if [ -n "$DEBUG" ]; then | |
806 | set -x; | |
807 | set -v; | |
808 | fi | |
809 | ||
810 | if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then | |
811 | echo "Version: $PACKAGE_VERSION" | |
812 | echo "Release: $PACKAGE_RELEASE" | |
813 | ||
814 | TAGVER=`make_tagver` | |
815 | ||
816 | if [ "$TAG_VERSION" = "yes" ]; then | |
817 | echo "CVS tag: $TAGVER" | |
818 | fi | |
819 | if [ -n "$TAG" ]; then | |
820 | echo "CVS tag: $TAG" | |
821 | fi | |
822 | ||
823 | OPTIONS="tag -F" | |
824 | if [ -n "$CVSROOT" ]; then | |
825 | OPTIONS="-d $CVSROOT $OPTIONS" | |
826 | fi | |
827 | ||
828 | cd "$SOURCE_DIR" | |
829 | for i in $TAG_FILES | |
830 | do | |
831 | # don't tag files stored on distfiles | |
832 | [ -n "`src_md5 $i`" ] && continue | |
833 | if [ -f "`nourl $i`" ]; then | |
834 | if [ "$TAG_VERSION" = "yes" ]; then | |
835 | cvs $OPTIONS $TAGVER `nourl $i` | |
836 | fi | |
837 | if [ -n "$TAG" ]; then | |
838 | cvs $OPTIONS $TAG `nourl $i` | |
839 | fi | |
840 | else | |
841 | Exit_error err_no_source_in_repo $i | |
842 | fi | |
843 | done | |
844 | ||
845 | cd "$SPECS_DIR" | |
846 | if [ "$TAG_VERSION" = "yes" ]; then | |
847 | cvs $OPTIONS $TAGVER $SPECFILE | |
848 | fi | |
849 | if [ -n "$TAG" ]; then | |
850 | cvs $OPTIONS $TAG $SPECFILE | |
851 | fi | |
852 | ||
853 | unset OPTIONS | |
854 | fi | |
855 | } | |
856 | ||
857 | branch_files() | |
858 | { | |
859 | TAG=$1 | |
860 | echo "CVS branch tag: $TAG" | |
861 | shift; | |
862 | ||
863 | TAG_FILES="$@" | |
864 | ||
865 | if [ -n "$DEBUG" ]; then | |
866 | set -x; | |
867 | set -v; | |
868 | fi | |
869 | ||
870 | if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then | |
871 | ||
872 | OPTIONS="tag -b" | |
873 | if [ -n "$CVSROOT" ]; then | |
874 | OPTIONS="-d $CVSROOT $OPTIONS" | |
875 | fi | |
876 | cd "$SOURCE_DIR" | |
877 | for i in $TAG_FILES | |
878 | do | |
879 | if [ -f `nourl $i` ]; then | |
880 | cvs $OPTIONS $TAG `nourl $i` | |
881 | else | |
882 | Exit_error err_no_source_in_repo $i | |
883 | fi | |
884 | done | |
885 | cd "$SPECS_DIR" | |
886 | cvs $OPTIONS $TAG $SPECFILE | |
887 | ||
888 | unset OPTIONS | |
889 | fi | |
890 | } | |
891 | ||
892 | ||
893 | ||
59398507 | 894 | build_package() |
895 | { | |
cd445739 AM |
896 | if [ -n "$DEBUG" ]; then |
897 | set -x; | |
898 | set -v; | |
899 | fi | |
5a491465 | 900 | |
cd445739 AM |
901 | cd "$SPECS_DIR" |
902 | ||
903 | if [ -n "$TRY_UPGRADE" ]; then | |
904 | if [ -n "$FLOAT_VERSION" ]; then | |
905 | TNOTIFY=`./pldnotify.awk $SPECFILE -n` | |
906 | else | |
907 | TNOTIFY=`./pldnotify.awk $SPECFILE` | |
908 | fi | |
909 | ||
910 | TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'` | |
911 | ||
912 | if [ -n "$TNEWVER" ]; then | |
913 | TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'` | |
914 | echo "New version found, updating spec file to version " $TNEWVER | |
915 | cp -f $SPECFILE $SPECFILE.bak | |
916 | chmod +w $SPECFILE | |
917 | eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE" | |
918 | eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE" | |
919 | parse_spec; | |
7f347798 | 920 | if [ -n "$ICONS" ]; then |
921 | get_files $ICONS; | |
922 | parse_spec; | |
923 | fi | |
cd445739 AM |
924 | get_files "$SOURCES $PATCHES"; |
925 | unset TOLDVER TNEWVER TNOTIFY | |
926 | fi | |
927 | fi | |
928 | cd "$SPECS_DIR" | |
2a5f078d | 929 | |
cd445739 AM |
930 | case "$COMMAND" in |
931 | build ) | |
932 | BUILD_SWITCH="-ba" ;; | |
933 | build-binary ) | |
934 | BUILD_SWITCH="-bb" ;; | |
935 | build-source ) | |
936 | BUILD_SWITCH="-bs --nodeps" ;; | |
937 | build-prep ) | |
938 | BUILD_SWITCH="-bp --nodeps" ;; | |
939 | esac | |
940 | if [ -n "$LOGFILE" ]; then | |
941 | LOG=`eval echo $LOGFILE` | |
942 | if [ -d "$LOG" ]; then | |
943 | echo "Log file $LOG is a directory." | |
944 | echo "Parse error in the spec?" | |
945 | Exit_error err_build_fail; | |
946 | fi | |
947 | if [ -n "$LASTLOG_FILE" ]; then | |
948 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
949 | fi | |
950 | RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM | |
8f96ab6c | 951 | (time nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG |
cd445739 AM |
952 | RETVAL=`cat $RES_FILE` |
953 | rm $RES_FILE | |
954 | if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then | |
955 | if [ "$RETVAL" -eq "0" ]; then | |
956 | mv $LOG $LOGDIROK | |
957 | else | |
958 | mv $LOG $LOGDIRFAIL | |
959 | fi | |
960 | fi | |
8ba5cdda | 961 | else |
8f96ab6c | 962 | eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE |
cd445739 | 963 | RETVAL=$? |
8ba5cdda | 964 | fi |
cd445739 AM |
965 | if [ "$RETVAL" -ne "0" ]; then |
966 | if [ -n "$TRY_UPGRADE" ]; then | |
967 | echo "\n!!! Package with new version cannot be build automagically\n" | |
968 | mv -f $SPECFILE.bak $SPECFILE | |
969 | fi | |
970 | Exit_error err_build_fail; | |
971 | fi | |
972 | unset BUILD_SWITCH | |
973 | } | |
974 | ||
975 | nourl() | |
976 | { | |
977 | echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g' | |
978 | } | |
979 | ||
cd445739 AM |
980 | install_required_packages() |
981 | { | |
982 | run_poldek -vi $1 | |
983 | return $? | |
984 | } | |
985 | ||
986 | set_bconds_values() | |
987 | { | |
988 | AVAIL_BCONDS_WITHOUT="" | |
989 | AVAIL_BCONDS_WITH="" | |
990 | if `grep -q ^%bcond ${SPECFILE}`; then | |
991 | BCOND_VERSION="NEW" | |
36d03934 | 992 | elif `egrep -q ^#\ *_with ${SPECFILE}`; then |
cd445739 AM |
993 | BCOND_VERSION="OLD" |
994 | else | |
995 | BCOND_VERSION="NONE" | |
996 | fi | |
301cbfd4 ER |
997 | |
998 | # expand bconds from ~/.bcondrc | |
999 | # The file structure is like gentoo's package.use: | |
1000 | # --- | |
1001 | # * -selinux | |
1002 | # samba -mysql -pgsql | |
47a8df12 | 1003 | # w32codec-installer license_agreement |
301cbfd4 ER |
1004 | # php +mysqli |
1005 | # --- | |
c8a3e2ac | 1006 | if [ "${BCOND_VERSION}" != "NONE" ] && ( [ -f $HOME/.bcondrc ] || ( [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] ) ) ; then |
301cbfd4 ER |
1007 | # This takes package name, first defined in spec. |
1008 | # so consider that when defining flags for package. | |
1009 | PN=`$RPM -q --qf '%{NAME}\n' --specfile $SPECFILE | head -n 1` | |
1010 | AVAIL=`$RPMBUILD --bcond $SPECFILE` | |
1011 | ||
c8a3e2ac AG |
1012 | BCONDRC=$HOME/.bcondrc |
1013 | [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && BCONDRC=$HOME_ETC/.bcondrc | |
1014 | ||
301cbfd4 ER |
1015 | while read pkg flags; do |
1016 | # ignore comments | |
1017 | [[ "$pkg" == \#* ]] && continue | |
1018 | ||
1019 | # any package or current package? | |
1020 | if [ "$pkg" = "*" ] || [ "$pkg" = "$PN" ]; then | |
1021 | for flag in $flags; do | |
1022 | opt=${flag#[+-]} | |
1023 | ||
1024 | # use only flags which are in this package. | |
1025 | if [[ $AVAIL = *${opt}* ]]; then | |
3b5101f0 ER |
1026 | if [[ $flag = -* ]]; then |
1027 | BCOND="$BCOND --without $opt" | |
301cbfd4 | 1028 | else |
3b5101f0 | 1029 | BCOND="$BCOND --with $opt" |
301cbfd4 ER |
1030 | fi |
1031 | fi | |
1032 | done | |
1033 | fi | |
c8a3e2ac | 1034 | done < $BCONDRC |
301cbfd4 ER |
1035 | fi |
1036 | ||
cd445739 AM |
1037 | case "${BCOND_VERSION}" in |
1038 | NONE) | |
7e365483 | 1039 | : |
cd445739 | 1040 | ;; |
7e365483 | 1041 | OLD) |
cd445739 AM |
1042 | echo "Warning: This spec has old style bconds. Fix it || die." |
1043 | for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_without_` | |
1044 | do | |
1045 | AVAIL_BCOND_WITHOUT=`echo $opt|sed -e "s/^_without_//g"` | |
1046 | if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then | |
1047 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>" | |
1048 | else | |
1049 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT" | |
1050 | fi | |
1051 | done | |
2a5f078d | 1052 | |
cd445739 AM |
1053 | for opt in `$RPMBUILD --bcond $SPECFILE |grep ^_with_` |
1054 | do | |
1055 | AVAIL_BCOND_WITH=`echo $opt|sed -e "s/^_with_//g"` | |
1056 | if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then | |
1057 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" | |
1058 | else | |
1059 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1060 | fi | |
1061 | done | |
1062 | ;; | |
1063 | NEW) | |
1064 | cond_type="" # with || without | |
1065 | for opt in `$RPMBUILD --bcond $SPECFILE` | |
1066 | do | |
1067 | case "$opt" in | |
1068 | _without) | |
1069 | cond_type="without" | |
1070 | ;; | |
1071 | _with) | |
1072 | cond_type="with" | |
1073 | ;; | |
f8d24cee | 1074 | _without_*) |
1075 | AVAIL_BCOND_WITHOUT="`echo $opt | sed 's/^_without_//g'`" | |
1076 | if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then | |
1077 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>" | |
1078 | else | |
1079 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT" | |
1080 | fi | |
1081 | ;; | |
1082 | _with_*) | |
1083 | AVAIL_BCOND_WITH="`echo $opt | sed 's/^_with_//g'`" | |
1084 | if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then | |
1085 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" | |
1086 | else | |
1087 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1088 | fi | |
1089 | ;; | |
cd445739 AM |
1090 | *) |
1091 | case "$cond_type" in | |
1092 | with) | |
1093 | cond_type='' | |
1094 | AVAIL_BCOND_WITH="$opt" | |
1095 | if `echo $BCOND|grep -q -- "--with $AVAIL_BCOND_WITH"`;then | |
1096 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" | |
1097 | else | |
1098 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1099 | fi | |
7e365483 | 1100 | ;; |
cd445739 AM |
1101 | without) |
1102 | cond_type='' | |
1103 | AVAIL_BCOND_WITHOUT="$opt" | |
1104 | if `echo $BCOND|grep -q -- "--without $AVAIL_BCOND_WITHOUT"`;then | |
1105 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>" | |
1106 | else | |
1107 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT" | |
1108 | fi | |
1109 | ;; | |
1110 | esac | |
1111 | ;; | |
1112 | esac | |
1113 | done | |
1114 | ;; | |
1115 | esac | |
1116 | } | |
1117 | ||
1118 | run_sub_builder() | |
1119 | { | |
1120 | package_name="${1}" | |
1121 | echo -ne "Package installation failed:\t$package_name\n" | |
1122 | # | |
1123 |