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