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