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_unpack2() { #
|
---|
233 | #----------------------------------#
|
---|
234 | local FILE=$1
|
---|
235 | (
|
---|
236 | cat << EOF
|
---|
237 | @\$(call unpack2,$FILE)
|
---|
238 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
239 | echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
|
---|
240 | EOF
|
---|
241 | ) >> $MKFILE.tmp
|
---|
242 | }
|
---|
243 |
|
---|
244 |
|
---|
245 | #=============================#
|
---|
246 | wrt_unpack3() { # Unpack and set 'ROOT' var
|
---|
247 | #=============================#
|
---|
248 | local FILE=$1
|
---|
249 | (
|
---|
250 | cat << EOF
|
---|
251 | @\$(call unpack3,$FILE)
|
---|
252 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
253 | echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
|
---|
254 | EOF
|
---|
255 | ) >> $MKFILE.tmp
|
---|
256 | }
|
---|
257 |
|
---|
258 |
|
---|
259 |
|
---|
260 | #----------------------------------#
|
---|
261 | wrt_target_vars() { # Target vars for hlfs (cross-build method)
|
---|
262 | #----------------------------------#
|
---|
263 | (
|
---|
264 | cat << EOF
|
---|
265 | @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
|
---|
266 | echo "export ldso=/lib/${LOADER}" >> envars
|
---|
267 | EOF
|
---|
268 | ) >> $MKFILE.tmp
|
---|
269 |
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | #----------------------------------#
|
---|
274 | wrt_run_as_su() { #
|
---|
275 | #----------------------------------#
|
---|
276 | local this_script=$1
|
---|
277 | local file=$2
|
---|
278 | (
|
---|
279 | cat << EOF
|
---|
280 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
|
---|
281 | su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 && \\
|
---|
282 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
|
---|
283 | EOF
|
---|
284 | ) >> $MKFILE.tmp
|
---|
285 | }
|
---|
286 |
|
---|
287 |
|
---|
288 | #==================================#
|
---|
289 | wrt_run_as_lfs() { # header to log file, execute script, footer to log file
|
---|
290 | #==================================#
|
---|
291 | local this_script=$1
|
---|
292 | local file=$2
|
---|
293 | (
|
---|
294 | cat << EOF
|
---|
295 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
|
---|
296 | su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 && \\
|
---|
297 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
|
---|
298 | EOF
|
---|
299 | ) >> $MKFILE.tmp
|
---|
300 | }
|
---|
301 |
|
---|
302 |
|
---|
303 | #----------------------------------#
|
---|
304 | wrt_run_as_root() { #
|
---|
305 | #----------------------------------#
|
---|
306 | local this_script=$1
|
---|
307 | local file=$2
|
---|
308 | (
|
---|
309 | cat << EOF
|
---|
310 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
|
---|
311 | export LFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 && \\
|
---|
312 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
|
---|
313 | EOF
|
---|
314 | ) >> $MKFILE.tmp
|
---|
315 | }
|
---|
316 |
|
---|
317 |
|
---|
318 | #=============================#
|
---|
319 | wrt_run_as_root2() { # Some scripts must be run as root..
|
---|
320 | #=============================#
|
---|
321 | local this_script=$1
|
---|
322 | local file=$2
|
---|
323 | (
|
---|
324 | cat << EOF
|
---|
325 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \`\n" >logs/$this_script && \\
|
---|
326 | source envars && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 && \\
|
---|
327 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \`\n" >>logs/$this_script
|
---|
328 | EOF
|
---|
329 | ) >> $MKFILE.tmp
|
---|
330 | }
|
---|
331 |
|
---|
332 |
|
---|
333 | #----------------------------------#
|
---|
334 | wrt_remove_build_dirs() { #
|
---|
335 | #----------------------------------#
|
---|
336 | local name=$1
|
---|
337 | (
|
---|
338 | cat << EOF
|
---|
339 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
340 | rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
|
---|
341 | if [ -e \$(MOUNT_PT)\$(SRC)/$name-build ]; then \\
|
---|
342 | rm -r \$(MOUNT_PT)\$(SRC)/$name-build; \\
|
---|
343 | fi;
|
---|
344 | EOF
|
---|
345 | ) >> $MKFILE.tmp
|
---|
346 | }
|
---|
347 |
|
---|
348 |
|
---|
349 | #----------------------------------#
|
---|
350 | wrt_remove_build_dirs2() { #
|
---|
351 | #----------------------------------#
|
---|
352 | local name=$1
|
---|
353 | (
|
---|
354 | cat << EOF
|
---|
355 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
356 | rm -r \$(SRC)/\$\$ROOT && \\
|
---|
357 | if [ -e \$(SRC)/$name-build ]; then \\
|
---|
358 | rm -r \$(SRC)/$name-build; \\
|
---|
359 | fi;
|
---|
360 | EOF
|
---|
361 | ) >> $MKFILE.tmp
|
---|
362 | }
|
---|
363 |
|
---|
364 |
|
---|
365 |
|
---|
366 | #----------------------------------#
|
---|
367 | wrt_run_as_chroot1() { #
|
---|
368 | #----------------------------------#
|
---|
369 | local this_script=$1
|
---|
370 | local file=$2
|
---|
371 | (
|
---|
372 | cat << EOF
|
---|
373 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/${this_script} && \\
|
---|
374 | \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' && \\
|
---|
375 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/${this_script}
|
---|
376 | EOF
|
---|
377 | ) >> $MKFILE.tmp
|
---|
378 | }
|
---|
379 |
|
---|
380 |
|
---|
381 | #----------------------------------#
|
---|
382 | wrt_run_as_chroot2() { #
|
---|
383 | #----------------------------------#
|
---|
384 | local this_script=$1
|
---|
385 | local file=$2
|
---|
386 | (
|
---|
387 | cat << EOF
|
---|
388 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/${this_script} && \\
|
---|
389 | \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' && \\
|
---|
390 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/${this_script}
|
---|
391 | EOF
|
---|
392 | ) >> $MKFILE.tmp
|
---|
393 | }
|
---|
394 |
|
---|
395 |
|
---|
396 | #----------------------------------#
|
---|
397 | wrt_copy_fstab() { #
|
---|
398 | #----------------------------------#
|
---|
399 | local i=$1
|
---|
400 | (
|
---|
401 | cat << EOF
|
---|
402 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$i && \\
|
---|
403 | cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1 && \\
|
---|
404 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$i
|
---|
405 | EOF
|
---|
406 | ) >> $MKFILE.tmp
|
---|
407 | }
|
---|
408 |
|
---|
409 | #----------------------------------#
|
---|
410 | wrt_copy_fstab2() { #
|
---|
411 | #----------------------------------#
|
---|
412 | local i=$1
|
---|
413 | (
|
---|
414 | cat << EOF
|
---|
415 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \`\n" >logs/$i && \\
|
---|
416 | cp -v $FSTAB /etc/fstab >>logs/$i 2>&1 && \\
|
---|
417 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \`\n" >>logs/$i
|
---|
418 | EOF
|
---|
419 | ) >> $MKFILE.tmp
|
---|
420 | }
|
---|
421 |
|
---|
422 |
|
---|
423 | #----------------------------------#
|
---|
424 | wrt_export_pkgdir() { #
|
---|
425 | #----------------------------------#
|
---|
426 | (
|
---|
427 | cat << EOF
|
---|
428 | @echo "export PKGDIR=\$(SRC)/binutils-build" > envars
|
---|
429 | EOF
|
---|
430 | ) >> $MKFILE.tmp
|
---|
431 | }
|
---|
432 |
|
---|
433 |
|
---|
434 | #----------------------------#
|
---|
435 | run_make() {
|
---|
436 | #----------------------------#
|
---|
437 | # Test if make must be run.
|
---|
438 | if [ "$RUNMAKE" = "1" ] ; then
|
---|
439 | # Test to make sure we're running the build as root
|
---|
440 | if [ "$UID" != "0" ] ; then
|
---|
441 | echo "You must be logged in as root to successfully build LFS."
|
---|
442 | exit 1
|
---|
443 | fi
|
---|
444 | # Build the system
|
---|
445 | if [ -e $MKFILE ] ; then
|
---|
446 | echo -ne "Building the LFS system...\n"
|
---|
447 | cd $JHALFSDIR && make -f ${PROGNAME}-Makefile
|
---|
448 | echo -ne "done\n"
|
---|
449 | fi
|
---|
450 | fi
|
---|
451 | }
|
---|
452 |
|
---|
453 |
|
---|
454 | #----------------------------#
|
---|
455 | clean_builddir() {
|
---|
456 | #----------------------------#
|
---|
457 | # Test if the clean must be done.
|
---|
458 | if [ "$CLEAN" = "1" ] ; then
|
---|
459 | # Test to make sure we're running the clean as root
|
---|
460 | if [ "$UID" != "0" ] ; then
|
---|
461 | echo "You must be logged in as root to clean the build directory."
|
---|
462 | exit 1
|
---|
463 | fi
|
---|
464 | # Test to make sure that the build directory was populated by jhalfs
|
---|
465 | if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
|
---|
466 | echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
|
---|
467 | exit 1
|
---|
468 | else
|
---|
469 | # Clean the build directory
|
---|
470 | echo -ne "Cleaning $BUILDDIR...\n"
|
---|
471 | rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,usr,var}
|
---|
472 | echo -ne "Cleaning $JHALFSDIR...\n"
|
---|
473 | rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,commands,logs,Makefile,dump-lfs-scripts.xsl,functions,packages,patches}
|
---|
474 | echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
|
---|
475 | rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
|
---|
476 | echo -ne "done\n"
|
---|
477 | fi
|
---|
478 | fi
|
---|
479 | }
|
---|
480 |
|
---|
481 | #----------------------------#
|
---|
482 | get_book() {
|
---|
483 | #----------------------------#
|
---|
484 | cd $JHALFSDIR
|
---|
485 |
|
---|
486 | if [ -z $WC ] ; then
|
---|
487 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
488 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
489 | exit 1"
|
---|
490 | echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
|
---|
491 |
|
---|
492 | case $PROGNAME in
|
---|
493 | lfs) svn_root="LFS" ;;
|
---|
494 | hlfs) svn_root="HLFS" ;;
|
---|
495 | clfs) svn_root="cross-lfs" ;;
|
---|
496 | blfs) svn_root="BLFS" ;;
|
---|
497 | *) echo "BOOK not defined in function <get_book>"
|
---|
498 | exit 1 ;;
|
---|
499 | esac
|
---|
500 | # Grab a fresh LFS book if it's missing, otherwise, update it from the
|
---|
501 | # repo. If we've already extracted the commands, move on to getting the
|
---|
502 | # sources.
|
---|
503 | if [ -d ${PROGNAME}-$LFSVRS ] ; then
|
---|
504 | cd ${PROGNAME}-$LFSVRS
|
---|
505 | if LC_ALL=C svn up | grep -q At && test -d $JHALFSDIR/commands && \
|
---|
506 | test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
|
---|
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 | get_sources
|
---|
512 | else
|
---|
513 | echo -ne "done\n"
|
---|
514 | # Set the canonical book version
|
---|
515 | cd $JHALFSDIR
|
---|
516 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
517 | extract_commands
|
---|
518 | fi
|
---|
519 | else
|
---|
520 | case $LFSVRS in
|
---|
521 | development)
|
---|
522 | svn co $SVN/${svn_root}/trunk/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
|
---|
523 | alphabetical)
|
---|
524 | svn co $SVN/${svn_root}/branches/$LFSVRS/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
|
---|
525 | udev_update)
|
---|
526 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
|
---|
527 | esac
|
---|
528 | echo -ne "done\n"
|
---|
529 | # Set the canonical book version
|
---|
530 | cd $JHALFSDIR
|
---|
531 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
532 | extract_commands
|
---|
533 | fi
|
---|
534 | else
|
---|
535 | echo -ne "Using $BOOK as book's sources ...\n"
|
---|
536 | # Set the canonical book version
|
---|
537 | cd $JHALFSDIR
|
---|
538 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
539 | extract_commands
|
---|
540 | fi
|
---|
541 | }
|
---|
542 |
|
---|
543 |
|
---|
544 | #----------------------------#
|
---|
545 | build_patches_file() { # Supply a suitably formated list of patches.
|
---|
546 | #----------------------------#
|
---|
547 | local saveIFS=$IFS
|
---|
548 | local IFS
|
---|
549 |
|
---|
550 | rm -f patches
|
---|
551 |
|
---|
552 | LOC_add_patches_entry() {
|
---|
553 | for f in `grep "/$1-" patcheslist_.wget`; do
|
---|
554 | basename $f | sed "s|${2}|\&${1}-version;|" >> patches
|
---|
555 | done
|
---|
556 | }
|
---|
557 |
|
---|
558 | case ${PROGNAME} in
|
---|
559 | hlfs)
|
---|
560 | echo -n "Creating the ${L_arrow}${BOLD}HLFS${R_arrow} specific patcheslist_.wget file"
|
---|
561 | xsltproc --nonet \
|
---|
562 | --xinclude \
|
---|
563 | --stringparam model $MODEL \
|
---|
564 | -o patcheslist_.wget \
|
---|
565 | patcheslist.xsl \
|
---|
566 | $BOOK/chapter04/patches.xml
|
---|
567 | #> /dev/null 2>&1
|
---|
568 |
|
---|
569 | # .... U G L Y .... what to do with the grsecurity patch to the kernel..
|
---|
570 | for f in `grep "/grsecurity-" patcheslist_.wget`; do
|
---|
571 | basename $f >> patches
|
---|
572 | done
|
---|
573 | ;;
|
---|
574 |
|
---|
575 | clfs) # Pull out a list of arch specific patches
|
---|
576 | echo -n "Creating ${L_arrow}${BOLD}$ARCH${R_arrow} specific patcheslist_.wget file"
|
---|
577 | xsltproc -xinclude \
|
---|
578 | -o patcheslist_.wget \
|
---|
579 | patcheslist.xsl \
|
---|
580 | $BOOK/${ARCH}-index.xml
|
---|
581 | ;;
|
---|
582 | *) return
|
---|
583 | esac
|
---|
584 |
|
---|
585 |
|
---|
586 | IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
|
---|
587 | for f in `cat packages`; do
|
---|
588 | IFS=$saveIFS # Restore the system defaults
|
---|
589 | LOC_add_patches_entry \
|
---|
590 | `echo $f | sed -e 's/-version//' \
|
---|
591 | -e 's/-file.*//' \
|
---|
592 | -e 's/"//g' \
|
---|
593 | -e 's/uclibc/uClibc/'`
|
---|
594 | done
|
---|
595 |
|
---|
596 | echo " ...OK"
|
---|
597 | }
|
---|
598 |
|
---|
599 |
|
---|
600 | #----------------------------#
|
---|
601 | extract_commands() { #
|
---|
602 | #----------------------------#
|
---|
603 | local saveIFS=$IFS
|
---|
604 |
|
---|
605 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
606 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
607 | exit 1"
|
---|
608 |
|
---|
609 | cd $JHALFSDIR
|
---|
610 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
611 |
|
---|
612 | # Start clean
|
---|
613 | if [ -d commands ]; then
|
---|
614 | rm -rf commands
|
---|
615 | mkdir -v commands
|
---|
616 | fi
|
---|
617 | echo -n "Extracting commands for"
|
---|
618 |
|
---|
619 | # Dump the commands in shell script form from the HLFS book.
|
---|
620 | case ${PROGNAME} in
|
---|
621 | clfs)
|
---|
622 | echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
|
---|
623 | xsltproc --xinclude \
|
---|
624 | --nonet \
|
---|
625 | --output ./${PROGNAME}-commands/ \
|
---|
626 | $BOOK/stylesheets/dump-commands.xsl $BOOK/$ARCH-index.xml
|
---|
627 | ;;
|
---|
628 | hlfs)
|
---|
629 | echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS architecture"
|
---|
630 | xsltproc --nonet \
|
---|
631 | --xinclude \
|
---|
632 | --stringparam model $MODEL \
|
---|
633 | --stringparam testsuite $TEST \
|
---|
634 | --stringparam timezone $TIMEZONE \
|
---|
635 | --stringparam page $PAGE \
|
---|
636 | --stringparam lang $LANG \
|
---|
637 | --stringparam lc_all $LC_ALL \
|
---|
638 | --stringparam keymap $KEYMAP \
|
---|
639 | --stringparam grsecurity_host $GRSECURITY_HOST \
|
---|
640 | -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
641 | ;;
|
---|
642 | lfs)
|
---|
643 | echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
|
---|
644 | xsltproc --nonet \
|
---|
645 | --xinclude \
|
---|
646 | --stringparam testsuite $TEST \
|
---|
647 | --stringparam vim-lang $VIMLANG \
|
---|
648 | --stringparam timezone $TIMEZONE \
|
---|
649 | --stringparam page $PAGE \
|
---|
650 | --stringparam lang $LANG \
|
---|
651 | -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
652 | ;;
|
---|
653 | blfs)
|
---|
654 | echo -n " ${L_arrow}${BOLD}BLFS${R_arrow} build"
|
---|
655 | xsltproc --nonet \
|
---|
656 | --xinclude \
|
---|
657 | --stringparam testsuite $TEST \
|
---|
658 | --stringparam server $SERVER \
|
---|
659 | -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
660 | ;;
|
---|
661 | *) exit 1
|
---|
662 | esac
|
---|
663 |
|
---|
664 | echo " ...OK"
|
---|
665 |
|
---|
666 | # Make the scripts executable.
|
---|
667 | chmod -R +x $JHALFSDIR/${PROGNAME}-commands
|
---|
668 |
|
---|
669 | # Grab the patches and package names.
|
---|
670 | for i in patches packages ; do
|
---|
671 | rm -f $i
|
---|
672 | done
|
---|
673 | #
|
---|
674 | case "${PROGNAME}" in
|
---|
675 | clfs)
|
---|
676 | ################################
|
---|
677 | # A LOCAL function
|
---|
678 | # xx_.wget contains arch specific files but in URL format
|
---|
679 | # Build a file with only arch specific files.. small ugly..
|
---|
680 | LOC_add_packages_entry() {
|
---|
681 | local fileMATCH aFILE
|
---|
682 |
|
---|
683 | fileMATCH="/$1"
|
---|
684 | # format.. Filename-Version or FilenameVersion
|
---|
685 | for aFILE in `grep ${fileMATCH}-*[[:digit:]] packageslist_.wget`; do
|
---|
686 | # Block vim-x.x-lang file, will add it later based on config flag
|
---|
687 | if [[ ! "${aFILE}" =~ "vim-$2-lang" ]]; then
|
---|
688 | echo "$1-version \"$2\"" >> packages
|
---|
689 | fi
|
---|
690 | done
|
---|
691 | }
|
---|
692 | #################################
|
---|
693 |
|
---|
694 | # We only want a list arch specific files..
|
---|
695 | # Unfortunately this script produces URL's which must be converted to a std format
|
---|
696 | echo -n "Creating CLFS ${L_arrow}${BOLD}${ARCH}${R_arrow} specific packageslist_.wget file"
|
---|
697 | xsltproc -xinclude \
|
---|
698 | -o packageslist_.wget \
|
---|
699 | packageslist.xsl \
|
---|
700 | $BOOK/${ARCH}-index.xml
|
---|
701 |
|
---|
702 | # This has the correct format but contains packages from every book
|
---|
703 | grep "\-version " $BOOK/packages.ent | sed -e 's@<!ENTITY @@' \
|
---|
704 | -e 's@">@"@' \
|
---|
705 | -e '/generic/d' > packages.tmp
|
---|
706 | # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
|
---|
707 | # separates each iteration by lines.
|
---|
708 | # Modify the 'internal field separator' to break on 'LF' only
|
---|
709 | IFS=$'\x0A'
|
---|
710 | for f in `cat packages.tmp`; do
|
---|
711 | IFS=$saveIFS # Restore the system defaults
|
---|
712 | LOC_add_packages_entry \
|
---|
713 | `echo $f | sed -e 's/-version//' \
|
---|
714 | -e 's/-file.*//' \
|
---|
715 | -e 's/"//g'`
|
---|
716 | done
|
---|
717 | echo " ...OK"
|
---|
718 | ;;
|
---|
719 |
|
---|
720 | *)
|
---|
721 | echo -n "Creating <${PROGNAME}> specific packageslist_.wget file"
|
---|
722 | grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
|
---|
723 | -e 's@">@"@' \
|
---|
724 | -e '/generic/d' >> packages
|
---|
725 | ;;
|
---|
726 | esac
|
---|
727 |
|
---|
728 | # Download the vim-lang package if it must be installed
|
---|
729 | if [ "$VIMLANG" = "1" ] && [ ! "$PROGNAME" = "hlfs" ] ; then
|
---|
730 | echo `grep "vim" packages | sed 's@vim@&-lang@'` >> packages
|
---|
731 | fi
|
---|
732 | echo `grep "udev-config-file" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@'` >> packages
|
---|
733 |
|
---|
734 | # There is no useful patches.ent file so we will create one.
|
---|
735 | case "${PROGNAME}" in
|
---|
736 | hlfs)
|
---|
737 | build_patches_file ;;
|
---|
738 | clfs )
|
---|
739 | build_patches_file ;;
|
---|
740 | lfs)
|
---|
741 | grep "^<\!ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
|
---|
742 | ;;
|
---|
743 | blfs) ;;
|
---|
744 | *) exit 1
|
---|
745 | esac
|
---|
746 |
|
---|
747 | # Done. Moving on...
|
---|
748 | get_sources
|
---|
749 | }
|
---|
750 |
|
---|
751 |
|
---|
752 | #----------------------------#
|
---|
753 | download() { # Download file, write name to MISSING_FILES.DMP if an error
|
---|
754 | #----------------------------#
|
---|
755 | cd $BUILDDIR/sources
|
---|
756 |
|
---|
757 | # Hackish fix for the bash-doc, glibc-{linuxthreads,libidn}
|
---|
758 | # that don't conform to norms in the URL scheme.
|
---|
759 | DIR=`echo $1 | sed 's@-doc@@;s@-linuxthreads@@;s@-libidn@@;s@-testsuite@@'`
|
---|
760 |
|
---|
761 | # If the file exists in the archive copy it to the $BUILDDIR/sources dir
|
---|
762 | # MD5SUM is assumed to be correct from previous download
|
---|
763 | if [ ! -z ${SRC_ARCHIVE} ] &&
|
---|
764 | [ -d ${SRC_ARCHIVE} ] &&
|
---|
765 | [ -f ${SRC_ARCHIVE}/$2 ]; then
|
---|
766 | cp ${SRC_ARCHIVE}/$2 .
|
---|
767 | echo "$2: -- ok"
|
---|
768 | return
|
---|
769 | fi
|
---|
770 |
|
---|
771 | # Find the md5 sum for this package.
|
---|
772 | if [ $2 != MD5SUMS ] ; then
|
---|
773 | set +e
|
---|
774 | MD5=`grep " $2" MD5SUMS`
|
---|
775 | if [ $? -ne 0 ]; then
|
---|
776 | set -e
|
---|
777 | echo "${RED}$2 not found in MD5SUMS${OFF}"
|
---|
778 | echo "$2 not found in MD5SUMS" >> MISSING_FILES.DMP
|
---|
779 | return
|
---|
780 | fi
|
---|
781 | set -e
|
---|
782 | fi
|
---|
783 |
|
---|
784 | if [ ! -f $2 ] ; then
|
---|
785 | case $DL in
|
---|
786 | wget ) wget --passive $FTP/$DIR/$2 ;;
|
---|
787 | curl ) `curl -# $FTP/$DIR/$2 -o $2` ;;
|
---|
788 | * ) echo "$DL not supported at this time." ;;
|
---|
789 | esac
|
---|
790 | elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
|
---|
791 | case $DL in
|
---|
792 | wget ) wget --passive -c $FTP/$DIR/$2 ;;
|
---|
793 | curl ) `curl -# -C - $FTP/$DIR/$2 -o $2` ;;
|
---|
794 | * ) echo "$DL not supported at this time." ;;
|
---|
795 | esac
|
---|
796 | fi
|
---|
797 |
|
---|
798 | if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
|
---|
799 | exit 1
|
---|
800 | fi
|
---|
801 | if [ $2 != MD5SUMS ] ; then
|
---|
802 | echo `grep "$MD5" MD5SUMS` >> MD5SUMS-$VERSION
|
---|
803 | fi
|
---|
804 |
|
---|
805 | # If we make it this far we should copy the freshly downloaded file
|
---|
806 | # to the source archive.
|
---|
807 | if [ ! -z ${SRC_ARCHIVE} ] &&
|
---|
808 | [ -d ${SRC_ARCHIVE} ] &&
|
---|
809 | [ -w ${SRC_ARCHIVE} ] &&
|
---|
810 | [ $2 != MD5SUMS ]; then
|
---|
811 | echo "Store file:<$2> in package archive"
|
---|
812 | cp -v $2 ${SRC_ARCHIVE}
|
---|
813 | fi
|
---|
814 |
|
---|
815 | }
|
---|
816 |
|
---|
817 |
|
---|
818 | #----------------------------#
|
---|
819 | get_sources() {
|
---|
820 | #----------------------------#
|
---|
821 |
|
---|
822 | # Test if the packages must be downloaded
|
---|
823 | if [ "$HPKG" = "1" ] ; then
|
---|
824 |
|
---|
825 | # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
|
---|
826 | # separates each iteration by lines.
|
---|
827 | # Modify the 'internal field separator' to break on 'LF' only
|
---|
828 | IFS=$'\x0A'
|
---|
829 |
|
---|
830 | if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
|
---|
831 | cd $BUILDDIR/sources
|
---|
832 | if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
|
---|
833 | if [ -f MD5SUMS-$VERSION ] ; then rm MD5SUMS-$VERSION ; fi
|
---|
834 | if [ -f MISSING_FILES.DMP ] ; then rm MISSING_FILES.DMP ; fi
|
---|
835 |
|
---|
836 | download "" MD5SUMS
|
---|
837 |
|
---|
838 | # Iterate through each package and grab it, along with any patches it needs.
|
---|
839 | for i in `cat $JHALFSDIR/packages` ; do
|
---|
840 | PKG=`echo $i | sed -e 's/-version.*//' -e 's/-file.*//'`
|
---|
841 |
|
---|
842 | # There are some entities that aren't valid packages.
|
---|
843 | if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
|
---|
844 |
|
---|
845 | VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
|
---|
846 | case $PKG in
|
---|
847 | tcl) FILE="$PKG$VRS-src.tar.bz2" ;;
|
---|
848 | vim-lang) PKG="vim"
|
---|
849 | FILE="vim-$VRS-lang.tar.bz2" ;;
|
---|
850 | udev-config) PKG="udev"
|
---|
851 | FILE="$VRS" ;;
|
---|
852 | *) FILE="$PKG-$VRS.tar.bz2" ;;
|
---|
853 | esac
|
---|
854 | download $PKG $FILE
|
---|
855 |
|
---|
856 | # Download any associated patches
|
---|
857 | for patch in `grep "&$PKG-version" $JHALFSDIR/patches` ; do
|
---|
858 | PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
|
---|
859 | download $PKG $PATCH
|
---|
860 | done
|
---|
861 | done
|
---|
862 | fi
|
---|
863 | }
|
---|
864 |
|
---|
865 | #-----------------------------------------------#
|
---|
866 | _IS_() # Function to test build scripts names
|
---|
867 | #-----------------------------------------------#
|
---|
868 | {
|
---|
869 | # Returns substr $2 or null str
|
---|
870 | # Must use string testing
|
---|
871 | case $1 in
|
---|
872 | *$2*) echo "$2" ;;
|
---|
873 | *) echo "" ;;
|
---|
874 | esac
|
---|
875 | }
|
---|