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