]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | # ----------- | |
3 | # $Id$ | |
4 | # Exit codes: | |
5 | # 0 - succesful | |
6 | # 1 - help displayed | |
7 | # 2 - no spec file name in cmdl parameters | |
8 | # 3 - spec file not stored in repo | |
9 | # 4 - some source, patch or icon files not stored in repo | |
10 | # 5 - package build failed | |
11 | # 6 - spec file with errors | |
12 | # 7 - wrong source in /etc/poldek.conf | |
13 | # 8 - Failed installing buildrequirements and subrequirements | |
14 | # 9 - Requested tag already exist | |
15 | # 10 - Refused to build fractional release | |
16 | # 100 - Unknown error (should not happen) | |
17 | ||
18 | # Notes (todo): | |
19 | # - builder -u fetches current version first (well that's okay, how you compare versions if you have no old spec?) | |
20 | # - when Icon: field is present, -5 and -a5 doesn't work | |
21 | # - builder -R skips installing BR if spec is not present before builder invocation (need to run builder twice) | |
22 | ||
23 | VERSION="\ | |
24 | Build package utility from PLD Linux CVS repository | |
25 | v0.15 (C) 1999-2006 Free Penguins". | |
26 | PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin" | |
27 | ||
28 | COMMAND="build" | |
29 | TARGET="" | |
30 | ||
31 | SPECFILE="" | |
32 | BE_VERBOSE="" | |
33 | QUIET="" | |
34 | CLEAN="" | |
35 | DEBUG="" | |
36 | NOURLS="" | |
37 | NOCVS="" | |
38 | NOCVSSPEC="" | |
39 | NODIST="" | |
40 | NOINIT="" | |
41 | UPDATE="" | |
42 | UPDATE5="" | |
43 | ADD5="" | |
44 | NO5="" | |
45 | ALWAYS_CVSUP=${ALWAYS_CVSUP:-"yes"} | |
46 | CVSROOT="" | |
47 | ||
48 | # It can be used i.e. in log file naming. | |
49 | # See LOGFILE example. | |
50 | DATE=`date +%Y-%m-%d_%H-%M-%S` | |
51 | ||
52 | # Example: LOGFILE='../log.$PACKAGE_NAME' | |
53 | # Example: LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE' | |
54 | # Yes, you can use variable name! Note _single_ quotes! | |
55 | LOGFILE='' | |
56 | ||
57 | LOGDIR="" | |
58 | LOGDIROK="" | |
59 | LOGDIRFAIL="" | |
60 | LASTLOG_FILE="" | |
61 | ||
62 | CHMOD="no" | |
63 | CHMOD_MODE="0444" | |
64 | RPMOPTS="" | |
65 | RPMBUILDOPTS="" | |
66 | BCOND="" | |
67 | GROUP_BCONDS="no" | |
68 | CVSIGNORE_DF="no" | |
69 | ||
70 | PATCHES="" | |
71 | SOURCES="" | |
72 | ICONS="" | |
73 | PACKAGE_RELEASE="" | |
74 | PACKAGE_VERSION="" | |
75 | PACKAGE_NAME="" | |
76 | PROTOCOL="ftp" | |
77 | WGET_RETRIES=${MAX_WGET_RETRIES:-0} | |
78 | CVS_RETRIES=${MAX_CVS_RETRIES:-1000} | |
79 | ||
80 | CVSTAG="" | |
81 | RES_FILE="" | |
82 | ||
83 | CVS_SERVER="cvs.pld-linux.org" | |
84 | DISTFILES_SERVER="://distfiles.pld-linux.org" | |
85 | ATTICDISTFILES_SERVER="://attic-distfiles.pld-linux.org" | |
86 | ||
87 | DEF_NICE_LEVEL=19 | |
88 | SCHEDTOOL="auto" | |
89 | ||
90 | FAIL_IF_NO_SOURCES="yes" | |
91 | ||
92 | # let get_files skip over files which are present to get those damn files fetched | |
93 | SKIP_EXISTING_FILES="no" | |
94 | ||
95 | if [ -x /usr/bin/rpm-getdeps ]; then | |
96 | FETCH_BUILD_REQUIRES_RPMGETDEPS="yes" | |
97 | else | |
98 | FETCH_BUILD_REQUIRES_RPMGETDEPS="no" | |
99 | fi | |
100 | ||
101 | # Here we load saved user environment used to | |
102 | # predefine options set above, or passed to builder | |
103 | # in command line. | |
104 | # This one reads global system environment settings: | |
105 | if [ -f ~/etc/builderrc ]; then | |
106 | . ~/etc/builderrc | |
107 | fi | |
108 | # And this one cascades settings using user personal | |
109 | # builder settings. | |
110 | # Example of ~/.builderrc: | |
111 | # | |
112 | #UPDATE_POLDEK_INDEXES="yes" | |
113 | #FETCH_BUILD_REQUIRES="yes" | |
114 | #REMOVE_BUILD_REQUIRES="force" | |
115 | #GROUP_BCONDS="yes" | |
116 | #LOGFILE='../LOGS/log.$PACKAGE_NAME.$DATE' | |
117 | #TITLECHANGE=no | |
118 | # | |
119 | SU_SUDO="" | |
120 | if [ -n "$HOME_ETC" ]; then | |
121 | USER_CFG="$HOME_ETC/.builderrc" | |
122 | else | |
123 | USER_CFG=~/.builderrc | |
124 | fi | |
125 | ||
126 | [ -f "$USER_CFG" ] && . "$USER_CFG" | |
127 | ||
128 | wget --help 2>&1 | grep -q ' \-\-no-check\-certificate ' && WGET_OPTS="$WGET_OPTS --no-check-certificate" | |
129 | ||
130 | if [ "$SCHEDTOOL" = "auto" ]; then | |
131 | if [ -x /usr/bin/schedtool ] && schedtool -B -e echo >/dev/null; then | |
132 | SCHEDTOOL="schedtool -B -e" | |
133 | else | |
134 | SCHEDTOOL="no" | |
135 | fi | |
136 | fi | |
137 | ||
138 | if [ -n "$USE_PROZILLA" ]; then | |
139 | GETURI="proz --no-getch -r -P ./ -t$WGET_RETRIES $PROZILLA_OPTS" | |
140 | GETURI2="$GETURI" | |
141 | OUTFILEOPT="-O" | |
142 | elif [ -n "$USE_AXEL" ]; then | |
143 | GETURI="axel -a $AXEL_OPTS" | |
144 | GETURI2="$GETURI" | |
145 | OUTFILEOPT="-o" | |
146 | else | |
147 | wget --help 2>&1 | grep -q ' \-\-inet ' && WGET_OPTS="$WGET_OPTS --inet" | |
148 | wget --help 2>&1 | grep -q ' \-\-retry\-connrefused ' && WGET_OPTS="$WGET_OPTS --retry-connrefused" | |
149 | ||
150 | GETURI="wget --passive-ftp -c -nd -t$WGET_RETRIES $WGET_OPTS" | |
151 | GETURI2="wget -c -nd -t$WGET_RETRIES $WGET_OPTS" | |
152 | OUTFILEOPT="-O" | |
153 | fi | |
154 | ||
155 | GETLOCAL="cp -a" | |
156 | ||
157 | if (rpm --version 2>&1 | grep -q '4.0.[0-2]'); then | |
158 | RPM="rpm" | |
159 | RPMBUILD="rpm" | |
160 | else | |
161 | RPM="rpm" | |
162 | RPMBUILD="rpmbuild" | |
163 | fi | |
164 | ||
165 | POLDEK_INDEX_DIR="`$RPM --eval %_rpmdir`/" | |
166 | POLDEK_CMD="$SU_SUDO /usr/bin/poldek --noask" | |
167 | ||
168 | run_poldek() | |
169 | { | |
170 | RES_FILE=~/tmp/poldek-exit-status.$RANDOM | |
171 | if [ -n "$LOGFILE" ]; then | |
172 | LOG=`eval echo $LOGFILE` | |
173 | if [ -n "$LASTLOG_FILE" ]; then | |
174 | echo "LASTLOG=$LOG" > $LASTLOG_FILE | |
175 | fi | |
176 | (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE})|tee -a $LOG | |
177 | return $exit_pldk | |
178 | else | |
179 | (${NICE_COMMAND} ${POLDEK_CMD} `while test $# -gt 0; do echo "$1 ";shift;done` ; echo $? > ${RES_FILE}) 1>&2 >/dev/null | |
180 | return `cat ${RES_FILE}` | |
181 | rm -rf ${RES_FILE} | |
182 | fi | |
183 | } | |
184 | ||
185 | #--------------------------------------------- | |
186 | # functions | |
187 | ||
188 | usage() | |
189 | { | |
190 | if [ -n "$DEBUG" ]; then set -xv; fi | |
191 | echo "\ | |
192 | Usage: builder [-D|--debug] [-V|--version] [-a|--as_anon] [-b|-ba|--build] | |
193 | ||
194 | [-bb|--build-binary] [-bs|--build-source] [-u|--try-upgrade] | |
195 | [{-B|--branch} <branch>] [{-d|--cvsroot} <cvsroot>] [-g|--get] | |
196 | [-h|--help] [--http] [{-l,--logtofile} <logfile>] [-m|--mr-proper] | |
197 | [-q|--quiet] [--date <yyyy-mm-dd> [-r <cvstag>] [{-T--tag <cvstag>] | |
198 | [-Tvs|--tag-version-stable] [-Tvn|--tag-version-nest] | |
199 | [-Ts|--tag-stable] [-Tn|--tag-nest] [-Tv|--tag-version] | |
200 | [{-Tp|--tag-prefix} <prefix>] [{-tt|--test-tag}] | |
201 | [-nu|--no-urls] [-v|--verbose] [--opts <rpm opts>] [--show-bconds] | |
202 | [--with/--without <feature>] [--define <macro> <value>] <package>[.spec][:cvstag] | |
203 | ||
204 | -5, --update-md5 - update md5 comments in spec, implies -nd -ncs | |
205 | -a5, --add-md5 - add md5 comments to URL sources, implies -nc -nd -ncs | |
206 | -n5, --no-md5 - ignore md5 comments in spec | |
207 | -D, --debug - enable builder script debugging mode, | |
208 | -debug - produce rpm debug package (same as --opts -debug) | |
209 | -V, --version - output builder version | |
210 | -a, --as_anon - get files via pserver as cvs@$CVS_SERVER, | |
211 | -b, -ba, --build - get all files from CVS repo or HTTP/FTP and build package | |
212 | from <package>.spec, | |
213 | -bb, --build-binary - get all files from CVS repo or HTTP/FTP and build binary | |
214 | only package from <package>.spec, | |
215 | -bp, --build-prep - execute the %prep phase of <package>.spec, | |
216 | -bc - reserved (not implemented) | |
217 | -bi reserved (not implemented) | |
218 | -bs, --build-source - get all files from CVS repo or HTTP/FTP and only pack | |
219 | them into src.rpm, | |
220 | --short-circuit - reserved (not implemented) | |
221 | -B, --branch - add branch | |
222 | -c, --clean - clean all temporarily created files (in BUILD, SOURCES, | |
223 | SPECS and \$RPM_BUILD_ROOT), | |
224 | -d <cvsroot>, --cvsroot <cvsroot> | |
225 | - setup \$CVSROOT, | |
226 | --define <macro> <value> | |
227 | - define a macro <macro> with value <value>, | |
228 | --nodeps - rpm won't check any dependences | |
229 | -g, --get - get <package>.spec and all related files from CVS repo | |
230 | or HTTP/FTP, | |
231 | -h, --help - this message, | |
232 | --http - use http instead of ftp, | |
233 | -l <logfile>, --logtofile <logfile> | |
234 | - log all to file, | |
235 | -m, --mr-proper - only remove all files related to spec file and all work | |
236 | resources, | |
237 | -nc, --no-cvs - don't download sources from CVS, if source URL is given, | |
238 | -ncs, --no-cvs-specs | |
239 | - don't check specs in CVS | |
240 | -nd, --no-distfiles - don't download from distfiles | |
241 | -nm, --no-mirrors - don't download from mirror, if source URL is given, | |
242 | -nu, --no-urls - don't try to download from FTP/HTTP location, | |
243 | -ns, --no-srcs - don't download Sources | |
244 | -ns0, --no-source0 - don't download Source0 | |
245 | -nn, --no-net - don't download anything from the net | |
246 | -ni, --no-init - don't initialize builder paths (SPECS and SOURCES) | |
247 | -ske, | |
248 | --skip-existing-files - skip existing files in get_files | |
249 | --opts <rpm opts> - additional options for rpm | |
250 | -q, --quiet - be quiet, | |
251 | --date yyyy-mm-dd - build package using resources from specified CVS date, | |
252 | -r <cvstag>, --cvstag <cvstag> | |
253 | - build package using resources from specified CVS tag, | |
254 | -R, --fetch-build-requires | |
255 | - fetch what is BuildRequired, | |
256 | -RB, --remove-build-requires | |
257 | - remove all you fetched with -R or --fetch-build-requires | |
258 | remember, this option requires confirmation, | |
259 | -FRB, --force-remove-build-requires | |
260 | - remove all you fetched with -R or --fetch-build-requires | |
261 | remember, this option works without confirmation, | |
262 | -sd, --source-distfiles - list sources available from distfiles (intended for offline | |
263 | operations; does not work when Icon field is present | |
264 | but icon file is absent), | |
265 | -sdp, --source-distfiles-paths - list sources available from distfiles - | |
266 | paths relative to distfiles directory (intended for offline | |
267 | operations; does not work when Icon field is present | |
268 | but icon file is absent), | |
269 | -sf, --source-files - list sources - bare filenames (intended for offline | |
270 | operations; does not work when Icon field is present | |
271 | but icon file is absent), | |
272 | -sp, --source-paths - list sources - filenames with full local paths (intended for | |
273 | offline operations; does not work when Icon field is present | |
274 | but icon file is absent), | |
275 | -su, --source-urls - list urls - urls to sources and patches | |
276 | intended for copying urls with spec with lots of macros in urls | |
277 | -T <cvstag> , --tag <cvstag> | |
278 | - add cvs tag <cvstag> for files, | |
279 | -Tvs, --tag-version-stable | |
280 | - add cvs tags STABLE and NAME-VERSION-RELEASE for files, | |
281 | -Tvn, --tag-version-nest | |
282 | - add cvs tags NEST and NAME-VERSION-RELEASE for files, | |
283 | -Ts, --tag-stable | |
284 | - add cvs tag STABLE for files, | |
285 | -Tn, --tag-nest | |
286 | - add cvs tag NEST for files, | |
287 | -Tv, --tag-version | |
288 | - add cvs tag NAME-VERSION-RELEASE for files, | |
289 | -Tp, --tag-prefix <prefix> | |
290 | - add <prefix> to NAME-VERSION-RELEASE tags, | |
291 | -tt, --test-tag <prefix> | |
292 | - fail if tag is already present, | |
293 | -ir, --integer-release-only | |
294 | - allow only integer and snapshot releases | |
295 | -v, --verbose - be verbose, | |
296 | -u, --try-upgrade - check version, and try to upgrade package | |
297 | -un, --try-upgrade-with-float-version | |
298 | - as above, but allow float version | |
299 | -U, --update - refetch sources, don't use distfiles, and update md5 comments | |
300 | -Upi, --update-poldek-indexes | |
301 | - refresh or make poldek package index files. | |
302 | -np, --nopatch <patchnumber> | |
303 | - don't apply <patchnumber> | |
304 | --show-bconds - show available conditional builds, which can be used | |
305 | - with --with and/or --without switches. | |
306 | --with/--without <feature> | |
307 | - conditional build package depending on %_with_<feature>/ | |
308 | %_without_<feature> macro switch. You may now use | |
309 | --with feat1 feat2 feat3 --without feat4 feat5 --with feat6 | |
310 | constructions. Set GROUP_BCONDS to yes to make use of it. | |
311 | --target <platform>, --target=<platform> | |
312 | - build for platform <platform>. | |
313 | --init-rpm-dir - initialize ~/rpm directory structure | |
314 | " | |
315 | } | |
316 | ||
317 | update_shell_title() { | |
318 | [ -t 1 ] || return | |
319 | local len=${COLUMNS:-80} | |
320 | local msg=$(echo "$*" | cut -c-$len) | |
321 | ||
322 | if [ -n "$BE_VERBOSE" ]; then | |
323 | echo >&2 "$(date +%s.%N) $*" | |
324 | fi | |
325 | ||
326 | if [ "x$TITLECHANGE" == "xyes" -o "x$TITLECHANGE" == "x" ]; then | |
327 | local pkg | |
328 | if [ -n "$PACKAGE_NAME" ]; then | |
329 | pkg=${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE} | |
330 | else | |
331 | pkg=${SPECFILE} | |
332 | fi | |
333 | ||
334 | msg="$pkg: ${SHELL_TITLE_PREFIX:+$SHELL_TITLE_PREFIX }$msg" | |
335 | case "$TERM" in | |
336 | cygwin|xterm*) | |
337 | echo >&2 -ne "\033]1;$msg\007\033]2;$msg\007" | |
338 | ;; | |
339 | screen*) | |
340 | echo >&2 -ne "\033]0;$msg\007" | |
341 | ;; | |
342 | esac | |
343 | fi | |
344 | } | |
345 | ||
346 | # set TARGET from BuildArch: from SPECFILE | |
347 | set_spec_target() { | |
348 | if [ -n "$SPECFILE" ] && [ -z "$TARGET" ]; then | |
349 | tmp=$(awk '/^BuildArch:/ { print $NF}' $SPECFILE) | |
350 | if [ "$tmp" ]; then | |
351 | TARGET="$tmp" | |
352 | case "$RPMBUILD" in | |
353 | "rpmbuild") | |
354 | TARGET_SWITCH="--target $TARGET" ;; | |
355 | "rpm") | |
356 | TARGET_SWITCH="--target=$TARGET" ;; | |
357 | esac | |
358 | fi | |
359 | fi | |
360 | } | |
361 | ||
362 | cache_rpm_dump () { | |
363 | if [ -n "$DEBUG" ]; then | |
364 | set -x; | |
365 | set -v; | |
366 | fi | |
367 | ||
368 | update_shell_title "cache_rpm_dump" | |
369 | local rpm_dump | |
370 | rpm_dump=` | |
371 | ||
372 | # we reset macros not to contain macros.build as all the %() macros are | |
373 | # executed here, while none of them are actually needed. | |
374 | # what we need from dump is NAME, VERSION, RELEASE and PATCHES/SOURCES. | |
375 | # at the time of this writing macros.build + macros contained 70 "%(...)" macros. | |
376 | macrofiles="/usr/lib/rpm/macros:$SPECS_DIR/.builder-rpmmacros:~/etc/.rpmmacros:~/.rpmmacros" | |
377 | dump='%{echo:dummy: PACKAGE_NAME %{name} }%dump' | |
378 | # FIXME: better ideas than .rpmrc? | |
379 | printf 'include:/usr/lib/rpm/rpmrc\nmacrofiles:%s\n' $macrofiles > .builder-rpmrc | |
380 | # TODO: move these to /usr/lib/rpm/macros | |
381 | cat > .builder-rpmmacros <<'EOF' | |
382 | %requires_releq_kernel_up %{nil} | |
383 | %requires_releq_kernel_smp %{nil} | |
384 | %requires_releq() %{nil} | |
385 | %pyrequires_eq() %{nil} | |
386 | %requires_eq() %{nil} | |
387 | %requires_eq_to() %{nil} | |
388 | %releq_kernel_up ERROR | |
389 | %releq_kernel_smp ERROR | |
390 | %kgcc_package ERROR | |
391 | %_fontsdir ERROR | |
392 | %ruby_version ERROR | |
393 | %ruby_ver_requires_eq() %{nil} | |
394 | %ruby_mod_ver_requires_eq() %{nil} | |
395 | %__php_api_requires() %{nil} | |
396 | %php_major_version ERROR | |
397 | %php_api_version ERROR | |
398 | %py_ver ERROR | |
399 | EOF | |
400 | case "$RPMBUILD" in | |
401 | rpm) | |
402 | ARGS='-bp' | |
403 | ;; | |
404 | rpmbuild) | |
405 | ARGS='--nodigest --nosignature --nobuild' | |
406 | ;; | |
407 | esac | |
408 | $RPMBUILD --rcfile .builder-rpmrc $ARGS --nodeps --define "prep $dump" $BCOND $TARGET_SWITCH $SPECFILE 2>&1 | |
409 | ` | |
410 | if [ $? -gt 0 ]; then | |
411 | error=$(echo "$rpm_dump" | sed -ne '/^error:/,$p') | |
412 | echo "$error" >&2 | |
413 | Exit_error err_build_fail; | |
414 | fi | |
415 | ||
416 | # make small dump cache | |
417 | rpm_dump_cache=`echo "$rpm_dump" | awk ' | |
418 | $2 ~ /^SOURCEURL/ {print} | |
419 | $2 ~ /^PATCHURL/ {print} | |
420 | $2 ~ /^nosource/ {print} | |
421 | $2 ~ /^PACKAGE_/ {print} | |
422 | '` | |
423 | ||
424 | update_shell_title "cache_rpm_dump: OK!" | |
425 | } | |
426 | ||
427 | rpm_dump () { | |
428 | if [ -z "$rpm_dump_cache" ] ; then | |
429 | echo "internal error: cache_rpm_dump not called!" 1>&2 | |
430 | fi | |
431 | echo "$rpm_dump_cache" | |
432 | } | |
433 | ||
434 | get_icons() | |
435 | { | |
436 | update_shell_title "get icons" | |
437 | ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`" | |
438 | if [ -z "$ICONS" ]; then | |
439 | return | |
440 | fi | |
441 | ||
442 |