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