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