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