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