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