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