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