1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # $Id$
|
---|
4 |
|
---|
5 | set +e
|
---|
6 |
|
---|
7 | # VT100 colors
|
---|
8 | declare -r BLACK=$'\e[1;30m'
|
---|
9 | declare -r DK_GRAY=$'\e[0;30m'
|
---|
10 |
|
---|
11 | declare -r RED=$'\e[31m'
|
---|
12 | declare -r GREEN=$'\e[32m'
|
---|
13 | declare -r YELLOW=$'\e[33m'
|
---|
14 | declare -r BLUE=$'\e[34m'
|
---|
15 | declare -r MAGENTA=$'\e[35m'
|
---|
16 | declare -r CYAN=$'\e[36m'
|
---|
17 | declare -r WHITE=$'\e[37m'
|
---|
18 |
|
---|
19 | declare -r OFF=$'\e[0m'
|
---|
20 | declare -r BOLD=$'\e[1m'
|
---|
21 | declare -r REVERSE=$'\e[7m'
|
---|
22 | declare -r HIDDEN=$'\e[8m'
|
---|
23 |
|
---|
24 | declare -r tab_=$'\t'
|
---|
25 | declare -r nl_=$'\n'
|
---|
26 |
|
---|
27 | declare -r DD_BORDER="${BOLD}${WHITE}==============================================================================${OFF}"
|
---|
28 | declare -r SD_BORDER="${BOLD}${WHITE}------------------------------------------------------------------------------${OFF}"
|
---|
29 | declare -r STAR_BORDER="${BOLD}${WHITE}******************************************************************************${OFF}"
|
---|
30 |
|
---|
31 | # bold yellow > < pair
|
---|
32 | declare -r R_arrow=$'\e[1;33m>\e[0m'
|
---|
33 | declare -r L_arrow=$'\e[1;33m<\e[0m'
|
---|
34 |
|
---|
35 |
|
---|
36 | usage() {
|
---|
37 | cat <<- -EOF-
|
---|
38 | ${DD_BORDER}
|
---|
39 | ${BOLD}
|
---|
40 | Usage: $0 ${BOLD}[OPTION]
|
---|
41 |
|
---|
42 | Options:
|
---|
43 | ${BOLD} -h, --help${OFF}
|
---|
44 | print this help, then exit
|
---|
45 |
|
---|
46 | ${BOLD} -V, --version${OFF}
|
---|
47 | print version information, then exit
|
---|
48 |
|
---|
49 | ${BOLD} -B, --book VER${OFF}
|
---|
50 | checkout VER version of the book. Supported versions at this time are:
|
---|
51 | dev* | trunk | SVN aliases for Development {C,H,B}LFS
|
---|
52 | alpha* aliases for the LFS alphabetical branch
|
---|
53 | udev* aliases for the LFS udev_update branch
|
---|
54 |
|
---|
55 | ${BOLD} -D --directory DIR${OFF}
|
---|
56 | use DIR directory for building ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF}; all files jhalfs-X produces
|
---|
57 | will be in the directory DIR/jhalfs.
|
---|
58 |
|
---|
59 | ${BOLD} -G, --get-packages${OFF}
|
---|
60 | download the packages and patches. This assumes that the server declared
|
---|
61 | in the configuration file has the proper packages and patches for the
|
---|
62 | book version being processed.
|
---|
63 |
|
---|
64 | ${BOLD} -T, --testsuites N ${OFF}
|
---|
65 | Run test suites [0-3]
|
---|
66 | 0 = none
|
---|
67 | 1 = only chapter06 Glibc, GCC and Binutils testsuites
|
---|
68 | 2 = all chapter06 testsuites (in BLFS, alias to 1)
|
---|
69 | 3 = all chapter05 and chapter06 testsuites
|
---|
70 | In BLFS, 2 and 3 are aliases to 1
|
---|
71 | In CLFS, 3 is an alias to 2
|
---|
72 |
|
---|
73 | ${BOLD} -W, --working-copy DIR${OFF}
|
---|
74 | use the local working copy placed in DIR as the $(echo $PROGNAME | tr [a-z] [A-Z]) book
|
---|
75 | -EOF-
|
---|
76 |
|
---|
77 | [[ ${PROGNAME} != "blfs" ]] &&
|
---|
78 | cat <<- -EOF-
|
---|
79 |
|
---|
80 | ${BOLD} -F, --fstab FILE${OFF}
|
---|
81 | use FILE as the /etc/fstab file for the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} system. If not specified,
|
---|
82 | a default /etc/fstab file with dummy values is created.
|
---|
83 |
|
---|
84 | ${BOLD} -K, --kernel-config FILE${OFF}
|
---|
85 | use the kernel configuration file specified in FILE to build the kernel.
|
---|
86 | if the file is not found, or if not specified, the kernel build is skipped.
|
---|
87 |
|
---|
88 | ${BOLD} -M, --run-make${OFF}
|
---|
89 | run make on the generated Makefile
|
---|
90 |
|
---|
91 | ${BOLD} -R --rebuild${OFF}
|
---|
92 | clean the build directory before to perfom any other task. The directory
|
---|
93 | is cleaned only if it was populated by a previous jhalfs-X run.
|
---|
94 | -EOF-
|
---|
95 |
|
---|
96 | [[ ${PROGNAME} = "clfs" ]] &&
|
---|
97 | cat <<- -EOF-
|
---|
98 |
|
---|
99 | ${BOLD} -A, --arch ARCH ${OFF}
|
---|
100 | Select the TARGET architecture, valid selections are:
|
---|
101 | 32bit builds
|
---|
102 | x86, i486, i586, ppc, mips, mipsel, sparc, sparcv8
|
---|
103 | 64bit builds
|
---|
104 | x86_64-64, mips64-64, mipsel64-64, sparc64-64, alpha
|
---|
105 | 64bit multi-lib
|
---|
106 | x86_64, mips64, mipsel64, sparc64, ppc64
|
---|
107 |
|
---|
108 | ${BOLD} --boot_config FILE ${OFF}
|
---|
109 | The configuration file for the bootstrap kernel if method=boot
|
---|
110 |
|
---|
111 | ${BOLD} --method BUILDMETHOD ${OFF}
|
---|
112 | Select the build method, chroot or boot
|
---|
113 | -EOF-
|
---|
114 |
|
---|
115 | [[ ${PROGNAME} = "hlfs" ]] &&
|
---|
116 | cat <<- -EOF-
|
---|
117 |
|
---|
118 | ${BOLD} --model STYLE ${OFF}
|
---|
119 | Select the library model for the HLFS system
|
---|
120 | Valid choices are: glibc or uclibc
|
---|
121 | -EOF-
|
---|
122 |
|
---|
123 | [[ ${PROGNAME} = "blfs" ]] &&
|
---|
124 | cat <<- -EOF-
|
---|
125 |
|
---|
126 | ${BOLD} --dependencies 0/1/2${OFF}
|
---|
127 | add dependencies of type TYPE to the build tree.
|
---|
128 | If not set, both required and recommended are used.
|
---|
129 |
|
---|
130 | Possible values are:
|
---|
131 | 0 - required only required dependecies are used
|
---|
132 | 1 - recommended both required a recommended dependencies are used
|
---|
133 | 2 - optional all dependencies are used
|
---|
134 | -EOF-
|
---|
135 |
|
---|
136 | cat <<- -EOF-
|
---|
137 | ${DD_BORDER}
|
---|
138 | -EOF-
|
---|
139 | exit
|
---|
140 | }
|
---|
141 |
|
---|
142 | version="
|
---|
143 | ${BOLD} \"jhalfs-X\"${OFF} builder tool (development) \$Rev$
|
---|
144 | \$Date$
|
---|
145 |
|
---|
146 | ${BOLD} \"${PROGNAME}\"${OFF} script module
|
---|
147 |
|
---|
148 | Written by Jeremy Huntwork,
|
---|
149 | Manuel Canales Esparcia,
|
---|
150 | George Boudreau
|
---|
151 |
|
---|
152 | This program is published under the ${BOLD}Gnu General Public License, Version 2.${OFF}
|
---|
153 | "
|
---|
154 |
|
---|
155 |
|
---|
156 | no_empty_builddir() {
|
---|
157 | 'clear'
|
---|
158 | cat <<- -EOF-
|
---|
159 | ${DD_BORDER}
|
---|
160 |
|
---|
161 | ${tab_}${tab_}${BOLD}${RED}W A R N I N G${OFF}
|
---|
162 | Looks like the \$BUILDDIR directory contains subdirectories
|
---|
163 | from a previous HLFS build.
|
---|
164 |
|
---|
165 | Please format the partition mounted on \$BUILDDIR or set
|
---|
166 | a different build directory before running jhalfs-X.
|
---|
167 | ${OFF}
|
---|
168 | ${DD_BORDER}
|
---|
169 | -EOF-
|
---|
170 | exit
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|
174 | help="${nl_}Try '$0 --help' for more information."
|
---|
175 |
|
---|
176 |
|
---|
177 | exit_missing_arg="\
|
---|
178 | echo \"Option '\$1' requires an argument\" >&2
|
---|
179 | echo \"\$help\" >&2
|
---|
180 | exit 1"
|
---|
181 |
|
---|
182 | no_dl_client="\
|
---|
183 | echo \"Could not find a way to download the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} sources.\" >&2
|
---|
184 | echo \"Attempting to continue.\" >&2"
|
---|
185 |
|
---|
186 | HEADER="# This file is automatically generated by jhalfs-X
|
---|
187 | # DO NOT EDIT THIS FILE MANUALLY
|
---|
188 | #
|
---|
189 | # Generated on `date \"+%F %X %Z\"`"
|
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 |
|
---|
194 |
|
---|
195 | #----------------------------------#
|
---|
196 | wrt_target() { #
|
---|
197 | #----------------------------------#
|
---|
198 | local i=$1
|
---|
199 | local PREV=$2
|
---|
200 | (
|
---|
201 | cat << EOF
|
---|
202 |
|
---|
203 | $i: $PREV
|
---|
204 | @\$(call echo_message, Building)
|
---|
205 | EOF
|
---|
206 | ) >> $MKFILE.tmp
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|
210 | #----------------------------------#
|
---|
211 | wrt_unpack() { # Unpack and set 'ROOT' var
|
---|
212 | #----------------------------------#
|
---|
213 | local FILE=$1
|
---|
214 | (
|
---|
215 | cat << EOF
|
---|
216 | @\$(call unpack,$FILE)
|
---|
217 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
218 | echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
|
---|
219 | chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
|
---|
220 | EOF
|
---|
221 | ) >> $MKFILE.tmp
|
---|
222 | }
|
---|
223 |
|
---|
224 |
|
---|
225 | #----------------------------------#
|
---|
226 | wrt_unpack2() { #
|
---|
227 | #----------------------------------#
|
---|
228 | local FILE=$1
|
---|
229 | (
|
---|
230 | cat << EOF
|
---|
231 | @\$(call unpack2,$FILE)
|
---|
232 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
233 | echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
|
---|
234 | EOF
|
---|
235 | ) >> $MKFILE.tmp
|
---|
236 | }
|
---|
237 |
|
---|
238 |
|
---|
239 | #=============================#
|
---|
240 | wrt_unpack3() { #
|
---|
241 | #=============================#
|
---|
242 | local FILE=$1
|
---|
243 | (
|
---|
244 | cat << EOF
|
---|
245 | @\$(call unpack3,$FILE)
|
---|
246 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
247 | echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
|
---|
248 | EOF
|
---|
249 | ) >> $MKFILE.tmp
|
---|
250 | }
|
---|
251 |
|
---|
252 |
|
---|
253 |
|
---|
254 | #----------------------------------#
|
---|
255 | wrt_target_vars() { # Target vars for hlfs (cross-build method)
|
---|
256 | #----------------------------------#
|
---|
257 | (
|
---|
258 | cat << EOF
|
---|
259 | @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
|
---|
260 | echo "export ldso=/lib/${LOADER}" >> envars
|
---|
261 | EOF
|
---|
262 | ) >> $MKFILE.tmp
|
---|
263 |
|
---|
264 | }
|
---|
265 |
|
---|
266 |
|
---|
267 | #----------------------------------#
|
---|
268 | wrt_run_as_su() { # header to log file, execute script, footer to log file
|
---|
269 | #----------------------------------#
|
---|
270 | local this_script=$1
|
---|
271 | local file=$2
|
---|
272 | (
|
---|
273 | cat << EOF
|
---|
274 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
|
---|
275 | su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 && \\
|
---|
276 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
|
---|
277 | EOF
|
---|
278 | ) >> $MKFILE.tmp
|
---|
279 | }
|
---|
280 |
|
---|
281 |
|
---|
282 | #==================================#
|
---|
283 | wrt_run_as_lfs() { #
|
---|
284 | #==================================#
|
---|
285 | local this_script=$1
|
---|
286 | local file=$2
|
---|
287 | (
|
---|
288 | cat << EOF
|
---|
289 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
|
---|
290 | su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 && \\
|
---|
291 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
|
---|
292 | EOF
|
---|
293 | ) >> $MKFILE.tmp
|
---|
294 | }
|
---|
295 |
|
---|
296 |
|
---|
297 | #----------------------------------#
|
---|
298 | wrt_run_as_root() { #
|
---|
299 | #----------------------------------#
|
---|
300 | local this_script=$1
|
---|
301 | local file=$2
|
---|
302 | (
|
---|
303 | cat << EOF
|
---|
304 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
|
---|
305 | export LFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 && \\
|
---|
306 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
|
---|
307 | EOF
|
---|
308 | ) >> $MKFILE.tmp
|
---|
309 | }
|
---|
310 |
|
---|
311 |
|
---|
312 | #=============================#
|
---|
313 | wrt_run_as_root2() { # Some scripts must be run as root..
|
---|
314 | #=============================#
|
---|
315 | local this_script=$1
|
---|
316 | local file=$2
|
---|
317 | (
|
---|
318 | cat << EOF
|
---|
319 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \`\n" >logs/$this_script && \\
|
---|
320 | source envars && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 && \\
|
---|
321 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \`\n" >>logs/$this_script
|
---|
322 | EOF
|
---|
323 | ) >> $MKFILE.tmp
|
---|
324 | }
|
---|
325 |
|
---|
326 |
|
---|
327 | #----------------------------------#
|
---|
328 | wrt_remove_build_dirs() { #
|
---|
329 | #----------------------------------#
|
---|
330 | local name=$1
|
---|
331 | (
|
---|
332 | cat << EOF
|
---|
333 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
334 | rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
|
---|
335 | if [ -e \$(MOUNT_PT)\$(SRC)/$name-build ]; then \\
|
---|
336 | rm -r \$(MOUNT_PT)\$(SRC)/$name-build; \\
|
---|
337 | fi;
|
---|
338 | EOF
|
---|
339 | ) >> $MKFILE.tmp
|
---|
340 | }
|
---|
341 |
|
---|
342 |
|
---|
343 | #----------------------------------#
|
---|
344 | wrt_remove_build_dirs2() { #
|
---|
345 | #----------------------------------#
|
---|
346 | local name=$1
|
---|
347 | (
|
---|
348 | cat << EOF
|
---|
349 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
350 | rm -r \$(SRC)/\$\$ROOT && \\
|
---|
351 | if [ -e \$(SRC)/$name-build ]; then \\
|
---|
352 | rm -r \$(SRC)/$name-build; \\
|
---|
353 | fi;
|
---|
354 | EOF
|
---|
355 | ) >> $MKFILE.tmp
|
---|
356 | }
|
---|
357 |
|
---|
358 |
|
---|
359 |
|
---|
360 | #----------------------------------#
|
---|
361 | wrt_run_as_chroot1() { #
|
---|
362 | #----------------------------------#
|
---|
363 | local this_script=$1
|
---|
364 | local file=$2
|
---|
365 | (
|
---|
366 | cat << EOF
|
---|
367 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/${this_script} && \\
|
---|
368 | \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' && \\
|
---|
369 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/${this_script}
|
---|
370 | EOF
|
---|
371 | ) >> $MKFILE.tmp
|
---|
372 | }
|
---|
373 |
|
---|
374 |
|
---|
375 | #----------------------------------#
|
---|
376 | wrt_run_as_chroot2() { #
|
---|
377 | #----------------------------------#
|
---|
378 | local this_script=$1
|
---|
379 | local file=$2
|
---|
380 | (
|
---|
381 | cat << EOF
|
---|
382 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/${this_script} && \\
|
---|
383 | \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' && \\
|
---|
384 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/${this_script}
|
---|
385 | EOF
|
---|
386 | ) >> $MKFILE.tmp
|
---|
387 | }
|
---|
388 |
|
---|
389 |
|
---|
390 | #----------------------------------#
|
---|
391 | wrt_copy_fstab() { #
|
---|
392 | #----------------------------------#
|
---|
393 | local i=$1
|
---|
394 | (
|
---|
395 | cat << EOF
|
---|
396 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$i && \\
|
---|
397 | cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1 && \\
|
---|
398 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$i
|
---|
399 | EOF
|
---|
400 | ) >> $MKFILE.tmp
|
---|
401 | }
|
---|
402 |
|
---|
403 | #----------------------------------#
|
---|
404 | wrt_copy_fstab2() { #
|
---|
405 | #----------------------------------#
|
---|
406 | local i=$1
|
---|
407 | (
|
---|
408 | cat << EOF
|
---|
409 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \`\n" >logs/$i && \\
|
---|
410 | cp -v /sources/fstab /etc/fstab >>logs/$i 2>&1 && \\
|
---|
411 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \`\n" >>logs/$i
|
---|
412 | EOF
|
---|
413 | ) >> $MKFILE.tmp
|
---|
414 | }
|
---|
415 |
|
---|
416 |
|
---|
417 | #----------------------------------#
|
---|
418 | wrt_export_pkgdir() { #
|
---|
419 | #----------------------------------#
|
---|
420 | (
|
---|
421 | cat << EOF
|
---|
422 | @echo "export PKGDIR=\$(SRC)/binutils-build" > envars
|
---|
423 | EOF
|
---|
424 | ) >> $MKFILE.tmp
|
---|
425 | }
|
---|
426 |
|
---|
427 |
|
---|
428 | #----------------------------#
|
---|
429 | run_make() {
|
---|
430 | #----------------------------#
|
---|
431 | # Test if make must be run.
|
---|
432 | if [ "$RUNMAKE" = "1" ] ; then
|
---|
433 | # Test to make sure we're running the build as root
|
---|
434 | if [ "$UID" != "0" ] ; then
|
---|
435 | echo "You must be logged in as root to successfully build the system."
|
---|
436 | exit 1
|
---|
437 | fi
|
---|
438 | # Build the system
|
---|
439 | if [ -e $MKFILE ] ; then
|
---|
440 | echo -ne "Building the system...\n"
|
---|
441 | cd $JHALFSDIR && make -f ${PROGNAME}-Makefile
|
---|
442 | echo -ne "done\n"
|
---|
443 | fi
|
---|
444 | fi
|
---|
445 | }
|
---|
446 |
|
---|
447 |
|
---|
448 | #----------------------------#
|
---|
449 | clean_builddir() {
|
---|
450 | #----------------------------#
|
---|
451 | # Test if the clean must be done.
|
---|
452 | if [ "$CLEAN" = "1" ] ; then
|
---|
453 | # Test to make sure we're running the clean as root
|
---|
454 | if [ "$UID" != "0" ] ; then
|
---|
455 | echo "You must be logged in as root to clean the build directory."
|
---|
456 | exit 1
|
---|
457 | fi
|
---|
458 | # Test to make sure that the build directory was populated by jhalfs
|
---|
459 | if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
|
---|
460 | echo "Looks like $BUILDDIR was not populated by a previous jhalfs-X run."
|
---|
461 | exit 1
|
---|
462 | else
|
---|
463 | # Clean the build directory
|
---|
464 | echo -ne "Cleaning $BUILDDIR...\n"
|
---|
465 | rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
|
---|
466 | echo -ne "Cleaning $JHALFSDIR...\n"
|
---|
467 | rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
|
---|
468 | echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
|
---|
469 | rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
|
---|
470 | echo -ne "done\n"
|
---|
471 | fi
|
---|
472 | fi
|
---|
473 | }
|
---|
474 |
|
---|
475 | #----------------------------#
|
---|
476 | get_book() {
|
---|
477 | #----------------------------#
|
---|
478 | cd $JHALFSDIR
|
---|
479 |
|
---|
480 | if [ -z $WC ] ; then
|
---|
481 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
482 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
483 | exit 1"
|
---|
484 | echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
|
---|
485 |
|
---|
486 | case $PROGNAME in
|
---|
487 | lfs) svn_root="LFS" ;;
|
---|
488 | hlfs) svn_root="HLFS" ;;
|
---|
489 | clfs) svn_root="cross-lfs" ;;
|
---|
490 | blfs) svn_root="BLFS" ;;
|
---|
491 | *) echo "BOOK not defined in function <get_book>"
|
---|
492 | exit 1 ;;
|
---|
493 | esac
|
---|
494 | # Grab a fresh book if it's missing, otherwise, update it from the
|
---|
495 | # repo. If we've already extracted the commands, move on to getting the
|
---|
496 | # sources.
|
---|
497 | if [ -d ${PROGNAME}-$LFSVRS ] ; then
|
---|
498 | cd ${PROGNAME}-$LFSVRS
|
---|
499 | if LC_ALL=C svn up | grep -q At && test -d $JHALFSDIR/commands && \
|
---|
500 | test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
|
---|
501 | echo -ne "done\n"
|
---|
502 | # Set the canonical book version
|
---|
503 | cd $JHALFSDIR
|
---|
504 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
505 | get_sources
|
---|
506 | else
|
---|
507 | echo -ne "done\n"
|
---|
508 | # Set the canonical book version
|
---|
509 | cd $JHALFSDIR
|
---|
510 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
511 | extract_commands
|
---|
512 | fi
|
---|
513 | else
|
---|
514 | case $LFSVRS in
|
---|
515 | development)
|
---|
516 | svn co $SVN/${svn_root}/trunk/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
|
---|
517 | alphabetical)
|
---|
518 | svn co $SVN/${svn_root}/branches/$LFSVRS/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
|
---|
519 | udev_update)
|
---|
520 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
|
---|
521 | esac
|
---|
522 | echo -ne "done\n"
|
---|
523 | # Set the canonical book version
|
---|
524 | cd $JHALFSDIR
|
---|
525 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
526 | extract_commands
|
---|
527 | fi
|
---|
528 | else
|
---|
529 | echo -ne "Using $BOOK as book's sources ...\n"
|
---|
530 | # Set the canonical book version
|
---|
531 | cd $JHALFSDIR
|
---|
532 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
533 | extract_commands
|
---|
534 | fi
|
---|
535 | }
|
---|
536 |
|
---|
537 |
|
---|
538 | #----------------------------#
|
---|
539 | build_patches_file() { # Supply a suitably formated list of patches.
|
---|
540 | #----------------------------#
|
---|
541 | local saveIFS=$IFS
|
---|
542 | local IFS
|
---|
543 |
|
---|
544 | rm -f patches
|
---|
545 |
|
---|
546 | LOC_add_patches_entry() {
|
---|
547 | for f in `grep "/$1-" patcheslist_.wget`; do
|
---|
548 | basename $f | sed "s|${2}|\&${1}-version;|" >> patches
|
---|
549 | done
|
---|
550 | }
|
---|
551 |
|
---|
552 | case ${PROGNAME} in
|
---|
553 | hlfs)
|
---|
554 | echo -n "Creating the HLFS ${L_arrow}${BOLD}$MODEL${R_arrow} specific patches file"
|
---|
555 | xsltproc --nonet \
|
---|
556 | --xinclude \
|
---|
557 | --stringparam model $MODEL \
|
---|
558 | -o patcheslist_.wget \
|
---|
559 | patcheslist.xsl \
|
---|
560 | $BOOK/chapter04/patches.xml
|
---|
561 | #> /dev/null 2>&1
|
---|
562 |
|
---|
563 | # .... U G L Y .... what to do with the grsecurity patch to the kernel..
|
---|
564 | for f in `grep "/grsecurity-" patcheslist_.wget`; do
|
---|
565 | basename $f >> patches
|
---|
566 | done
|
---|
567 | ;;
|
---|
568 |
|
---|
569 | clfs) # Pull out a list of arch specific patches
|
---|
570 | echo -n "Creating CLFS ${L_arrow}${BOLD}$ARCH${R_arrow} specific patches file"
|
---|
571 | xsltproc -xinclude \
|
---|
572 | -o patcheslist_.wget \
|
---|
573 | patcheslist.xsl \
|
---|
574 | $BOOK/materials/${ARCH}-chapter.xml
|
---|
575 | ;;
|
---|
576 | *) return
|
---|
577 | esac
|
---|
578 |
|
---|
579 |
|
---|
580 | IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
|
---|
581 | for f in `cat packages`; do
|
---|
582 | IFS=$saveIFS # Restore the system defaults
|
---|
583 | LOC_add_patches_entry \
|
---|
584 | `echo $f | sed -e 's/-version//' \
|
---|
585 | -e 's/-file.*//' \
|
---|
586 | -e 's/"//g' \
|
---|
587 | -e 's/uclibc/uClibc/'`
|
---|
588 | done
|
---|
589 |
|
---|
590 | rm -f patcheslist_.wget
|
---|
591 |
|
---|
592 | echo " ...OK"
|
---|
593 | }
|
---|
594 |
|
---|
595 |
|
---|
596 | #----------------------------#
|
---|
597 | extract_commands() { #
|
---|
598 | #----------------------------#
|
---|
599 | local saveIFS=$IFS
|
---|
600 |
|
---|
601 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
602 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
603 | exit 1"
|
---|
604 |
|
---|
605 | cd $JHALFSDIR
|
---|
606 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
607 |
|
---|
608 | # Start clean
|
---|
609 | if [ -d commands ]; then
|
---|
610 | rm -rf commands
|
---|
611 | mkdir -v commands
|
---|
612 | fi
|
---|
613 | echo -n "Extracting commands for"
|
---|
614 |
|
---|
615 | # Dump the commands in shell script form from the HLFS book.
|
---|
616 | case ${PROGNAME} in
|
---|
617 | clfs)
|
---|
618 | echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
|
---|
619 | xsltproc --nonet \
|
---|
620 | --xinclude \
|
---|
621 | --stringparam method $METHOD \
|
---|
622 | --stringparam testsuite $TEST \
|
---|
623 | --stringparam vim-lang $VIMLANG \
|
---|
624 | --stringparam timezone $TIMEZONE \
|
---|
625 | --stringparam page $PAGE \
|
---|
626 | --stringparam lang $LANG \
|
---|
627 | --stringparam keymap $KEYMAP \
|
---|
628 | -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
|
---|
629 | ;;
|
---|
630 | hlfs)
|
---|
631 | echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
|
---|
632 | xsltproc --nonet \
|
---|
633 | --xinclude \
|
---|
634 | --stringparam model $MODEL \
|
---|
635 | --stringparam testsuite $TEST \
|
---|
636 | --stringparam timezone $TIMEZONE \
|
---|
637 | --stringparam page $PAGE \
|
---|
638 | --stringparam lang $LANG \
|
---|
639 | --stringparam lc_all $LC_ALL \
|
---|
640 | --stringparam keymap $KEYMAP \
|
---|
641 | --stringparam grsecurity_host $GRSECURITY_HOST \
|
---|
642 | -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
643 | ;;
|
---|
644 | lfs)
|
---|
645 | echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
|
---|
646 | xsltproc --nonet \
|
---|
647 | --xinclude \
|
---|
648 | --stringparam testsuite $TEST \
|
---|
649 | --stringparam vim-lang $VIMLANG \
|
---|
650 | --stringparam timezone $TIMEZONE \
|
---|
651 | --stringparam page $PAGE \
|
---|
652 | --stringparam lang $LANG \
|
---|
653 | -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
654 | ;;
|
---|
655 | blfs)
|
---|
656 | echo -n " ${L_arrow}${BOLD}BLFS${R_arrow} build"
|
---|
657 | xsltproc --nonet \
|
---|
658 | --xinclude \
|
---|
659 | --stringparam testsuite $TEST \
|
---|
660 | --stringparam server $SERVER \
|
---|
661 | -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
662 | ;;
|
---|
663 | *) exit 1
|
---|
664 | esac
|
---|
665 |
|
---|
666 | echo " ...OK"
|
---|
667 |
|
---|
668 | # Make the scripts executable.
|
---|
669 | chmod -R +x $JHALFSDIR/${PROGNAME}-commands
|
---|
670 |
|
---|
671 | # Grab the patches and package names.
|
---|
672 | for i in patches packages ; do
|
---|
673 | rm -f $i
|
---|
674 | done
|
---|
675 | #
|
---|
676 | case "${PROGNAME}" in
|
---|
677 | clfs)
|
---|
678 | ################################
|
---|
679 | # A LOCAL function
|
---|
680 | # xx_.wget contains arch specific files but in URL format
|
---|
681 | # Build a file with only arch specific files.. small ugly..
|
---|
682 | LOC_add_packages_entry() {
|
---|
683 | local fileMATCH aFILE
|
---|
684 |
|
---|
685 | # Deal with a non-standard format
|
---|
686 | if [[ "$1" = "clfs-bootscripts" ]]; then
|
---|
687 | set -- "bootscripts-cross-lfs" $2
|
---|
688 | fi
|
---|
689 | fileMATCH="/$1"
|
---|
690 |
|
---|
691 | # format.. Filename-Version or FilenameVersion
|
---|
692 | for aFILE in `grep ${fileMATCH}-*[[:digit:]] packageslist_.wget`; do
|
---|
693 | # Block vim-x.x-lang file, will add it later based on config flag
|
---|
694 | if [[ ! "${aFILE}" =~ "vim-$2-lang" ]]; then
|
---|
695 | echo "$1-version \"$2\"" >> packages
|
---|
696 | fi
|
---|
697 | done
|
---|
698 | }
|
---|
699 | #################################
|
---|
700 |
|
---|
701 | # We only want a list arch specific files..
|
---|
702 | # Unfortunately this script produces URL's which must be converted to a std format
|
---|
703 | echo -n "Creating CLFS ${L_arrow}${BOLD}${ARCH}${R_arrow} specific packages file"
|
---|
704 | xsltproc -xinclude \
|
---|
705 | -o packageslist_.wget \
|
---|
706 | packageslist.xsl \
|
---|
707 | $BOOK/materials/${ARCH}-chapter.xml
|
---|
708 |
|
---|
709 | # This has the correct format but contains packages from every book
|
---|
710 | grep "\-version " $BOOK/packages.ent | sed -e 's@<!ENTITY @@' \
|
---|
711 | -e 's@">@"@' \
|
---|
712 | -e '/generic/d' > packages.tmp
|
---|
713 | # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
|
---|
714 | # separates each iteration by lines.
|
---|
715 | # Modify the 'internal field separator' to break on 'LF' only
|
---|
716 | IFS=$'\x0A'
|
---|
717 | for f in `cat packages.tmp`; do
|
---|
718 | IFS=$saveIFS # Restore the system defaults
|
---|
719 | LOC_add_packages_entry \
|
---|
720 | `echo $f | sed -e 's/-version//' \
|
---|
721 | -e 's/-file.*//' \
|
---|
722 | -e 's/"//g'`
|
---|
723 | done
|
---|
724 |
|
---|
725 | rm -f packageslist_.wget packages.tmp
|
---|
726 |
|
---|
727 | echo " ...OK"
|
---|
728 | ;;
|
---|
729 |
|
---|
730 | hlfs)
|
---|
731 | echo -n "Creating <${PROGNAME}> specific packages file"
|
---|
732 | grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
|
---|
733 | -e 's@">@"@' \
|
---|
734 | -e '/generic/d' >> packages
|
---|
735 | echo " ...OK"
|
---|
736 | ;;
|
---|
737 |
|
---|
738 | lfs)
|
---|
739 | echo -n "Creating <${PROGNAME}> specific packages file"
|
---|
740 | grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
|
---|
741 | -e 's@">@"@' \
|
---|
742 | -e '/generic/d' >> packages
|
---|
743 | echo `grep "glibc" packages | sed 's@glibc@glibc-libidn@'` >> packages
|
---|
744 | echo `grep "udev-config-file" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@'` >> packages
|
---|
745 | echo " ...OK"
|
---|
746 | ;;
|
---|
747 | esac
|
---|
748 |
|
---|
749 | # Download the vim-lang package if it must be installed
|
---|
750 | if [ "$VIMLANG" = "1" ] && [ ! "$PROGNAME" = "hlfs" ] ; then
|
---|
751 | echo `grep "vim" packages | sed 's@vim@&-lang@'` >> packages
|
---|
752 | fi
|
---|
753 |
|
---|
754 | # Create the patches file
|
---|
755 | case "${PROGNAME}" in
|
---|
756 | hlfs)
|
---|
757 | build_patches_file ;;
|
---|
758 | clfs )
|
---|
759 | build_patches_file ;;
|
---|
760 | lfs)
|
---|
761 | grep "^<\!ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
|
---|
762 | ;;
|
---|
763 | blfs) ;;
|
---|
764 | *) exit 1
|
---|
765 | esac
|
---|
766 |
|
---|
767 | # Done. Moving on...
|
---|
768 | get_sources
|
---|
769 | }
|
---|
770 |
|
---|
771 |
|
---|
772 | #----------------------------#
|
---|
773 | download() { # Download file, write name to MISSING_FILES.DMP if an error
|
---|
774 | #----------------------------#
|
---|
775 | cd $BUILDDIR/sources
|
---|
776 |
|
---|
777 | # Hackish fix for the bash-doc, glibc-{linuxthreads,libidn}
|
---|
778 | # that don't conform to norms in the URL scheme.
|
---|
779 | DIR=`echo $1 | sed 's@-doc@@;s@-linuxthreads@@;s@-libidn@@;s@-testsuite@@'`
|
---|
780 |
|
---|
781 | # If the file exists in the archive copy it to the $BUILDDIR/sources dir
|
---|
782 | # MD5SUM is assumed to be correct from previous download
|
---|
783 | if [ ! -z ${SRC_ARCHIVE} ] &&
|
---|
784 | [ -d ${SRC_ARCHIVE} ] &&
|
---|
785 | [ -f ${SRC_ARCHIVE}/$2 ]; then
|
---|
786 | cp ${SRC_ARCHIVE}/$2 .
|
---|
787 | echo "$2: -- ok"
|
---|
788 | return
|
---|
789 | fi
|
---|
790 |
|
---|
791 | # Find the md5 sum for this package.
|
---|
792 | if [ $2 != MD5SUMS ] ; then
|
---|
793 | set +e
|
---|
794 | MD5=`grep " $2" MD5SUMS`
|
---|
795 | if [ $? -ne 0 ]; then
|
---|
796 | set -e
|
---|
797 | echo "${RED}$2 not found in MD5SUMS${OFF}"
|
---|
798 | echo "$2 not found in MD5SUMS" >> MISSING_FILES.DMP
|
---|
799 | return
|
---|
800 | fi
|
---|
801 | set -e
|
---|
802 | fi
|
---|
803 |
|
---|
804 | if [ ! -f $2 ] ; then
|
---|
805 | case $DL in
|
---|
806 | wgetFTP ) wget --passive $FTP/$DIR/$2 ;;
|
---|
807 | wget ) wget $HTTP/$DIR/$2 ;;
|
---|
808 | curl ) `curl -# $FTP/$DIR/$2 -o $2` ;;
|
---|
809 | * ) echo "$DL not supported at this time." ;;
|
---|
810 | esac
|
---|
811 | elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
|
---|
812 | case $DL in
|
---|
813 | wgetFTP ) wget --passive -c $FTP/$DIR/$2 ;;
|
---|
814 | wget ) wget -c $HTTP/$DIR/$2 ;;
|
---|
815 | curl ) `curl -# -C - $FTP/$DIR/$2 -o $2` ;;
|
---|
816 | * ) echo "$DL not supported at this time." ;;
|
---|
817 | esac
|
---|
818 | fi
|
---|
819 |
|
---|
820 | if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
|
---|
821 | exit 1
|
---|
822 | fi
|
---|
823 | if [ $2 != MD5SUMS ] ; then
|
---|
824 | echo `grep "$MD5" MD5SUMS` >> MD5SUMS-$VERSION
|
---|
825 | fi
|
---|
826 |
|
---|
827 | # If we make it this far we should copy the freshly downloaded file
|
---|
828 | # to the source archive.
|
---|
829 | if [ ! -z ${SRC_ARCHIVE} ] &&
|
---|
830 | [ -d ${SRC_ARCHIVE} ] &&
|
---|
831 | [ -w ${SRC_ARCHIVE} ] &&
|
---|
832 | [ $2 != MD5SUMS ]; then
|
---|
833 | echo "Store file:<$2> in package archive"
|
---|
834 | cp -v $2 ${SRC_ARCHIVE}
|
---|
835 | fi
|
---|
836 |
|
---|
837 | }
|
---|
838 |
|
---|
839 |
|
---|
840 | #----------------------------#
|
---|
841 | get_sources() {
|
---|
842 | #----------------------------#
|
---|
843 |
|
---|
844 | # Test if the packages must be downloaded
|
---|
845 | if [ "$HPKG" = "1" ] ; then
|
---|
846 |
|
---|
847 | # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
|
---|
848 | # separates each iteration by lines.
|
---|
849 | # Modify the 'internal field separator' to break on 'LF' only
|
---|
850 | IFS=$'\x0A'
|
---|
851 |
|
---|
852 | if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
|
---|
853 | cd $BUILDDIR/sources
|
---|
854 | if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
|
---|
855 | if [ -f MD5SUMS-$VERSION ] ; then rm MD5SUMS-$VERSION ; fi
|
---|
856 | if [ -f MISSING_FILES.DMP ] ; then rm MISSING_FILES.DMP ; fi
|
---|
857 |
|
---|
858 | download "" MD5SUMS
|
---|
859 |
|
---|
860 | # Iterate through each package and grab it, along with any patches it needs.
|
---|
861 | for i in `cat $JHALFSDIR/packages` ; do
|
---|
862 | PKG=`echo $i | sed -e 's/-version.*//' -e 's/-file.*//'`
|
---|
863 |
|
---|
864 | # There are some entities that aren't valid packages.
|
---|
865 | if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
|
---|
866 |
|
---|
867 | VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
|
---|
868 | case $PKG in
|
---|
869 | tcl) FILE="$PKG$VRS-src.tar.bz2" ;;
|
---|
870 | vim-lang) PKG="vim"
|
---|
871 | FILE="vim-$VRS-lang.tar.bz2" ;;
|
---|
872 | udev-config) PKG="udev"
|
---|
873 | FILE="$VRS" ;;
|
---|
874 | *) FILE="$PKG-$VRS.tar.bz2" ;;
|
---|
875 | esac
|
---|
876 | download $PKG $FILE
|
---|
877 |
|
---|
878 | # Download any associated patches
|
---|
879 | for patch in `grep "&$PKG-version" $JHALFSDIR/patches` ; do
|
---|
880 | PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
|
---|
881 | download $PKG $PATCH
|
---|
882 | done
|
---|
883 | done
|
---|
884 | if [[ -s $BUILDDIR/sources/MISSING_FILES.DMP ]]; then
|
---|
885 | echo -e "\n\n${tab_}${RED} One or more files were not retrieved.\n${tab_} Check ${L_arrow}$BUILDDIR/sources/MISSING_FILES.DMP${R_arrow} for names ${OFF}\n\n"
|
---|
886 | fi
|
---|
887 | fi
|
---|
888 | }
|
---|
889 |
|
---|
890 | #-----------------------------------------------#
|
---|
891 | _IS_() # Function to test build scripts names
|
---|
892 | #-----------------------------------------------#
|
---|
893 | {
|
---|
894 | # Returns substr $2 or null str
|
---|
895 | # Must use string testing
|
---|
896 | case $1 in
|
---|
897 | *$2*) echo "$2" ;;
|
---|
898 | *) echo "" ;;
|
---|
899 | esac
|
---|
900 | }
|
---|