]>
Commit | Line | Data |
---|---|---|
b054f772 | 1 | #!/bin/sh |
33f5276d | 2 | # ----------- |
25fa34fe | 3 | # $Id$ |
33f5276d | 4 | # Exit codes: |
5 | # 0 - succesful | |
6 | # 1 - help dispayed | |
7 | # 2 - no spec file name in cmdl parameters | |
8 | # 3 - spec file not stored in repo | |
0ad50ce9 | 9 | # 4 - some source, patch or icon files not stored in repo |
10 | # 5 - package build failed | |
5a491465 | 11 | |
4003ad8c | 12 | VERSION="\ |
13 | Build package utility from PLD CVS repository | |
6cb7df6d | 14 | V 0.11 (C) 1999-2003 Free Penguins". |
5a491465 | 15 | PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin" |
a7af9862 | 16 | |
b03f053b | 17 | COMMAND="build" |
18 | ||
bde1c404 | 19 | SPECFILE="" |
d287305c | 20 | BE_VERBOSE="" |
4003ad8c | 21 | QUIET="" |
5dd89621 | 22 | CLEAN="" |
7c2dd1b2 | 23 | DEBUG="" |
cc97f1f3 | 24 | NOURLS="" |
157dc315 | 25 | NOCVS="" |
6fc910c7 | 26 | NOCVSSPEC="" |
fc0e5bb5 | 27 | NODIST="" |
b130abf2 | 28 | UPDATE="" |
a9d9a79a | 29 | UPDATE5="" |
de6b5b2a | 30 | ADD5="" |
58947ded | 31 | ALLWAYS_CVSUP=${ALLWAYS_CVSUP:-"yes"} |
c61a8d10 AM |
32 | if [ -s CVS/Root ]; then |
33 | CVSROOT=$(cat CVS/Root) | |
34 | else | |
35 | CVSROOT=${CVSROOT:-""} | |
36 | fi | |
d6a75d60 | 37 | # Example: LOGFILE='../log.$PACKAGE_NAME' |
38 | # Yes, you can use variable name! Note _single_ quotes! | |
39 | LOGFILE='' | |
00fcec7e | 40 | |
41 | LOGDIR="" | |
42 | LOGDIROK="" | |
43 | LOGDIRFAIL="" | |
44 | LASTLOG_FILE="" | |
45 | LTAG="" | |
d6a75d60 | 46 | CHMOD="yes" |
47 | CHMOD_MODE="0444" | |
33a9d2d1 | 48 | RPMOPTS="" |
6049c3d1 | 49 | BCOND="" |
d287305c | 50 | |
51 | PATCHES="" | |
52 | SOURCES="" | |
7053d3fd | 53 | ICONS="" |
d287305c | 54 | PACKAGE_RELEASE="" |
55 | PACKAGE_VERSION="" | |
56 | PACKAGE_NAME="" | |
34c911e6 | 57 | WGET_RETRIES=${MAX_WGET_RETRIES:-0} |
b92ecfc9 | 58 | CVS_RETRIES=${MAX_CVS_RETRIES:-1000} |
5a491465 | 59 | |
00fcec7e | 60 | CVSTAG="" |
61 | RES_FILE="" | |
62 | ||
62546902 | 63 | CVS_SERVER="cvs.pld-linux.org" |
6cb7df6d | 64 | DISTFILES_SERVER="ftp://distfiles.pld-linux.org" |
ea15df77 | 65 | |
3ae81a20 | 66 | DEF_NICE_LEVEL=0 |
67 | ||
c6a390a1 AM |
68 | FAIL_IF_NO_SOURCES="yes" |
69 | ||
8f7b338e | 70 | GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES --inet" |
71 | GETURI2="wget -c -nd -t$WGET_RETRIES --inet" | |
6aefe77b | 72 | GETLOCAL="cp -a" |
11f33a0c | 73 | |
7147050f AM |
74 | if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then |
75 | RPM="rpm" | |
76 | RPMBUILD="rpm" | |
77 | else | |
78 | RPM="rpm" | |
79 | RPMBUILD="rpmbuild" | |
80 | fi | |
81 | ||
6eb44b93 | 82 | if [ -f ~/etc/builderrc ]; then |
7922b3ec | 83 | . ~/etc/builderrc |
6eb44b93 | 84 | elif [ -f ~/.builderrc ]; then |
7922b3ec | 85 | . ~/.builderrc |
5aa0ef93 AF |
86 | fi |
87 | ||
da946cd6 | 88 | #--------------------------------------------- |
89 | # functions | |
90 | ||
5a491465 | 91 | usage() |
92 | { | |
7c2dd1b2 | 93 | if [ -n "$DEBUG" ]; then set -xv; fi |
94 | echo "\ | |
7922b3ec | 95 | Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build] |
81f85806 | 96 | |
97 | [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade] | |
98 | [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get] | |
99 | [-h|--help] [{-l,--logtofile} <logfile>] [-m|--mr-proper] | |
00fcec7e | 100 | [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>] |
a2164135 MM |
101 | [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest] |
102 | [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version] | |
81f85806 | 103 | [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] |
c9ff8825 | 104 | [--with/--without <feature>] [--define <macro> <value>] <package>[.spec] |
5a491465 | 105 | |
de6b5b2a MM |
106 | -5, --update-md5 |
107 | - update md5 comments in spec, implies -nd | |
108 | -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd | |
a2a9c8df | 109 | -D, --debug - enable script debugging mode, |
5a491465 | 110 | -V, --version - output builder version |
62546902 | 111 | -a, --as_anon - get files via pserver as cvs@$CVS_SERVER, |
79b2ec0e | 112 | -b, -ba, |
cc97f1f3 | 113 | --build - get all files from CVS repo or HTTP/FTP and build |
5a491465 | 114 | package from <package>.spec, |
7922b3ec | 115 | -bb, --build-binary |
116 | - get all files from CVS repo or HTTP/FTP and build | |
79b2ec0e | 117 | binary only package from <package>.spec, |
118 | -bs, | |
cc97f1f3 SZ |
119 | --build-source - get all files from CVS repo or HTTP/FTP and only |
120 | pack them into src.rpm, | |
8ba5cdda | 121 | -B, --branch - add branch |
7922b3ec | 122 | -c, --clean - clean all temporarily created files (in BUILD, |
79b2ec0e | 123 | SOURCES, SPECS and \$RPM_BUILD_ROOT), |
7922b3ec | 124 | -d <cvsroot>, --cvsroot <cvsroot> |
125 | - setup \$CVSROOT, | |
e7bdc1b4 | 126 | --define <macro> <value> |
81f85806 | 127 | - define a macro <macro> with value <value>, |
7922b3ec | 128 | -g, --get - get <package>.spec and all related files from |
cc97f1f3 | 129 | CVS repo or HTTP/FTP, |
5a491465 | 130 | -h, --help - this message, |
7922b3ec | 131 | -l <logfile>, --logtofile <logfile> |
132 | - log all to file, | |
ff45a501 | 133 | -m, --mr-proper - only remove all files related to spec file and |
8bc51224 | 134 | all work resources, |
6fc910c7 | 135 | -nc, --no-cvs - don't download sources from CVS, if source URL is |
136 | given, | |
137 | -ncs, --no-cvs-specs | |
138 | - don't check specs in CVS | |
fc0e5bb5 TP |
139 | -nd, --no-distfiles |
140 | - don't download from distfiles | |
4ca52257 | 141 | -nm, --no-mirrors - don't download from mirror, if source URL is given, |
157dc315 | 142 | -nu, --no-urls - don't try to download from FTP/HTTP location, |
0143ec80 | 143 | -ns, --no-srcs - don't download Sources |
fd2b5687 | 144 | -ns0, --no-source0 |
0143ec80 | 145 | - don't download Source0 |
7922b3ec | 146 | --opts <rpm opts> |
147 | - additional options for rpm | |
5a491465 | 148 | -q, --quiet - be quiet, |
448deaa0 | 149 | --date yyyy-mm-dd |
150 | - build package using resources from specified CVS | |
151 | date, | |
7922b3ec | 152 | -r <cvstag>, --cvstag <cvstag> |
153 | - build package using resources from specified CVS | |
67fcd1e4 | 154 | tag, |
7922b3ec | 155 | -T <cvstag> , --tag <cvstag> |
156 | - add cvs tag <cvstag> for files, | |
78ce14b3 | 157 | -Tvs, --tag-version-stable |
158 | - add cvs tags STABLE and NAME-VERSION-RELESE for files, | |
a2164135 MM |
159 | -Tvn, --tag-version-nest |
160 | - add cvs tags NEST and NAME-VERSION-RELESE for files, | |
78ce14b3 | 161 | -Ts, --tag-stable |
162 | - add cvs tag STABLE for files, | |
a2164135 MM |
163 | -Tn, --tag-nest |
164 | - add cvs tag NEST for files, | |
7922b3ec | 165 | -Tv, --tag-version |
166 | - add cvs tag NAME-VERSION-RELESE for files, | |
5a491465 | 167 | -v, --verbose - be verbose, |
81f85806 | 168 | -u, --try-upgrade |
169 | - check version, and try to upgrade package | |
b130abf2 TP |
170 | -un, --try-upgrade-with-float-version |
171 | - as above, but allow float version | |
172 | -U, --update | |
de6b5b2a MM |
173 | - refetch sources, don't use distfiles, and update md5 |
174 | comments | |
d5787aec | 175 | --with/--without <feature> |
81f85806 | 176 | - conditional build package depending on |
d5787aec | 177 | %_with_<feature>/%_without_<feature> macro |
81f85806 | 178 | switch |
5a491465 | 179 | " |
180 | } | |
181 | ||
59398507 | 182 | parse_spec() |
183 | { | |
c3428d50 | 184 | if [ -n "$DEBUG" ]; then |
a7af9862 | 185 | set -x; |
186 | set -v; | |
71d62f04 | 187 | fi |
7c2dd1b2 | 188 | |
25fa34fe | 189 | cd $SPECS_DIR |
72fb89b5 | 190 | if [ "$NOSRCS" != "yes" ]; then |
a7af9862 | 191 | SOURCES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`" |
72fb89b5 | 192 | fi |
7147050f | 193 | if ($RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | grep -qEi ":.*nosource.*1"); then |
a7af9862 | 194 | FAIL_IF_NO_SOURCES="no" |
c6a390a1 AM |
195 | fi |
196 | ||
7147050f | 197 | PATCHES="`$RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`" |
cc97f1f3 | 198 | ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`" |
7147050f AM |
199 | PACKAGE_NAME="`$RPM -q --qf '%{NAME}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`" |
200 | PACKAGE_VERSION="`$RPM -q --qf '%{VERSION}\n' --specfile ${SPECFILE} 2> /dev/null| head -1`" | |
201 | PACKAGE_RELEASE="`$RPM -q --qf '%{RELEASE}\n' --specfile ${SPECFILE} 2> /dev/null | head -1`" | |
79379585 | 202 | |
9e06e5c3 | 203 | if [ -n "$BE_VERBOSE" ]; then |
00fcec7e | 204 | echo "- Sources : `nourl $SOURCES`" |
cc97f1f3 | 205 | if [ -n "$PATCHES" ]; then |
a7af9862 | 206 | echo "- Patches : `nourl $PATCHES`" |
cc97f1f3 | 207 | else |
a7af9862 | 208 | echo "- Patches : *no patches needed*" |
cc97f1f3 | 209 | fi |
7053d3fd | 210 | if [ -n "$ICONS" ]; then |
a7af9862 | 211 | echo "- Icon : `nourl $ICONS`" |
a3df415f | 212 | else |
a7af9862 | 213 | echo "- Icon : *no package icon*" |
a3df415f | 214 | fi |
9e06e5c3 | 215 | echo "- Name : $PACKAGE_NAME" |
216 | echo "- Version : $PACKAGE_VERSION" | |
39cbc282 | 217 | echo "- Release : $PACKAGE_RELEASE" |
d287305c | 218 | fi |
33f5276d | 219 | } |
220 | ||
221 | Exit_error() | |
222 | { | |
00fcec7e | 223 | if [ -n "$DEBUG" ]; then |
71d62f04 | 224 | set -x; |
00fcec7e | 225 | set -v; |
71d62f04 | 226 | fi |
7c2dd1b2 | 227 | |
33f5276d | 228 | cd $__PWD |
229 | ||
4849ca8d | 230 | case "$1" in |
33f5276d | 231 | "err_no_spec_in_cmdl" ) |
232 | echo "ERROR: spec file name not specified."; | |
233 | exit 2 ;; | |
234 | "err_no_spec_in_repo" ) | |
235 | echo "Error: spec file not stored in CVS repo."; | |
236 | exit 3 ;; | |
237 | "err_no_source_in_repo" ) | |
4849ca8d | 238 | echo "Error: some source, patch or icon files not stored in CVS repo. ($2)"; |
33f5276d | 239 | exit 4 ;; |
240 | "err_build_fail" ) | |
298c753e | 241 | echo "Error: package build failed. (${2:-no more info})"; |
33f5276d | 242 | exit 5 ;; |
243 | esac | |
244 | } | |
bc8d444f | 245 | |
33f5276d | 246 | init_builder() |
247 | { | |
00fcec7e | 248 | if [ -n "$DEBUG" ]; then |
71d62f04 | 249 | set -x; |
00fcec7e | 250 | set -v; |
71d62f04 | 251 | fi |
7c2dd1b2 | 252 | |
7147050f AM |
253 | SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`" |
254 | SPECS_DIR="`$RPM --eval '%{_specdir}'`" | |
bc8d444f | 255 | |
33f5276d | 256 | __PWD=`pwd` |
59398507 | 257 | } |
258 | ||
259 | get_spec() | |
260 | { | |
00fcec7e | 261 | if [ -n "$DEBUG" ]; then |
71d62f04 | 262 | set -x; |
00fcec7e | 263 | set -v; |
71d62f04 | 264 | fi |
7c2dd1b2 | 265 | |
6fc910c7 | 266 | if [ "$NOCVSSPEC" != "yes" ]; then |
267 | cd $SPECS_DIR | |
5644bf7e | 268 | |
6fc910c7 | 269 | OPTIONS="up " |
67fcd1e4 | 270 | |
6fc910c7 | 271 | if [ -n "$CVSROOT" ]; then |
272 | OPTIONS="-d $CVSROOT $OPTIONS" | |
273 | else | |
274 | if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then | |
275 | echo "warning: No cvs access defined - using local .spec file" | |
276 | NOCVSSPEC="yes" | |
277 | fi | |
278 | fi | |
00fcec7e | 279 | |
72e08ca8 | 280 | if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then |
6fc910c7 | 281 | OPTIONS="$OPTIONS -A" |
72e08ca8 AM |
282 | else |
283 | if [ -n "$CVSDATE" ]; then | |
284 | OPTIONS="$OPTIONS -D $CVSDATE" | |
285 | fi | |
286 | if [ -n "$CVSTAG" ]; then | |
287 | OPTIONS="$OPTIONS -r $CVSTAG" | |
288 | fi | |
6fc910c7 | 289 | fi |
33f5276d | 290 | |
b92ecfc9 AM |
291 | result=1 |
292 | retries_counter=0 | |
293 | while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do | |
294 | retries_counter=$(( $retries_counter + 1 )) | |
295 | output=$(LC_ALL=C cvs $OPTIONS $SPECFILE 2>&1) | |
296 | result=$? | |
fef1dc85 | 297 | [ -n "$output" ] && echo "$output" |
b92ecfc9 | 298 | if [ "$result" -ne "0" ]; then |
67a44175 | 299 | if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$retries_counter" -le "$CVS_RETRIES" ]; then |
ee004885 | 300 | echo "Trying again [$SPECFILE]... ($retries_counter)" |
96686ae5 | 301 | sleep 2 |
b92ecfc9 AM |
302 | continue |
303 | fi | |
304 | Exit_error err_no_spec_in_repo; | |
305 | fi | |
306 | done | |
33f5276d | 307 | fi |
6fc910c7 | 308 | if [ ! -f "$SPECFILE" ]; then |
b857906d | 309 | Exit_error err_no_spec_in_repo; |
6fc910c7 | 310 | fi |
a7af9862 | 311 | |
d013b3df | 312 | if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then |
7922b3ec | 313 | chmod $CHMOD_MODE $SPECFILE |
5aa0ef93 | 314 | fi |
7c2dd1b2 | 315 | unset OPTIONS |
67da0368 | 316 | grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE |
59398507 | 317 | } |
318 | ||
4ca52257 JK |
319 | find_mirror(){ |
320 | ||
321 | cd "$SPECS_DIR" | |
00fcec7e | 322 | url="$1" |
323 | if [ ! -f "mirrors" ] ; then | |
324 | cvs update mirrors >&2 | |
4ca52257 JK |
325 | fi |
326 | ||
327 | IFS="|" | |
328 | while read origin mirror name rest; do | |
00fcec7e | 329 | ol=`echo -n "$origin"|wc -c` |
4ca52257 JK |
330 | prefix="`echo -n "$url" | head -c $ol`" |
331 | if [ "$prefix" = "$origin" ] ; then | |
6fc910c7 | 332 | suffix="`echo "$url"|cut -b $ol-`" |
333 | echo -n "$mirror$suffix" | |
334 | return 0 | |
4ca52257 JK |
335 | fi |
336 | done < mirrors | |
337 | echo "$url" | |
338 | } | |
339 | ||
00fcec7e | 340 | src_no () |
341 | { | |
342 | cd $SPECS_DIR | |
343 | $RPMBUILD -bp $BCOND --define 'prep %dump' $SPECFILE 2>&1 | \ | |
12b959d0 | 344 | grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \ |
00fcec7e | 345 | sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \ |
1c92b7b8 | 346 | head -1 | xargs |
00fcec7e | 347 | } |
348 | ||
349 | src_md5 () | |
350 | { | |
351 | no=$(src_no "$1") | |
352 | [ -z "$no" ] && return | |
353 | cd $SPECS_DIR | |
1c92b7b8 | 354 | grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://' | xargs |
00fcec7e | 355 | } |
356 | ||
357 | distfiles_url () | |
358 | { | |
8963720e | 359 | echo "$DISTFILES_SERVER/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")" |
00fcec7e | 360 | } |
361 | ||
d99ac371 MM |
362 | good_md5 () |
363 | { | |
364 | md5=$(src_md5 "$1") | |
365 | [ "$md5" = "" ] || \ | |
366 | [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ] | |
367 | } | |
368 | ||
25fa34fe | 369 | get_files() |
59398507 | 370 | { |
25fa34fe AM |
371 | GET_FILES="$@" |
372 | ||
00fcec7e | 373 | if [ -n "$DEBUG" ]; then |
71d62f04 | 374 | set -x; |
00fcec7e | 375 | set -v; |
71d62f04 | 376 | fi |
7c2dd1b2 | 377 | |
25fa34fe | 378 | if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then |
7053d3fd | 379 | cd $SOURCE_DIR |
33f5276d | 380 | |
82c46005 | 381 | OPTIONS="up " |
7053d3fd | 382 | if [ -n "$CVSROOT" ]; then |
c1e79fcd | 383 | OPTIONS="-d $CVSROOT $OPTIONS" |
6fc910c7 | 384 | else |
385 | if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then | |
386 | echo "warning: No cvs access defined for SOURCES" | |
387 | NOCVS="yes" | |
388 | fi | |
67fcd1e4 | 389 | fi |
72e08ca8 AM |
390 | if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then |
391 | OPTIONS="$OPTIONS -A" | |
392 | else | |
393 | if [ -n "$CVSDATE" ]; then | |
394 | OPTIONS="$OPTIONS -D $CVSDATE" | |
395 | fi | |
396 | if [ -n "$CVSTAG" ]; then | |
397 | OPTIONS="$OPTIONS -r $CVSTAG" | |
398 | fi | |
399 | fi | |
25fa34fe | 400 | for i in $GET_FILES; do |
7922b3ec | 401 | if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ]; then |
4a0bb672 | 402 | if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then |
6fc910c7 | 403 | echo "Warning: no URL given for $i" |
157dc315 | 404 | fi |
a7af9862 | 405 | |
fc0e5bb5 | 406 | if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then |
d99ac371 | 407 | if good_md5 "$i"; then |
f67349b7 | 408 | echo "$(nourl "$i") having proper md5sum already exists" |
409 | continue | |
410 | fi | |
00fcec7e | 411 | target=$(nourl "$i") |
412 | url=$(distfiles_url "$i") | |
6aefe77b JR |
413 | if [ `echo $url | grep -E '^(\.|/)'` ] ; then |
414 | ${GETLOCAL} $url $target | |
415 | else | |
416 | if [ -z "$NOMIRRORS" ] ; then | |
417 | url="`find_mirror "$url"`" | |
00fcec7e | 418 | fi |
6aefe77b JR |
419 | ${GETURI} -O "$target" "$url" || \ |
420 | if [ `echo $url | grep -E 'ftp://'` ]; then | |
421 | ${GETURI2} -O "$target" "$url" | |
422 | fi | |
423 | test -s "$target" || rm -f "$target" | |
424 | fi | |
de6b5b2a MM |
425 | elif [ -z "$(src_md5 "$i")" ] && \ |
426 | ( [ -z "$NOCVS" ] || echo $i | grep -qvE '(ftp|http|https)://' ); then | |
b92ecfc9 AM |
427 | result=1 |
428 | retries_counter=0 | |
429 | while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do | |
430 | retries_counter=$(( $retries_counter + 1 )) | |
431 | output=$(LC_ALL=C cvs $OPTIONS `nourl $i` 2>&1) | |
432 | result=$? | |
fef1dc85 | 433 | [ -n "$output" ] && echo "$output" |
67a44175 | 434 | if (echo "$output" | grep -qE "(Cannot connect to|connect to .* failed|Connection reset by peer|Connection timed out)") && [ "$result" -ne "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; then |
ee004885 | 435 | echo "Trying again [`nourl $i`]... ($retries_counter)" |
96686ae5 | 436 | sleep 2 |
b92ecfc9 | 437 | continue |
711eb1e4 AM |
438 | else |
439 | break | |
b92ecfc9 AM |
440 | fi |
441 | done | |
157dc315 | 442 | fi |
a7af9862 | 443 | |
b130abf2 | 444 | if [ -z "$NOURLS" ] && [ ! -f "`nourl $i`" -o -n "$UPDATE" ] && [ `echo $i | grep -E 'ftp://|http://|https://'` ]; then |
00fcec7e | 445 | if [ -z "$NOMIRRORS" ] ; then |
6fc910c7 | 446 | i="`find_mirror "$i"`" |
447 | fi | |
448 | ${GETURI} "$i" || \ | |
449 | if [ `echo $i | grep -E 'ftp://'` ]; then ${GETURI2} "$i" ; fi | |
157dc315 SZ |
450 | fi |
451 | ||
de6b5b2a | 452 | |
12f74c10 | 453 | srcno=$(src_no $i) |
c6a390a1 | 454 | if [ ! -f "`nourl $i`" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then |
6fc910c7 | 455 | Exit_error err_no_source_in_repo $i; |
de6b5b2a | 456 | elif [ -n "$UPDATE5" ] && \ |
12f74c10 MM |
457 | ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \ |
458 | [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'[^0-9]' $SPECS_DIR/$SPECFILE)" ] ) || \ | |
de6b5b2a MM |
459 | grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE ) |
460 | then | |
de6b5b2a MM |
461 | echo "Updating source-$srcno md5." |
462 | md5=$(md5sum `nourl $i` | cut -f1 -d' ') | |
463 | perl -i -ne 'print "# Source'$srcno'-md5:\t'$md5'\n" | |
464 | if /^Source'$srcno'\s*:\s+/; | |
465 | print unless /^\s*#\s*Source'$srcno'-md5\s*:/i' \ | |
466 | $SPECS_DIR/$SPECFILE | |
cc97f1f3 | 467 | fi |
d99ac371 MM |
468 | |
469 | if good_md5 "$i"; then | |
470 | : | |
471 | else | |
472 | echo "MD5 sum mismatch. Use -U to refetch sources," | |
473 | echo "or -5 to update md5 sums, if you're sure files are correct." | |
474 | Exit_error err_no_source_in_repo $i | |
475 | fi | |
3ae81a20 | 476 | fi |
cc97f1f3 | 477 | done |
a7af9862 | 478 | |
5aa0ef93 | 479 | if [ "$CHMOD" = "yes" ]; then |
d013b3df AM |
480 | CHMOD_FILES="`nourl $GET_FILES`" |
481 | if [ -n "$CHMOD_FILES" ]; then | |
6fc910c7 | 482 | chmod $CHMOD_MODE $CHMOD_FILES |
d013b3df | 483 | fi |
5aa0ef93 | 484 | fi |
7c2dd1b2 | 485 | unset OPTIONS |
7053d3fd | 486 | fi |
59398507 | 487 | } |
488 | ||
1471f6d6 | 489 | tag_files() |
490 | { | |
491 | TAG_FILES="$@" | |
492 | ||
00fcec7e | 493 | if [ -n "$DEBUG" ]; then |
1471f6d6 | 494 | set -x; |
00fcec7e | 495 | set -v; |
1471f6d6 | 496 | fi |
497 | ||
498 | if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then | |
499 | echo $PACKAGE_VERSION | |
500 | echo $PACKAGE_RELEASE | |
b4fd0ec0 | 501 | TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"` |
01de2036 JB |
502 | if [ "$TAG_VERSION" = "yes" ]; then |
503 | echo "CVS tag: $TAGVER" | |
504 | fi | |
505 | if [ -n "$TAG" ]; then | |
506 | echo "CVS tag: $TAG" | |
507 | fi | |
1471f6d6 | 508 | |
509 | OPTIONS="tag -F" | |
510 | if [ -n "$CVSROOT" ]; then | |
511 | OPTIONS="-d $CVSROOT $OPTIONS" | |
512 | fi | |
513 | ||
514 | cd $SOURCE_DIR | |
515 | for i in $TAG_FILES; do | |
516 | if [ -f `nourl $i` ]; then | |
f02788de JB |
517 | if [ "$TAG_VERSION" = "yes" ]; then |
518 | cvs $OPTIONS $TAGVER `nourl $i` | |
519 | fi | |
520 | if [ -n "$TAG" ]; then | |
521 | cvs $OPTIONS $TAG `nourl $i` | |
522 | fi | |
1471f6d6 | 523 | else |
4849ca8d | 524 | Exit_error err_no_source_in_repo $i |
1471f6d6 | 525 | fi |
526 | done | |
527 | ||
528 | cd $SPECS_DIR | |
f02788de JB |
529 | if [ "$TAG_VERSION" = "yes" ]; then |
530 | cvs $OPTIONS $TAGVER $SPECFILE | |
531 | fi | |
532 | if [ -n "$TAG" ]; then | |
533 | cvs $OPTIONS $TAG $SPECFILE | |
534 | fi | |
1471f6d6 | 535 | |
536 | unset OPTIONS | |
537 | fi | |
538 | } | |
539 | ||
8ba5cdda PG |
540 | branch_files() |
541 | { | |
a7af9862 | 542 | TAG=$1 |
543 | echo "CVS branch tag: $TAG" | |
544 | shift; | |
8ba5cdda | 545 | |
a7af9862 | 546 | TAG_FILES="$@" |
8ba5cdda | 547 | |
a7af9862 | 548 | if [ -n "$DEBUG" ]; then |
549 | set -x; | |
550 | set -v; | |
551 | fi | |
8ba5cdda | 552 | |
a7af9862 | 553 | if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then |
554 | ||
555 | OPTIONS="tag -b" | |
556 | if [ -n "$CVSROOT" ]; then | |
557 | OPTIONS="-d $CVSROOT $OPTIONS" | |
8ba5cdda | 558 | fi |
a7af9862 | 559 | cd $SOURCE_DIR |
560 | for i in $TAG_FILES; do | |
561 | if [ -f `nourl $i` ]; then | |
562 | cvs $OPTIONS $TAG `nourl $i` | |
563 | else | |
564 | Exit_error err_no_source_in_repo $i | |
565 | fi | |
566 | done | |
567 | cd $SPECS_DIR | |
568 | cvs $OPTIONS $TAG $SPECFILE | |
569 | ||
570 | unset OPTIONS | |
571 | fi | |
8ba5cdda PG |
572 | } |
573 | ||
f308b816 | 574 | |
575 | ||
59398507 | 576 | build_package() |
577 | { | |
00fcec7e | 578 | if [ -n "$DEBUG" ]; then |
7922b3ec | 579 | set -x; |
00fcec7e | 580 | set -v; |
71d62f04 | 581 | fi |
7c2dd1b2 | 582 | |
33f5276d | 583 | cd $SPECS_DIR |
3d97a432 | 584 | |
00fcec7e | 585 | if [ -n "$TRY_UPGRADE" ]; then |
a7af9862 | 586 | |
587 | if [ -n "FLOAT_VERSION" ]; then | |
588 | TNOTIFY=`./pldnotify.awk $SPECFILE -n` | |
589 | else | |
590 | TNOTIFY=`./pldnotify.awk $SPECFILE` | |
591 | fi | |
592 | ||
3d97a432 | 593 | TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'` |
a7af9862 | 594 | |
0096b1ae | 595 | if [ -n "$TNEWVER" ]; then |
a7af9862 | 596 | |
3d97a432 | 597 | TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'` |
a7af9862 | 598 | |
3d97a432 | 599 | echo "New version found, updating spec file to version " $TNEWVER |
a7af9862 | 600 | |
3d97a432 | 601 | cp -f $SPECFILE $SPECFILE.bak |
a7af9862 | 602 | |
3d97a432 | 603 | chmod +w $SPECFILE |
a7af9862 | 604 | |
3d97a432 MK |
605 | eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE" |
606 | eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t1/' $SPECFILE" | |
a7af9862 | 607 | |
3d97a432 | 608 | parse_spec; |
a7af9862 | 609 | |
3d97a432 | 610 | get_files "$SOURCES $PATCHES"; |
a7af9862 | 611 | |
3d97a432 MK |
612 | unset TOLDVER TNEWVER TNOTIFY |
613 | fi | |
00fcec7e | 614 | |
3d97a432 MK |
615 | fi |
616 | ||
617 | ||
618 | cd $SPECS_DIR | |
619 | ||
79b2ec0e | 620 | case "$COMMAND" in |
621 | build ) | |
7922b3ec | 622 | BUILD_SWITCH="-ba" ;; |
79b2ec0e | 623 | build-binary ) |
624 | BUILD_SWITCH="-bb" ;; | |
625 | build-source ) | |
956d1492 | 626 | BUILD_SWITCH="-bs --nodeps" ;; |
79b2ec0e | 627 | esac |
d6a75d60 | 628 | if [ -n "$LOGFILE" ]; then |
00fcec7e | 629 | if [ -n "$CVSTAG" ]; then |
630 | LTAG="r_`echo $CVSTAG|sed -e 's/\./_/g'`_" | |
631 | else | |
632 | LTAG="" | |
633 | fi | |
972bd3c3 | 634 | LOG=`eval echo $LOGFILE` |
00fcec7e | 635 | if [ -n "$LASTLOG_FILE" ]; then |
636 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
637 | fi | |
638 | RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM | |
639 | (nice -n ${DEF_NICE_LEVEL} time $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE; echo $? > $RES_FILE) 2>&1 |tee $LOG | |
640 | RETVAL=`cat $RES_FILE` | |
641 | rm $RES_FILE | |
642 | if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then | |
643 | if [ "$RETVAL" -eq "0" ]; then | |
644 | mv $LOG $LOGDIROK | |
645 | else | |
646 | mv $LOG $LOGDIRFAIL | |
647 | fi | |
648 | fi | |
d6a75d60 | 649 | else |
7147050f | 650 | eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $SPECFILE |
f308b816 | 651 | RETVAL=$? |
d6a75d60 | 652 | fi |
33f5276d | 653 | |
f308b816 | 654 | if [ "$RETVAL" -ne "0" ]; then |
a7af9862 | 655 | |
00fcec7e | 656 | if [ -n "$TRY_UPGRADE" ]; then |
3d97a432 | 657 | echo "\n!!! Package with new version cannot be build automagically\n" |
3d97a432 | 658 | mv -f $SPECFILE.bak $SPECFILE |
3d97a432 | 659 | fi |
a7af9862 | 660 | |
33f5276d | 661 | Exit_error err_build_fail; |
662 | fi | |
a7af9862 | 663 | |
79b2ec0e | 664 | unset BUILD_SWITCH |
59398507 | 665 | } |
666 | ||
cc97f1f3 SZ |
667 | nourl() |
668 | { | |
a7af9862 | 669 | echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g' |
cc97f1f3 | 670 | } |
da946cd6 | 671 | #--------------------------------------------- |
672 | # main() | |
673 | ||
ba877a00 | 674 | if [ "$#" = 0 ]; then |
da946cd6 | 675 | usage; |
d764d255 | 676 | exit 1 |
da946cd6 | 677 | fi |
678 | ||
5a491465 | 679 | while test $# -gt 0 ; do |
680 | case "${1}" in | |
de6b5b2a | 681 | -5 | --update-md5 ) |
a9d9a79a TP |
682 | COMMAND="get"; |
683 | NODIST="yes" | |
684 | UPDATE5="yes" | |
685 | shift ;; | |
de6b5b2a MM |
686 | -a5 | --add-md5 ) |
687 | COMMAND="get"; | |
688 | NODIST="yes" | |
689 | NOCVS="yes" | |
690 | UPDATE5="yes" | |
691 | ADD5="yes" | |
692 | shift ;; | |
7c2dd1b2 | 693 | -D | --debug ) |
694 | DEBUG="yes"; shift ;; | |
bde1c404 | 695 | -V | --version ) |
4003ad8c | 696 | COMMAND="version"; shift ;; |
bde1c404 | 697 | -a | --as_anon ) |
62546902 | 698 | CVSROOT=":pserver:cvs@$CVS_SERVER:/cvsroot"; shift ;; |
79b2ec0e | 699 | -b | -ba | --build ) |
4003ad8c | 700 | COMMAND="build"; shift ;; |
79b2ec0e | 701 | -bb | --build-binary ) |
702 | COMMAND="build-binary"; shift ;; | |
703 | -bs | --build-source ) | |
704 | COMMAND="build-source"; shift ;; | |
8ba5cdda PG |
705 | -B | --branch ) |
706 | COMMAND="branch"; shift; TAG="${1}"; shift;; | |
5dd89621 | 707 | -c | --clean ) |
708 | CLEAN="--clean --rmspec --rmsource"; shift ;; | |
bde1c404 | 709 | -d | --cvsroot ) |
4003ad8c | 710 | shift; CVSROOT="${1}"; shift ;; |
bde1c404 | 711 | -g | --get ) |
712 | COMMAND="get"; shift ;; | |
713 | -h | --help ) | |
714 | COMMAND="usage"; shift ;; | |
5a491465 | 715 | -l | --logtofile ) |
4003ad8c | 716 | shift; LOGFILE="${1}"; shift ;; |
3ae81a20 | 717 | -ni| --nice ) |
718 | shift; DEF_NICE_LEVEL=${1}; shift ;; | |
8bc51224 | 719 | -m | --mr-proper ) |
720 | COMMAND="mr-proper"; shift ;; | |
157dc315 SZ |
721 | -nc | --no-cvs ) |
722 | NOCVS="yes"; shift ;; | |
37f54b4a | 723 | -ncs | --no-cvs-specs ) |
6fc910c7 | 724 | NOCVSSPEC="yes"; shift ;; |
fc0e5bb5 TP |
725 | -nd | --no-distfiles ) |
726 | NODIST="yes"; shift ;; | |
4ca52257 JK |
727 | -nm | --no-mirrors ) |
728 | NOMIRRORS="yes"; shift ;; | |
157dc315 SZ |
729 | -nu | --no-urls ) |
730 | NOURLS="yes"; shift ;; | |
72fb89b5 | 731 | -ns | --no-srcs ) |
732 | NOSRCS="yes"; shift ;; | |
fd2b5687 MM |
733 | -ns0 | --no-source0 ) |
734 | NOSOURCE0="yes"; shift ;; | |
33a9d2d1 SZ |
735 | --opts ) |
736 | shift; RPMOPTS="${1}"; shift ;; | |
6049c3d1 | 737 | --with | --without ) |
a2d6aca2 | 738 | BCOND="$BCOND $1 $2" ; shift 2 ;; |
bde1c404 | 739 | -q | --quiet ) |
33f5276d | 740 | QUIET="--quiet"; shift ;; |
448deaa0 | 741 | --date ) |
742 | CVSDATE="${2}"; shift 2 ;; | |
67fcd1e4 | 743 | -r | --cvstag ) |
744 | shift; CVSTAG="${1}"; shift ;; | |
78ce14b3 | 745 | -Tvs | --tag-version-stable ) |
7922b3ec | 746 | COMMAND="tag"; |
78ce14b3 | 747 | TAG="STABLE" |
7922b3ec | 748 | TAG_VERSION="yes" |
749 | shift;; | |
a2164135 | 750 | -Tvn | --tag-version-nest ) |
7922b3ec | 751 | COMMAND="tag"; |
a2164135 | 752 | TAG="NEST" |
7922b3ec | 753 | TAG_VERSION="yes" |
754 | shift;; | |
78ce14b3 | 755 | -Ts | --tag-stable ) |
7922b3ec | 756 | COMMAND="tag"; |
78ce14b3 | 757 | TAG="STABLE" |
7922b3ec | 758 | TAG_VERSION="no" |
759 | shift;; | |
a2164135 | 760 | -Tn | --tag-nest ) |
7922b3ec | 761 | COMMAND="tag"; |
a2164135 | 762 | TAG="NEST" |
7922b3ec | 763 | TAG_VERSION="no" |
764 | shift;; | |
765 | -Tv | --tag-version ) | |
766 | COMMAND="tag"; | |
f02788de | 767 | TAG="" |
7922b3ec | 768 | TAG_VERSION="yes" |
769 | shift;; | |
1471f6d6 | 770 | -T | --tag ) |
7922b3ec | 771 | COMMAND="tag"; |
772 | shift | |
773 | TAG="$1" | |
774 | TAG_VERSION="no" | |
775 | shift;; | |
b130abf2 | 776 | -U | --update ) |
de6b5b2a MM |
777 | UPDATE="yes" |
778 | NODIST="yes" | |
779 | UPDATE5="yes" | |
780 | COMMAND="get" | |
781 | shift ;; | |
0096b1ae | 782 | -u | --try-upgrade ) |
3d97a432 | 783 | TRY_UPGRADE="1"; shift ;; |
a7af9862 | 784 | -un | --try-upgrade-with-float-version ) |
785 | TRY_UPGRADE="1"; FLOAT_VERSION="1"; shift ;; | |
b130abf2 TP |
786 | -v | --verbose ) |
787 | BE_VERBOSE="1"; shift ;; | |
c7ab67cf | 788 | --define) |
c24b056c | 789 | shift |
c7ab67cf SZ |
790 | MACRO="${1}" |
791 | VALUE="${2}" | |
792 | shift 2 | |
793 | RPMOPTS="${RPMOPTS} --define \"${MACRO} ${VALUE}\"" | |
794 | ;; | |
bde1c404 | 795 | * ) |
0fc6e9ec | 796 | SPECFILE="`basename ${1} .spec`.spec"; shift ;; |
5a491465 | 797 | esac |
798 | done | |
799 | ||
00fcec7e | 800 | if [ -n "$DEBUG" ]; then |
a7af9862 | 801 | set -x; |
00fcec7e | 802 | set -v; |
71d62f04 | 803 | fi |
7c2dd1b2 | 804 | |
bde1c404 | 805 | case "$COMMAND" in |
79b2ec0e | 806 | "build" | "build-binary" | "build-source" ) |
33f5276d | 807 | init_builder; |
8a7fc6f7 | 808 | if [ -n "$SPECFILE" ]; then |
59398507 | 809 | get_spec; |
810 | parse_spec; | |
298c753e AM |
811 | |
812 | if [ -n "$FAIL_IF_CHANGED_BUT_NOT_BUMPED" ]; then | |
b4fd0ec0 | 813 | TAGVER=$PACKAGE_NAME-`echo $PACKAGE_VERSION | sed -e "s/\./\_/g" -e "s/@/#/g"`-`echo $PACKAGE_RELEASE | sed -e "s/\./\_/g" -e "s/@/#/g"` |
298c753e | 814 | CURTAGREL=$(cvs status $SPECFILE | grep "Working revision:" | awk '{ print $3 }') |
1f188001 | 815 | TAGREL=$(cvs status -v $SPECFILE | grep -E "^[[:space:]]*${TAGVER}[[[:space:]]" | sed -e 's#.*(revision: ##g' -e 's#).*##g') |
298c753e AM |
816 | |
817 | if [ -n "$TAGREL" -a "$TAGREL" != "$CURTAGREL" ]; then | |
818 | Exit_error err_build_fail "not bumped ver-rel - was already used in rev $TAGREL" | |
819 | fi | |
820 | fi | |
821 | ||
25fa34fe | 822 | if [ -n "$ICONS" ]; then |
bc441b0c | 823 | get_files $ICONS; |
25fa34fe AM |
824 | parse_spec; |
825 | fi | |
f9a62a6a | 826 | if [ -n "$NOSOURCE0" ] ; then |
827 | SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'` | |
828 | fi | |
25fa34fe | 829 | get_files "$SOURCES $PATCHES"; |
59398507 | 830 | build_package; |
831 | else | |
33f5276d | 832 | Exit_error err_no_spec_in_cmdl; |
59398507 | 833 | fi |
834 | ;; | |
8ba5cdda PG |
835 | "branch" ) |
836 | init_builder; | |
837 | if [ -n "$SPECFILE" ]; then | |
838 | get_spec; | |
839 | parse_spec; | |
840 | if [ -n "$ICONS" ]; then | |
841 | get_files $ICONS | |
842 | parse_spec; | |
843 | fi | |
844 | get_files $SOURCES $PATCHES; | |
845 | branch_files $TAG "$SOURCES $PATCHES $ICONS"; | |
846 | else | |
847 | Exit_error err_no_spec_in_cmdl; | |
848 | fi | |
849 | ;; | |
bde1c404 | 850 | "get" ) |
33f5276d | 851 | init_builder; |
8a7fc6f7 | 852 | if [ -n "$SPECFILE" ]; then |
59398507 | 853 | get_spec; |
854 | parse_spec; | |
25fa34fe | 855 | if [ -n "$ICONS" ]; then |
7922b3ec | 856 | get_files $ICONS |
857 | parse_spec; | |
25fa34fe | 858 | fi |
fd2b5687 MM |
859 | if [ -n "$NOSOURCE0" ] ; then |
860 | SOURCES=`echo $SOURCES | xargs | sed -e 's/[^ ]*//'` | |
861 | fi | |
bc441b0c | 862 | get_files $SOURCES $PATCHES |
bde1c404 | 863 | else |
33f5276d | 864 | Exit_error err_no_spec_in_cmdl; |
bde1c404 | 865 | fi |
866 | ;; | |
1471f6d6 | 867 | "tag" ) |
868 | init_builder; | |
869 | if [ -n "$SPECFILE" ]; then | |
870 | get_spec; | |
871 | parse_spec; | |
872 | if [ -n "$ICONS" ]; then | |
7922b3ec | 873 | get_files $ICONS |
874 | parse_spec; | |
1471f6d6 | 875 | fi |
bc441b0c | 876 | get_files $SOURCES $PATCHES; |
1471f6d6 | 877 | tag_files "$SOURCES $PATCHES $ICONS"; |
878 | else | |
879 | Exit_error err_no_spec_in_cmdl; | |
880 | fi | |
881 | ;; | |
8bc51224 | 882 | "mr-proper" ) |
7147050f | 883 | $RPM --clean --rmsource --rmspec --force --nodeps $SPECFILE |
8bc51224 | 884 | ;; |
bde1c404 | 885 | "usage" ) |
886 | usage;; | |
4003ad8c | 887 | "version" ) |
888 | echo "$VERSION";; | |
bde1c404 | 889 | esac |
9e06e5c3 | 890 | |
891 | cd $__PWD |