]>
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 |
ebaff775 | 25 | v0.14 (C) 1999-2006 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 | ||
e225de91 ER |
301 | if [ -n "$BE_VERBOSE" ]; then |
302 | echo >&2 "$(date +%s.%N) $*" | |
303 | fi | |
304 | ||
f2e42a41 | 305 | msg="builder[$SPECFILE] ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg" |
c890b916 ER |
306 | case "$TERM" in |
307 | cygwin|xterm*) | |
2dddf439 | 308 | echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007" |
c890b916 ER |
309 | ;; |
310 | screen*) | |
2dddf439 | 311 | echo >&2 -ne "\033]0;$msg\007" |
c890b916 ER |
312 | ;; |
313 | esac | |
314 | } | |
315 | ||
7e40520f ER |
316 | # set TARGET from BuildArch: from SPECFILE |
317 | set_spec_target() { | |
318 | if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then | |
319 | tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE) | |
320 | if [ "$tmp" ]; then | |
321 | TARGET="$tmp" | |
322 | case "$RPMBUILD" in | |
323 | "rpmbuild") | |
324 | TARGET_SWITCH="--target $TARGET" ;; | |
325 | "rpm") | |
326 | TARGET_SWITCH="--target=$TARGET" ;; | |
327 | esac | |
328 | fi | |
329 | fi | |
330 | } | |
331 | ||
cd445739 | 332 | cache_rpm_dump () { |
b2aeec7d AM |
333 | if [ -n "$DEBUG" ]; then |
334 | set -x; | |
335 | set -v; | |
336 | fi | |
7e40520f | 337 | |
13974367 | 338 | update_shell_title "cache_rpm_dump" |
cd445739 | 339 | rpm_dump_cache=` |
fa4bf1df ER |
340 | # we reset macros not to contain macros.build as all the %() macros are |
341 | # executed here, while none of them are actually needed | |
342 | # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES. | |
343 | # macros.build + macros contained at the time of this writing 70 %() macros | |
7f41e74f | 344 | local macrofiles="/usr/lib/rpm/macros:$SPECS_DIR/.rpmmacros:~/etc/.rpmmacros:~/.rpmmacros" |
ebaff775 | 345 | local dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump' |
7cb24972 ER |
346 | # FIXME: better ideas than .rpmrc? |
347 | printf 'include:/usr/lib/rpm/rpmrc\nmacrofiles:%s\n' $macrofiles > .rpmrc | |
fb198857 ER |
348 | # TODO: move these to /usr/lib/rpm/macros |
349 | cat > .rpmmacros <<'EOF' | |
350 | %requires_releq_kernel_up %{nil} | |
351 | %requires_releq_kernel_smp %{nil} | |
bb01dee9 | 352 | %pyrequires_eq() %{nil} |
fb198857 ER |
353 | %releq_kernel_up ERROR |
354 | %releq_kernel_smp ERROR | |
355 | EOF | |
cd445739 AM |
356 | case "$RPMBUILD" in |
357 | rpm ) | |
7cb24972 | 358 | rpm --rcfile .rpmrc -bp --nodeps --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1 |
cd445739 AM |
359 | ;; |
360 | rpmbuild ) | |
c94b1395 | 361 | rpmbuild --rcfile .rpmrc --nodigest --nodeps --nosignature --nobuild --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1 |
cd445739 AM |
362 | ;; |
363 | esac` | |
fb198857 ER |
364 | if [ $? -gt 0 ]; then |
365 | echo "$rpm_dump_cache" | sed -ne '/^error:/,$p' >&2 | |
366 | Exit_error err_build_fail; | |
367 | fi | |
13974367 | 368 | update_shell_title "cache_rpm_dump: OK!" |
cd445739 AM |
369 | } |
370 | ||
371 | rpm_dump () { | |
372 | if [ -z "$rpm_dump_cache" ] ; then | |
373 | echo "internal error: cache_rpm_dump not called!" 1>&2 | |
374 | fi | |
375 | echo "$rpm_dump_cache" | |
376 | } | |
377 | ||
59398507 | 378 | parse_spec() |
379 | { | |
af4d5315 | 380 | update_shell_title "parsing specfile" |
cd445739 AM |
381 | if [ -n "$DEBUG" ]; then |
382 | set -x; | |
383 | set -v; | |
384 | fi | |
b2975fc3 | 385 | |
cd445739 | 386 | cd $SPECS_DIR |
cd445739 | 387 | cache_rpm_dump |
00fcec7e | 388 | |
cd445739 AM |
389 | if [ "$NOSRCS" != "yes" ]; then |
390 | SOURCES="`rpm_dump | awk '/SOURCEURL[0-9]+/ {print $3}'`" | |
391 | fi | |
7cb24972 | 392 | |
cd445739 AM |
393 | if (rpm_dump | grep -qEi ":.*nosource.*1"); then |
394 | FAIL_IF_NO_SOURCES="no" | |
395 | fi | |
396 | ||
397 | PATCHES="`rpm_dump | awk '/PATCHURL[0-9]+/ {print $3}'`" | |
398 | ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`" | |
fa4bf1df ER |
399 | PACKAGE_NAME=$(rpm_dump | awk '$2 == "PACKAGE_NAME" { print $3}') |
400 | PACKAGE_VERSION=$(rpm_dump | awk '$2 == "PACKAGE_VERSION" { print $3}') | |
401 | PACKAGE_RELEASE=$(rpm_dump | awk '$2 == "PACKAGE_RELEASE" { print $3}') | |
78eab2a1 | 402 | |
cd445739 AM |
403 | if [ -n "$BE_VERBOSE" ]; then |
404 | echo "- Sources : `nourl $SOURCES`" | |
405 | if [ -n "$PATCHES" ]; then | |
406 | echo "- Patches : `nourl $PATCHES`" | |
407 | else | |
408 | echo "- Patches : *no patches needed*" | |
409 | fi | |
410 | if [ -n "$ICONS" ]; then | |
411 | echo "- Icon : `nourl $ICONS`" | |
412 | else | |
413 | echo "- Icon : *no package icon*" | |
414 | fi | |
415 | echo "- Name : $PACKAGE_NAME" | |
416 | echo "- Version : $PACKAGE_VERSION" | |
417 | echo "- Release : $PACKAGE_RELEASE" | |
418 | fi | |
13974367 ER |
419 | |
420 | update_shell_title "parse_spec: OK!" | |
cd445739 AM |
421 | } |
422 | ||
423 | Exit_error() | |
424 | { | |
425 | if [ -n "$DEBUG" ]; then | |
426 | set -x; | |
427 | set -v; | |
428 | fi | |
429 | ||
430 | cd "$__PWD" | |
431 | ||
432 | case "$1" in | |
433 | "err_no_spec_in_cmdl" ) | |
434 | remove_build_requires | |
435 | echo "ERROR: spec file name not specified."; | |
436 | exit 2 ;; | |
437 | "err_no_spec_in_repo" ) | |
438 | remove_build_requires | |
439 | echo "Error: spec file not stored in CVS repo."; | |
440 | exit 3 ;; | |
441 | "err_no_source_in_repo" ) | |
442 | remove_build_requires | |
443 | echo "Error: some source, patch or icon files not stored in CVS repo. ($2)"; | |
444 | exit 4 ;; | |
445 | "err_build_fail" ) | |
446 | remove_build_requires | |
447 | echo "Error: package build failed. (${2:-no more info})"; | |
448 | exit 5 ;; | |
78eab2a1 AM |
449 | "err_no_package_data" ) |
450 | remove_build_requires | |
451 | echo "Error: couldn't get out package name/version/release from spec file." | |
452 | exit 6 ;; | |
50321881 JK |
453 | "err_tag_exists" ) |
454 | remove_build_requires | |
455 | echo "Tag ${2} already exists (spec release: ${3})."; | |
456 | exit 9 ;; | |
457 | "err_fract_rel" ) | |
458 | remove_build_requires | |
459 | echo "Release ${2} not integer and not a snapshot."; | |
460 | exit 10 ;; | |
fb96e0b5 AM |
461 | "err_branch_exists" ) |
462 | remove_build_requires | |
463 | echo "Tree branch already exists (${2})."; | |
464 | exit 11 ;; | |
50321881 | 465 | |
cd445739 | 466 | esac |
50321881 | 467 | echo "Unknown error." |
2a5f078d | 468 | exit 100 |
cd445739 AM |
469 | } |
470 | ||
471 | init_builder() | |
472 | { | |
473 | if [ -n "$DEBUG" ]; then | |
474 | set -x; | |
475 | set -v; | |
0dd6320d | 476 | fi |
cd445739 AM |
477 | |
478 | SOURCE_DIR="`$RPM --eval '%{_sourcedir}'`" | |
479 | SPECS_DIR="`$RPM --eval '%{_specdir}'`" | |
480 | ||
481 | __PWD="`pwd`" | |
00fcec7e | 482 | } |
483 | ||
d6a77ddb | 484 | get_spec() |
1471f6d6 | 485 | { |
c890b916 | 486 | |
2e5be021 | 487 | update_shell_title "get_spec" |
c890b916 | 488 | |
cd445739 AM |
489 | if [ -n "$DEBUG" ]; then |
490 | set -x; | |
491 | set -v; | |
492 | fi | |
493 | ||
494 | cd "$SPECS_DIR" | |
049ab214 | 495 | if [ ! -f "$SPECFILE" ]; then |
cd445739 AM |
496 | SPECFILE="`basename $SPECFILE .spec`.spec"; |
497 | fi | |
498 | if [ "$NOCVSSPEC" != "yes" ]; then | |
cd445739 | 499 | |
049ab214 ER |
500 | if [ ! -s CVS/Root -a "$NOCVSSPEC" != "yes" ]; then |
501 | echo "Warning: No CVS access defined - using local .spec file" | |
502 | NOCVSSPEC="yes" | |
cd445739 AM |
503 | fi |
504 | ||
049ab214 | 505 | cvsup "$SPECFILE" || Exit_error err_no_spec_in_repo |
cd445739 | 506 | fi |
049ab214 | 507 | |
cd445739 AM |
508 | if [ ! -f "$SPECFILE" ]; then |
509 | Exit_error err_no_spec_in_repo; | |
510 | fi | |
511 | ||
512 | if [ "$CHMOD" = "yes" -a -n "$SPECFILE" ]; then | |
513 | chmod $CHMOD_MODE $SPECFILE | |
514 | fi | |
515 | unset OPTIONS | |
a7eefc54 | 516 | [ -n "$DONT_PRINT_REVISION" ] || grep -E -m 1 "^#.*Revision:.*Date" $SPECFILE |
7e40520f ER |
517 | |
518 | set_spec_target | |
cd445739 AM |
519 | } |
520 | ||
521 | find_mirror() | |
522 | { | |
523 | cd "$SPECS_DIR" | |
524 | url="$1" | |
525 | if [ ! -f "mirrors" -a "$NOCVSSPEC" != "yes" ] ; then | |
526 | cvs update mirrors >&2 | |
527 | fi | |
528 | ||
529 | IFS="|" | |
530 | while read origin mirror name rest | |
531 | do | |
532 | ol=`echo -n "$origin"|wc -c` | |
533 | prefix="`echo -n "$url" | head -c $ol`" | |
534 | if [ "$prefix" = "$origin" ] ; then | |
535 | suffix="`echo "$url"|cut -b $ol-`" | |
536 | echo -n "$mirror$suffix" | |
537 | return 0 | |
538 | fi | |
539 | done < mirrors | |
540 | echo "$url" | |
541 | } | |
542 | ||
543 | src_no () | |
544 | { | |
545 | cd $SPECS_DIR | |
546 | rpm_dump | \ | |
547 | grep "SOURCEURL[0-9]*[ ]*$1""[ ]*$" | \ | |
548 | sed -e 's/.*SOURCEURL\([0-9][0-9]*\).*/\1/' | \ | |
549 | head -n 1 | xargs | |
1471f6d6 | 550 | } |
551 | ||
cd445739 | 552 | src_md5 () |
8ba5cdda | 553 | { |
cd445739 AM |
554 | [ X"$NO5" = X"yes" ] && return |
555 | no=$(src_no "$1") | |
556 | [ -z "$no" ] && return | |
557 | cd $SPECS_DIR | |
47a8df12 | 558 | spec_rev=$(grep $SPECFILE CVS/Entries 2>/dev/null | sed -e s:/$SPECFILE/:: -e s:/.*::) |
cd445739 AM |
559 | if [ -z "$spec_rev" ]; then |
560 | spec_rev="$(head -n 1 $SPECFILE | sed -e 's/.*\$Revision: \([0-9.]*\).*/\1/')" | |
561 | fi | |
562 | spec="$SPECFILE[0-9.,]*,$(echo $spec_rev | sed 's/\./\\./g')" | |
563 | md5=$(grep -s -v '^#' additional-md5sums | \ | |
564 | grep -E "[ ]$(basename "$1")[ ]+${spec}([ ,]|\$)" | \ | |
565 | sed -e 's/^\([0-9a-f]\{32\}\).*/\1/' | \ | |
566 | grep -E '^[0-9a-f]{32}$') | |
567 | if [ X"$md5" = X"" ] ; then | |
6203ea52 AG |
568 | source_md5=`grep -i "#[ ]*Source$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` |
569 | if [ ! -z "$source_md5" ] ; then | |
7e365483 | 570 | echo $source_md5; |
6203ea52 | 571 | else |
7e365483 KK |
572 | # we have empty SourceX-md5, but it is still possible |
573 | # that we have NoSourceX-md5 AND NoSource: X | |
574 | nosource_md5=`grep -i "#[ ]*NoSource$no-md5[ ]*:" $SPECFILE | sed -e 's/.*://'` | |
575 | if [ ! -z "$nosource_md5" -a ! X"`grep -i "^NoSource:[ ]*$no$" $SPECFILE`" = X"" ] ; then | |
576 | echo $nosource_md5; | |
577 | fi; | |
6203ea52 | 578 | fi; |
cd445739 AM |
579 | else |
580 | if [ $(echo "$md5" | wc -l) != 1 ] ; then | |
581 | echo "$SPECFILE: more then one entry in additional-md5sums for $1" 1>&2 | |
582 | fi | |
583 | echo "$md5" | tail -n 1 | |
584 | fi | |
585 | } | |
586 | ||
587 | distfiles_url () | |
588 | { | |
1246dc2a | 589 | echo "$PROTOCOL$DISTFILES_SERVER/distfiles/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")" |
cd445739 AM |
590 | } |
591 | ||
592 | distfiles_attic_url () | |
593 | { | |
1246dc2a | 594 | echo "$PROTOCOL$ATTICDISTFILES_SERVER/distfiles/Attic/by-md5/$(src_md5 "$1" | sed -e 's|^\(.\)\(.\)|\1/\2/&|')/$(basename "$1")" |
cd445739 AM |
595 | } |
596 | ||
597 | good_md5 () | |
598 | { | |
599 | md5=$(src_md5 "$1") | |
600 | [ "$md5" = "" ] || \ | |
601 | [ "$md5" = "$(md5sum $(nourl "$1") 2> /dev/null | sed -e 's/ .*//')" ] | |
8ba5cdda PG |
602 | } |
603 | ||
a4b50627 AF |
604 | good_size () |
605 | { | |
deccc50e AM |
606 | size="$(find $(nourl "$1") -printf "%s" 2>/dev/null)" |
607 | [ -n "$size" -a "$size" -gt 0 ] | |
a4b50627 AF |
608 | } |
609 | ||
947025e5 | 610 | cvsignore_df () |
611 | { | |
612 | if [ "$CVSIGNORE_DF" != "yes" ]; then | |
613 | return | |
614 | fi | |
615 | cvsignore=${SOURCE_DIR}/.cvsignore | |
616 | if ! grep -q "^$1\$" $cvsignore 2> /dev/null; then | |
617 | echo "$1" >> $cvsignore | |
618 | fi | |
619 | } | |
620 | ||
e7fa3b9f ER |
621 | cvsup() |
622 | { | |
623 | update_shell_title "cvsup" | |
624 | local OPTIONS="up " | |
625 | if [ -n "$CVSROOT" ]; then | |
626 | OPTIONS="-d $CVSROOT $OPTIONS" | |
e7fa3b9f | 627 | fi |
b1c6aace | 628 | |
e7fa3b9f ER |
629 | if [ -z "$CVSDATE" -a -z "$CVSTAG" ]; then |
630 | OPTIONS="$OPTIONS -A" | |
631 | else | |
632 | if [ -n "$CVSDATE" ]; then | |
633 | OPTIONS="$OPTIONS -D $CVSDATE" | |
634 | fi | |
635 | if [ -n "$CVSTAG" ]; then | |
636 | OPTIONS="$OPTIONS -r $CVSTAG" | |
637 | fi | |
638 | fi | |
639 | ||
640 | local result=1 | |
641 | local retries_counter=0 | |
642 | update_shell_title "cvsup: $# files" | |
643 | while [ "$result" != "0" -a "$retries_counter" -le "$CVS_RETRIES" ]; do | |
644 | retries_counter=$(( $retries_counter + 1 )) | |
645 | output=$(LC_ALL=C cvs $OPTIONS "$@" 2>&1) | |
646 | result=$? | |
647 | [ -n "$output" ] && echo "$output" | |
648 | 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 | |
649 | echo "Trying again [$*]... ($retries_counter)" | |
650 | update_shell_title "cvsup: retry #$retries_counter" | |
651 | sleep 2 | |
652 | continue | |
653 | else | |
654 | break | |
655 | fi | |
656 | done | |
657 | update_shell_title "cvsup: done!" | |
049ab214 | 658 | return $result |
e7fa3b9f ER |
659 | } |
660 | ||
cd445739 AM |
661 | get_files() |
662 | { | |
7cb24972 | 663 | update_shell_title "get_files" |
cd445739 AM |
664 | |
665 | if [ -n "$DEBUG" ]; then | |
666 | set -x; | |
667 | set -v; | |
668 | fi | |
669 | ||
f09c0772 | 670 | if [ $# -gt 0 ]; then |
cd445739 AM |
671 | cd "$SOURCE_DIR" |
672 | ||
b1c6aace | 673 | if [ ! -s CVS/Root -a "$NOCVS" != "yes" ]; then |
049ab214 | 674 | echo "Warning: No CVS access defined for SOURCES" |
b1c6aace ER |
675 | NOCVS="yes" |
676 | fi | |
677 | ||
f2e42a41 | 678 | local nc=0 |
e7fa3b9f | 679 | local get_files_cvs="" |
3815b69a | 680 | for i in "$@"; do |
f2e42a41 | 681 | nc=$((nc + 1)) |
dcebdffb | 682 | local cvsup=0 |
3815b69a | 683 | SHELL_TITLE_PREFIX="get_files[$nc/$#]" |
f2e42a41 | 684 | update_shell_title "$i" |
f09c0772 ER |
685 | local fp=`nourl "$i"` |
686 | if [ -f "$fp" ] && [ "$SKIP_EXISTING_FILES" = "yes" ]; then | |
18e5347d ER |
687 | continue |
688 | fi | |
cd445739 AM |
689 | if [ -n "$UPDATE5" ]; then |
690 | if [ -n "$ADD5" ]; then | |
f09c0772 | 691 | [ "$fp" = "$i" ] && continue |
cd445739 AM |
692 | grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue |
693 | else | |
694 | grep -qiE '^#[ ]*Source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue | |
695 | fi | |
696 | fi | |
697 | FROM_DISTFILES=0 | |
f09c0772 | 698 | if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then |
cd445739 AM |
699 | if echo $i | grep -vE '(http|ftp|https|cvs|svn)://' | grep -qE '\.(gz|bz2)$']; then |
700 | echo "Warning: no URL given for $i" | |
701 | fi | |
702 | ||
703 | if [ -n "$(src_md5 "$i")" ] && [ -z "$NODIST" ]; then | |
a4b50627 | 704 | if good_md5 "$i" && good_size "$i"; then |
deccc50e | 705 | echo "$(nourl "$i") having proper md5sum already exists" |
cd445739 AM |
706 | continue |
707 | fi | |
4ea1c265 | 708 | target="$fp" |
cd445739 AM |
709 | url=$(distfiles_url "$i") |
710 | url_attic=$(distfiles_attic_url "$i") | |
711 | FROM_DISTFILES=1 | |
33da77c4 | 712 | if [ "`echo $url | grep -E '^(\.|/)'`" ]; then |
18a52930 | 713 | update_shell_title "${GETLOCAL%% *}: $url" |
cd445739 AM |
714 | ${GETLOCAL} $url $target |
715 | else | |
716 | if [ -z "$NOMIRRORS" ]; then | |
717 | url="`find_mirror "$url"`" | |
718 | fi | |
18a52930 | 719 | update_shell_title "${GETURI%% *}: $url" |
ca2e6c31 | 720 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
33da77c4 | 721 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
18a52930 | 722 | update_shell_title "${GETURI2%% *}: $url" |
ca2e6c31 | 723 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 AM |
724 | fi |
725 | fi | |
726 | if ! test -s "$target"; then | |
727 | rm -f "$target" | |
728 | if [ `echo $url_attic | grep -E '^(\.|/)'` ]; then | |
18a52930 | 729 | update_shell_title "${GETLOCAL%% *}: $url_attic" |
cd445739 AM |
730 | ${GETLOCAL} $url_attic $target |
731 | else | |
732 | if [ -z "$NOMIRRORS" ]; then | |
733 | url_attic="`find_mirror "$url_attic"`" | |
734 | fi | |
18a52930 | 735 | update_shell_title "${GETURI%% *}: $url_attic" |
ca2e6c31 | 736 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
33da77c4 | 737 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
18a52930 | 738 | update_shell_title "${GETURI2%% *}: $url_attic" |
ca2e6c31 | 739 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 AM |
740 | fi |
741 | fi | |
742 | fi | |
947025e5 | 743 | if test -s "$target"; then |
744 | cvsignore_df $target | |
745 | else | |
cd445739 AM |
746 | rm -f "$target" |
747 | FROM_DISTFILES=0 | |
748 | fi | |
749 | elif [ -z "$(src_md5 "$i")" -a "$NOCVS" != "yes" ]; then | |
dcebdffb | 750 | get_files_cvs="$get_files_cvs $fp" |
51616f76 | 751 | update_shell_title "$fp (will cvs up later)" |
dcebdffb | 752 | cvsup=1 |
cd445739 AM |
753 | fi |
754 | ||
f09c0772 | 755 | if [ -z "$NOURLS" ] && [ ! -f "$fp" -o -n "$UPDATE" ] && [ "`echo $i | grep -E 'ftp://|http://|https://'`" ]; then |
cd445739 AM |
756 | if [ -z "$NOMIRRORS" ]; then |
757 | im="`find_mirror "$i"`" | |
758 | else | |
759 | im="$i" | |
760 | fi | |
18a52930 | 761 | update_shell_title "${GETURI%% *}: $im" |
cd445739 | 762 | ${GETURI} "$im" || \ |
33da77c4 | 763 | if [ "`echo $im | grep -E 'ftp://'`" ]; then |
18a52930 | 764 | update_shell_title "${GETURI2%% *}: $im" |
cd445739 | 765 | ${GETURI2} "$im" |
7e365483 | 766 | fi |
cd445739 AM |
767 | fi |
768 | ||
dcebdffb ER |
769 | if [ "$cvsup" = 1 ]; then |
770 | continue | |
771 | fi | |
772 | ||
cd445739 AM |
773 | fi |
774 | srcno=$(src_no $i) | |
f09c0772 | 775 | if [ ! -f "$fp" -a "$FAIL_IF_NO_SOURCES" != "no" ]; then |
cd445739 AM |
776 | Exit_error err_no_source_in_repo $i; |
777 | elif [ -n "$UPDATE5" ] && \ | |
778 | ( ( [ -n "$ADD5" ] && echo $i | grep -q -E 'ftp://|http://|https://' && \ | |
779 | [ -z "$(grep -E -i '^NoSource[ ]*:[ ]*'$i'([ ]|$)' $SPECS_DIR/$SPECFILE)" ] ) || \ | |
780 | grep -q -i -E '^#[ ]*source'$(src_no $i)'-md5[ ]*:' $SPECS_DIR/$SPECFILE ) | |
781 | then | |
deccc50e | 782 | echo "Updating source-$srcno md5." |
f09c0772 | 783 | md5=$(md5sum "$fp" | cut -f1 -d' ') |
cd445739 | 784 | perl -i -ne ' |
deccc50e AM |
785 | print unless /^\s*#\s*Source'$srcno'-md5\s*:/i; |
786 | print "# Source'$srcno'-md5:\t'$md5'\n" | |
cd445739 AM |
787 | if /^Source'$srcno'\s*:\s+/; |
788 | ' \ | |
789 | $SPECS_DIR/$SPECFILE | |
790 | fi | |
2a5f078d | 791 | |
a4b50627 | 792 | if good_md5 "$i" && good_size "$i"; then |
cd445739 AM |
793 | : |
794 | elif [ "$FROM_DISTFILES" = 1 ]; then | |
deccc50e | 795 | # wrong md5 from distfiles: remove the file and try again |
cd445739 | 796 | # but only once ... |
deccc50e | 797 | echo "MD5 sum mismatch. Trying full fetch." |
cd445739 AM |
798 | FROM_DISTFILES=2 |
799 | rm -f $target | |
18a52930 | 800 | update_shell_title "${GETURI%% *}: $url" |
ca2e6c31 | 801 | ${GETURI} ${OUTFILEOPT} "$target" "$url" || \ |
33da77c4 | 802 | if [ "`echo $url | grep -E 'ftp://'`" ]; then |
18a52930 | 803 | update_shell_title "${GETURI2%% *}: $url" |
ca2e6c31 | 804 | ${GETURI2} ${OUTFILEOPT} "$target" "$url" |
cd445739 AM |
805 | fi |
806 | if ! test -s "$target"; then | |
807 | rm -f "$target" | |
18a52930 | 808 | update_shell_title "${GETURI%% *}: $url_attic" |
ca2e6c31 | 809 | ${GETURI} ${OUTFILEOPT} "$target" "$url_attic" || \ |
33da77c4 | 810 | if [ "`echo $url_attic | grep -E 'ftp://'`" ]; then |
18a52930 | 811 | update_shell_title "${GETURI2%% *}: $url_attic" |
ca2e6c31 | 812 | ${GETURI2} ${OUTFILEOPT} "$target" "$url_attic" |
cd445739 AM |
813 | fi |
814 | fi | |
815 | test -s "$target" || rm -f "$target" | |
816 | fi | |
817 | ||
a4b50627 | 818 | if good_md5 "$i" && good_size "$i" ; then |
cd445739 AM |
819 | : |
820 | else | |
deccc50e AM |
821 | echo "MD5 sum mismatch or 0 size. Use -U to refetch sources," |
822 | echo "or -5 to update md5 sums, if you're sure files are correct." | |
cd445739 AM |
823 | Exit_error err_no_source_in_repo $i |
824 | fi | |
825 | done | |
e7fa3b9f ER |
826 | SHELL_TITLE_PREFIX="" |
827 | ||
828 | if [ "$get_files_cvs" ]; then | |
829 | cvsup $get_files_cvs | |
830 | fi | |
cd445739 AM |
831 | |
832 | if [ "$CHMOD" = "yes" ]; then | |
3815b69a | 833 | CHMOD_FILES="`nourl "$@"`" |
cd445739 AM |
834 | if [ -n "$CHMOD_FILES" ]; then |
835 | chmod $CHMOD_MODE $CHMOD_FILES | |
836 | fi | |
837 | fi | |
cd445739 AM |
838 | fi |
839 | } | |
840 | ||
841 | make_tagver() { | |
78eab2a1 AM |
842 | |
843 | if [ -n "$DEBUG" ]; then | |
844 | set -x; | |
845 | set -v; | |
846 | fi | |
2a5f078d | 847 | |
cd445739 AM |
848 | # Check whether first character of PACKAGE_NAME is legal for tag name |
849 | if [ -z "${PACKAGE_NAME##[_0-9]*}" -a -z "$TAG_PREFIX" ]; then | |
850 | TAG_PREFIX=tag_ | |
851 | fi | |
852 | 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"` | |
853 | # Remove #kernel.version_release from TAGVER because tagging sources | |
854 | # could occur with different kernel-headers than kernel-headers used at build time. | |
855 | TAGVER=$(echo "$TAGVER" | sed -e 's/#.*//g') | |
856 | echo -n "$TAGVER" | |
857 | } | |
858 | ||
859 | tag_files() | |
860 | { | |
861 | TAG_FILES="$@" | |
862 | ||
863 | if [ -n "$DEBUG" ]; then | |
864 | set -x; | |
865 | set -v; | |
866 | fi | |
867 | ||
868 | if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then | |
869 | echo "Version: $PACKAGE_VERSION" | |
870 | echo "Release: $PACKAGE_RELEASE" | |
871 | ||
872 | TAGVER=`make_tagver` | |
873 | ||
874 | if [ "$TAG_VERSION" = "yes" ]; then | |
875 | echo "CVS tag: $TAGVER" | |
876 | fi | |
877 | if [ -n "$TAG" ]; then | |
878 | echo "CVS tag: $TAG" | |
879 | fi | |
880 | ||
881 | OPTIONS="tag -F" | |
882 | if [ -n "$CVSROOT" ]; then | |
883 | OPTIONS="-d $CVSROOT $OPTIONS" | |
884 | fi | |
885 | ||
886 | cd "$SOURCE_DIR" | |
887 | for i in $TAG_FILES | |
888 | do | |
889 | # don't tag files stored on distfiles | |
890 | [ -n "`src_md5 $i`" ] && continue | |
891 | if [ -f "`nourl $i`" ]; then | |
892 | if [ "$TAG_VERSION" = "yes" ]; then | |
893 | cvs $OPTIONS $TAGVER `nourl $i` | |
894 | fi | |
895 | if [ -n "$TAG" ]; then | |
896 | cvs $OPTIONS $TAG `nourl $i` | |
897 | fi | |
898 | else | |
899 | Exit_error err_no_source_in_repo $i | |
900 | fi | |
901 | done | |
902 | ||
903 | cd "$SPECS_DIR" | |
904 | if [ "$TAG_VERSION" = "yes" ]; then | |
905 | cvs $OPTIONS $TAGVER $SPECFILE | |
906 | fi | |
907 | if [ -n "$TAG" ]; then | |
908 | cvs $OPTIONS $TAG $SPECFILE | |
909 | fi | |
910 | ||
911 | unset OPTIONS | |
912 | fi | |
913 | } | |
914 | ||
915 | branch_files() | |
916 | { | |
917 | TAG=$1 | |
918 | echo "CVS branch tag: $TAG" | |
919 | shift; | |
920 | ||
921 | TAG_FILES="$@" | |
922 | ||
923 | if [ -n "$DEBUG" ]; then | |
924 | set -x; | |
925 | set -v; | |
926 | fi | |
927 | ||
928 | if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then | |
929 | ||
930 | OPTIONS="tag -b" | |
931 | if [ -n "$CVSROOT" ]; then | |
932 | OPTIONS="-d $CVSROOT $OPTIONS" | |
933 | fi | |
934 | cd "$SOURCE_DIR" | |
935 | for i in $TAG_FILES | |
936 | do | |
937 | if [ -f `nourl $i` ]; then | |
938 | cvs $OPTIONS $TAG `nourl $i` | |
939 | else | |
940 | Exit_error err_no_source_in_repo $i | |
941 | fi | |
942 | done | |
943 | cd "$SPECS_DIR" | |
944 | cvs $OPTIONS $TAG $SPECFILE | |
945 | ||
946 | unset OPTIONS | |
947 | fi | |
948 | } | |
949 | ||
950 | ||
951 | ||
59398507 | 952 | build_package() |
953 | { | |
2e5be021 | 954 | update_shell_title "build_package" |
cd445739 AM |
955 | if [ -n "$DEBUG" ]; then |
956 | set -x; | |
957 | set -v; | |
958 | fi | |
5a491465 | 959 | |
cd445739 AM |
960 | cd "$SPECS_DIR" |
961 | ||
962 | if [ -n "$TRY_UPGRADE" ]; then | |
2e5be021 | 963 | update_shell_title "build_package: try_upgrade" |
cd445739 | 964 | if [ -n "$FLOAT_VERSION" ]; then |
cc538c24 | 965 | TNOTIFY=`./pldnotify.awk $SPECFILE -n` || exit 1 |
cd445739 | 966 | else |
cc538c24 | 967 | TNOTIFY=`./pldnotify.awk $SPECFILE` || exit 1 |
cd445739 AM |
968 | fi |
969 | ||
970 | TNEWVER=`echo $TNOTIFY | awk '{ match($4,/\[NEW\]/); print $5 }'` | |
971 | ||
972 | if [ -n "$TNEWVER" ]; then | |
973 | TOLDVER=`echo $TNOTIFY | awk '{ print $3; }'` | |
974 | echo "New version found, updating spec file to version " $TNEWVER | |
975 | cp -f $SPECFILE $SPECFILE.bak | |
976 | chmod +w $SPECFILE | |
977 | eval "perl -pi -e 's/Version:\t"$TOLDVER"/Version:\t"$TNEWVER"/gs' $SPECFILE" | |
f7b91886 | 978 | eval "perl -pi -e 's/Release:\t[1-9]{0,4}/Release:\t0.1/' $SPECFILE" |
cd445739 | 979 | parse_spec; |
7f347798 | 980 | if [ -n "$ICONS" ]; then |
981 | get_files $ICONS; | |
982 | parse_spec; | |
983 | fi | |
4ea1c265 | 984 | NODIST="yes" UPDATE5="yes" get_files $SOURCES $PATCHES; |
cd445739 AM |
985 | unset TOLDVER TNEWVER TNOTIFY |
986 | fi | |
987 | fi | |
988 | cd "$SPECS_DIR" | |
2a5f078d | 989 | |
cd445739 AM |
990 | case "$COMMAND" in |
991 | build ) | |
992 | BUILD_SWITCH="-ba" ;; | |
993 | build-binary ) | |
994 | BUILD_SWITCH="-bb" ;; | |
995 | build-source ) | |
996 | BUILD_SWITCH="-bs --nodeps" ;; | |
997 | build-prep ) | |
998 | BUILD_SWITCH="-bp --nodeps" ;; | |
999 | esac | |
c890b916 | 1000 | |
2e5be021 | 1001 | update_shell_title "build_package: $COMMAND" |
cd445739 AM |
1002 | if [ -n "$LOGFILE" ]; then |
1003 | LOG=`eval echo $LOGFILE` | |
1004 | if [ -d "$LOG" ]; then | |
1005 | echo "Log file $LOG is a directory." | |
1006 | echo "Parse error in the spec?" | |
1007 | Exit_error err_build_fail; | |
1008 | fi | |
1009 | if [ -n "$LASTLOG_FILE" ]; then | |
1010 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
1011 | fi | |
1012 | RES_FILE=~/tmp/$RPMBUILD-exit-status.$RANDOM | |
21bc1a97 | 1013 | (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 |
1014 | RETVAL=`cat $RES_FILE` |
1015 | rm $RES_FILE | |
1016 | if [ -n "$LOGDIROK" ] && [ -n "$LOGDIRFAIL" ]; then | |
1017 | if [ "$RETVAL" -eq "0" ]; then | |
1018 | mv $LOG $LOGDIROK | |
1019 | else | |
1020 | mv $LOG $LOGDIRFAIL | |
1021 | fi | |
1022 | fi | |
8ba5cdda | 1023 | else |
8f96ab6c | 1024 | eval nice -n ${DEF_NICE_LEVEL} $RPMBUILD $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $BCOND $TARGET_SWITCH $SPECFILE |
cd445739 | 1025 | RETVAL=$? |
8ba5cdda | 1026 | fi |
cd445739 AM |
1027 | if [ "$RETVAL" -ne "0" ]; then |
1028 | if [ -n "$TRY_UPGRADE" ]; then | |
1029 | echo "\n!!! Package with new version cannot be build automagically\n" | |
1030 | mv -f $SPECFILE.bak $SPECFILE | |
1031 | fi | |
1032 | Exit_error err_build_fail; | |
1033 | fi | |
1034 | unset BUILD_SWITCH | |
1035 | } | |
1036 | ||
1037 | nourl() | |
1038 | { | |
1039 | echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\|svn\)://[^ ]*/##g' | |
1040 | } | |
1041 | ||
cd445739 AM |
1042 | install_required_packages() |
1043 | { | |
1044 | run_poldek -vi $1 | |
1045 | return $? | |
1046 | } | |
1047 | ||
fa4bf1df ER |
1048 | find_spec_bcond() { |
1049 | # taken from find-spec-bcond, but with just getting the list | |
1050 | local SPEC="$1" | |
1051 | # quick revert hint: '$RPMBUILD --bcond $SPEC' | |
1052 | awk -F"\n" ' | |
1053 | /^%changelog/ { exit } | |
1054 | /_with(out)?_[_a-zA-Z0-9]+/{ | |
1055 | match($0, /_with(out)?_[_a-zA-Z0-9]+/); | |
1056 | print substr($0, RSTART, RLENGTH); | |
1057 | } | |
1058 | /^%bcond_with/{ | |
1059 | match($0, /bcond_with(out)?[ \t]+[_a-zA-Z0-9]+/); | |
1060 | bcond = substr($0, RSTART +5 , RLENGTH -5); | |
1061 | gsub(/[ \t]+/,"_",bcond); | |
1062 | print bcond | |
1063 | }' $SPEC | LC_ALL=C sort -u | |
1064 | } | |
1065 | ||
cd445739 AM |
1066 | set_bconds_values() |
1067 | { | |
0b65d15e | 1068 | update_shell_title "set bcond values" |
c890b916 | 1069 | |
cd445739 AM |
1070 | AVAIL_BCONDS_WITHOUT="" |
1071 | AVAIL_BCONDS_WITH="" | |
1072 | if `grep -q ^%bcond ${SPECFILE}`; then | |
1073 | BCOND_VERSION="NEW" | |
36d03934 | 1074 | elif `egrep -q ^#\ *_with ${SPECFILE}`; then |
cd445739 AM |
1075 | BCOND_VERSION="OLD" |
1076 | else | |
fa4bf1df | 1077 | return |
cd445739 | 1078 | fi |
301cbfd4 | 1079 | |
fa4bf1df ER |
1080 | local bcond_avail=$(find_spec_bcond $SPECFILE) |
1081 | ||
301cbfd4 ER |
1082 | # expand bconds from ~/.bcondrc |
1083 | # The file structure is like gentoo's package.use: | |
1084 | # --- | |
1085 | # * -selinux | |
1086 | # samba -mysql -pgsql | |
47a8df12 | 1087 | # w32codec-installer license_agreement |
301cbfd4 ER |
1088 | # php +mysqli |
1089 | # --- | |
fa4bf1df | 1090 | if ([ -f $HOME/.bcondrc ] || ([ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ])); then |
3e1cbfe0 | 1091 | SN=${SPECFILE%%\.spec} |
301cbfd4 | 1092 | |
fa4bf1df ER |
1093 | local bcondrc=$HOME/.bcondrc |
1094 | [ -n $HOME_ETC ] && [ -f $HOME_ETC/.bcondrc ] && bcondrc=$HOME_ETC/.bcondrc | |
c8a3e2ac | 1095 | |
301cbfd4 ER |
1096 | while read pkg flags; do |
1097 | # ignore comments | |
1098 | [[ "$pkg" == \#* ]] && continue | |
1099 | ||
1100 | # any package or current package? | |
fa4bf1df | 1101 | if [ "$pkg" = "*" ] || [ "$pkg" = "$PACKAGE_NAME" ] || [ "$pkg" = "$SN" ]; then |
301cbfd4 | 1102 | for flag in $flags; do |
fa4bf1df | 1103 | local opt=${flag#[+-]} |
301cbfd4 ER |
1104 | |
1105 | # use only flags which are in this package. | |
fa4bf1df | 1106 | if [[ $bcond_avail = *${opt}* ]]; then |
3b5101f0 ER |
1107 | if [[ $flag = -* ]]; then |
1108 | BCOND="$BCOND --without $opt" | |
301cbfd4 | 1109 | else |
3b5101f0 | 1110 | BCOND="$BCOND --with $opt" |
301cbfd4 ER |
1111 | fi |
1112 | fi | |
1113 | done | |
1114 | fi | |
fa4bf1df ER |
1115 | done < $bcondrc |
1116 | update_shell_title "parse ~/.bcondrc: DONE!" | |
301cbfd4 ER |
1117 | fi |
1118 | ||
fa4bf1df | 1119 | update_shell_title "parse bconds" |
cd445739 | 1120 | case "${BCOND_VERSION}" in |
fa4bf1df | 1121 | NONE) |
7e365483 | 1122 | : |
cd445739 | 1123 | ;; |
7e365483 | 1124 | OLD) |
cd445739 | 1125 | echo "Warning: This spec has old style bconds. Fix it || die." |
fa4bf1df | 1126 | for opt in `echo "$bcond_avail" | grep ^_without_` |
cd445739 | 1127 | do |
fa4bf1df ER |
1128 | AVAIL_BCOND_WITHOUT=${opt#_without_} |
1129 | if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then | |
cd445739 AM |
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 | done | |
2a5f078d | 1135 | |
fa4bf1df | 1136 | for opt in `echo "$bcond_avail" | grep ^_with_` |
cd445739 | 1137 | do |
fa4bf1df ER |
1138 | AVAIL_BCOND_WITH=${opt#_with_} |
1139 | if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then | |
cd445739 AM |
1140 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" |
1141 | else | |
1142 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1143 | fi | |
1144 | done | |
1145 | ;; | |
1146 | NEW) | |
fa4bf1df ER |
1147 | local cond_type="" # with || without |
1148 | for opt in $bcond_avail; do | |
cd445739 AM |
1149 | case "$opt" in |
1150 | _without) | |
1151 | cond_type="without" | |
1152 | ;; | |
1153 | _with) | |
1154 | cond_type="with" | |
1155 | ;; | |
f8d24cee | 1156 | _without_*) |
fa4bf1df ER |
1157 | AVAIL_BCOND_WITHOUT=${opt#_without_} |
1158 | if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then | |
f8d24cee | 1159 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>" |
1160 | else | |
1161 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT" | |
1162 | fi | |
1163 | ;; | |
1164 | _with_*) | |
fa4bf1df ER |
1165 | AVAIL_BCOND_WITH=${opt#_with_} |
1166 | if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then | |
f8d24cee | 1167 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" |
1168 | else | |
1169 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1170 | fi | |
1171 | ;; | |
cd445739 AM |
1172 | *) |
1173 | case "$cond_type" in | |
1174 | with) | |
1175 | cond_type='' | |
1176 | AVAIL_BCOND_WITH="$opt" | |
fa4bf1df | 1177 | if [[ "$BCOND" = *--with?${AVAIL_BCOND_WITH}* ]]; then |
cd445739 AM |
1178 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH <$AVAIL_BCOND_WITH>" |
1179 | else | |
1180 | AVAIL_BCONDS_WITH="$AVAIL_BCONDS_WITH $AVAIL_BCOND_WITH" | |
1181 | fi | |
7e365483 | 1182 | ;; |
cd445739 AM |
1183 | without) |
1184 | cond_type='' | |
1185 | AVAIL_BCOND_WITHOUT="$opt" | |
fa4bf1df | 1186 | if [[ "$BCOND" = *--without?${AVAIL_BCOND_WITHOUT}* ]]; then |
cd445739 AM |
1187 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT <$AVAIL_BCOND_WITHOUT>" |
1188 | else | |
1189 | AVAIL_BCONDS_WITHOUT="$AVAIL_BCONDS_WITHOUT $AVAIL_BCOND_WITHOUT" | |
1190 | fi | |
1191 | ;; | |
1192 | esac | |
1193 | ;; | |
1194 | esac | |
1195 | done | |
1196 | ;; | |
1197 | esac | |
1198 | } | |
1199 | ||
1200 | run_sub_builder() | |
1201 | { | |
1202 | package_name="${1}" | |
af6b168f | 1203 | update_shell_title "run_sub_builder $package_name" |
cd445739 AM |
1204 | # |
1205 |