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