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