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