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