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