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