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