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}==============================================================================${OFF}"
|
---|
28 | declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
|
---|
29 | declare -r STAR_BORDER="${BOLD}******************************************************************************${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 | ${RED}IMPORTANT:${OFF} Only supported command line switches are listed here.
|
---|
43 | For more fine-grained setups you must to edit the relevant
|
---|
44 | configuration files placed under ${BOLD}common/${OFF} and ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])/${OFF}
|
---|
45 |
|
---|
46 | Options:
|
---|
47 | ${BOLD} -h, --help${OFF}
|
---|
48 | print this help, then exit
|
---|
49 |
|
---|
50 | ${BOLD} -V, --version${OFF}
|
---|
51 | print version information, then exit
|
---|
52 |
|
---|
53 | ${BOLD} -B, --book VER${OFF}
|
---|
54 | use VER version of the book as the system to build.
|
---|
55 | Supported versions are: dev*, trunk, SVN
|
---|
56 | These are aliases for the Development version of {C,H,B}LFS
|
---|
57 |
|
---|
58 | ${BOLD} -D --directory DIR${OFF}
|
---|
59 | use DIR directory for building ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF}; all files jhalfs produces
|
---|
60 | will be in the directory DIR/jhalfs.
|
---|
61 | The current setting for BUILDDIR is "$BUILDDIR"
|
---|
62 |
|
---|
63 | ${BOLD} -G, --get-packages${OFF}
|
---|
64 | download the packages and patches. This assumes that the server declared
|
---|
65 | in the configuration file has the proper packages and patches for the
|
---|
66 | book version being processed.
|
---|
67 |
|
---|
68 | ${BOLD} -T, --testsuites N ${OFF}
|
---|
69 | Run test suites [0-3]
|
---|
70 | 0 = none
|
---|
71 | 1 = only chapter06 Glibc, GCC and Binutils testsuites
|
---|
72 | 2 = all chapter06 testsuites (in BLFS, alias to 1)
|
---|
73 | 3 = all chapter05 and chapter06 testsuites
|
---|
74 | In BLFS, 2 and 3 are aliases to 1
|
---|
75 | In CLFS, 3 is an alias to 2
|
---|
76 |
|
---|
77 | ${BOLD} -W, --working-copy DIR${OFF}
|
---|
78 | use the local working copy placed in DIR as the $(echo $PROGNAME | tr [a-z] [A-Z]) book
|
---|
79 | -EOF-
|
---|
80 |
|
---|
81 | [[ ${PROGNAME} != "blfs" ]] &&
|
---|
82 | cat <<- -EOF-
|
---|
83 |
|
---|
84 | ${BOLD} -C, --comparasion TYPE${OFF}
|
---|
85 | do iterative comparison analysis. This extends the total build time
|
---|
86 | considerably because the entire final system will rebuild itself
|
---|
87 | the number of times specified by ITERATIONS in common/config.
|
---|
88 | Types allowed are:
|
---|
89 | ICA = do ICA as designed by Greg Schafer
|
---|
90 | farce = do the farce analysis designed by Ken Moffat
|
---|
91 | both = perfom both ICA and farce analysis
|
---|
92 |
|
---|
93 | ${BOLD} -F, --fstab FILE${OFF}
|
---|
94 | use FILE as the /etc/fstab file for the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} system. If not specified,
|
---|
95 | a default /etc/fstab file with dummy values is created.
|
---|
96 |
|
---|
97 | ${BOLD} -K, --kernel-config FILE${OFF}
|
---|
98 | use the kernel configuration file specified in FILE to build the kernel.
|
---|
99 | if the file is not found, or if not specified, the kernel build is skipped.
|
---|
100 |
|
---|
101 | ${BOLD} -M, --run-make${OFF}
|
---|
102 | run make on the generated Makefile
|
---|
103 |
|
---|
104 | ${BOLD} -R --rebuild${OFF}
|
---|
105 | clean the build directory before perfoming any other task. The directory
|
---|
106 | is cleaned only if it was populated by a previous jhalfs run.
|
---|
107 | -EOF-
|
---|
108 |
|
---|
109 | [[ ${PROGNAME} = "clfs" ]] &&
|
---|
110 | cat <<- -EOF-
|
---|
111 |
|
---|
112 | ${BOLD} -A, --arch ARCH ${OFF}
|
---|
113 | Select the TARGET architecture, valid selections are:
|
---|
114 | 32bit builds
|
---|
115 | x86, i486, i586, ppc, mips, mipsel, sparc
|
---|
116 | 64bit builds
|
---|
117 | x86_64-64, mips64-64, mipsel64-64, sparc64-64, alpha
|
---|
118 | 64bit multi-lib
|
---|
119 | x86_64, mips64, mipsel64, sparc64, ppc64
|
---|
120 |
|
---|
121 | ${BOLD} --boot-config FILE ${OFF}
|
---|
122 | The configuration file for the bootstrap kernel if method=boot
|
---|
123 |
|
---|
124 | ${BOLD} --method BUILDMETHOD ${OFF}
|
---|
125 | Select the build method, chroot or boot
|
---|
126 | -EOF-
|
---|
127 |
|
---|
128 | [[ ${PROGNAME} = "hlfs" ]] &&
|
---|
129 | cat <<- -EOF-
|
---|
130 |
|
---|
131 | ${BOLD} --model STYLE ${OFF}
|
---|
132 | Select the library model for the HLFS system
|
---|
133 | Valid choices are: glibc or uclibc
|
---|
134 | -EOF-
|
---|
135 |
|
---|
136 | [[ ${PROGNAME} = "blfs" ]] &&
|
---|
137 | cat <<- -EOF-
|
---|
138 |
|
---|
139 | ${BOLD} --dependencies 0/1/2${OFF}
|
---|
140 | add dependencies of type TYPE to the build tree.
|
---|
141 | If not set, both required and recommended are used.
|
---|
142 |
|
---|
143 | Possible values are:
|
---|
144 | 0 - required only required dependecies are used
|
---|
145 | 1 - recommended both required a recommended dependencies are used
|
---|
146 | 2 - optional all dependencies are used
|
---|
147 | -EOF-
|
---|
148 |
|
---|
149 | cat <<- -EOF-
|
---|
150 | ${DD_BORDER}
|
---|
151 | -EOF-
|
---|
152 | exit
|
---|
153 | }
|
---|
154 |
|
---|
155 | version="
|
---|
156 | ${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
|
---|
157 | \$Date$
|
---|
158 |
|
---|
159 | ${BOLD} \"${PROGNAME}\"${OFF} script module
|
---|
160 |
|
---|
161 | Written by George Boudreau,
|
---|
162 | Manuel Canales Esparcia,
|
---|
163 | Jeremy Huntwork
|
---|
164 |
|
---|
165 | This program is published under the ${BOLD}Gnu General Public License, Version 2.${OFF}
|
---|
166 | "
|
---|
167 |
|
---|
168 |
|
---|
169 | no_empty_builddir() {
|
---|
170 | 'clear'
|
---|
171 | cat <<- -EOF-
|
---|
172 | ${DD_BORDER}
|
---|
173 |
|
---|
174 | ${tab_}${tab_}${BOLD}${RED}W A R N I N G${OFF}
|
---|
175 | Looks like the \$BUILDDIR directory contains subdirectories
|
---|
176 | from a previous HLFS build.
|
---|
177 |
|
---|
178 | Please format the partition mounted on \$BUILDDIR or set
|
---|
179 | a different build directory before running jhalfs.
|
---|
180 | ${OFF}
|
---|
181 | ${DD_BORDER}
|
---|
182 | -EOF-
|
---|
183 | exit
|
---|
184 | }
|
---|
185 |
|
---|
186 |
|
---|
187 | help="${nl_}Try '$0 --help' for more information."
|
---|
188 |
|
---|
189 |
|
---|
190 | exit_missing_arg="\
|
---|
191 | echo \"Option '\$1' requires an argument\" >&2
|
---|
192 | echo \"\$help\" >&2
|
---|
193 | exit 1"
|
---|
194 |
|
---|
195 | no_dl_client="\
|
---|
196 | echo \"Could not find a way to download the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} sources.\" >&2
|
---|
197 | echo \"Attempting to continue.\" >&2"
|
---|
198 |
|
---|
199 | HEADER="# This file is automatically generated by jhalfs
|
---|
200 | # DO NOT EDIT THIS FILE MANUALLY
|
---|
201 | #
|
---|
202 | # Generated on `date \"+%F %X %Z\"`"
|
---|
203 |
|
---|
204 |
|
---|
205 |
|
---|
206 | #----------------------------------#
|
---|
207 | wrt_target() { # Create target and initialize log file
|
---|
208 | #----------------------------------#
|
---|
209 | local i=$1
|
---|
210 | local PREV=$2
|
---|
211 | case $i in
|
---|
212 | iteration* ) local LOGFILE=$this_script.log ;;
|
---|
213 | * ) local LOGFILE=$this_script ;;
|
---|
214 | esac
|
---|
215 | (
|
---|
216 | cat << EOF
|
---|
217 |
|
---|
218 | $i: $PREV
|
---|
219 | @\$(call echo_message, Building)
|
---|
220 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >logs/$LOGFILE
|
---|
221 | EOF
|
---|
222 | ) >> $MKFILE.tmp
|
---|
223 | }
|
---|
224 |
|
---|
225 |
|
---|
226 | #----------------------------------#
|
---|
227 | wrt_unpack() { # Unpack and set 'ROOT' var
|
---|
228 | #----------------------------------#
|
---|
229 | local FILE=$1
|
---|
230 | (
|
---|
231 | cat << EOF
|
---|
232 | @\$(call unpack,$FILE)
|
---|
233 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
234 | echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
|
---|
235 | chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT
|
---|
236 | EOF
|
---|
237 | ) >> $MKFILE.tmp
|
---|
238 | }
|
---|
239 |
|
---|
240 |
|
---|
241 | #----------------------------------#
|
---|
242 | wrt_unpack2() { #
|
---|
243 | #----------------------------------#
|
---|
244 | local FILE=$1
|
---|
245 | (
|
---|
246 | cat << EOF
|
---|
247 | @\$(call unpack2,$FILE)
|
---|
248 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
249 | echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
|
---|
250 | EOF
|
---|
251 | ) >> $MKFILE.tmp
|
---|
252 | }
|
---|
253 |
|
---|
254 |
|
---|
255 | #----------------------------------#
|
---|
256 | wrt_unpack3() { #
|
---|
257 | #----------------------------------#
|
---|
258 | local FILE=$1
|
---|
259 | (
|
---|
260 | cat << EOF
|
---|
261 | @\$(call unpack3,$FILE)
|
---|
262 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
263 | echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
|
---|
264 | EOF
|
---|
265 | ) >> $MKFILE.tmp
|
---|
266 | }
|
---|
267 |
|
---|
268 |
|
---|
269 |
|
---|
270 | #----------------------------------#
|
---|
271 | wrt_target_vars() { # Target vars for hlfs (cross-build method)
|
---|
272 | #----------------------------------#
|
---|
273 | (
|
---|
274 | cat << EOF
|
---|
275 | @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
|
---|
276 | echo "export ldso=/lib/${LOADER}" >> envars
|
---|
277 | EOF
|
---|
278 | ) >> $MKFILE.tmp
|
---|
279 |
|
---|
280 | }
|
---|
281 |
|
---|
282 |
|
---|
283 | #----------------------------------#
|
---|
284 | wrt_run_as_su() { # Execute script inside time { }, footer to log file
|
---|
285 | #----------------------------------#
|
---|
286 | local this_script=$1
|
---|
287 | local file=$2
|
---|
288 | (
|
---|
289 | cat << EOF
|
---|
290 | @( time { su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
|
---|
291 | echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/$this_script
|
---|
292 | EOF
|
---|
293 | ) >> $MKFILE.tmp
|
---|
294 | }
|
---|
295 |
|
---|
296 |
|
---|
297 | #----------------------------------#
|
---|
298 | wrt_run_as_root() { # Some scripts must be run as root..
|
---|
299 | #----------------------------------#
|
---|
300 | local this_script=$1
|
---|
301 | local file=$2
|
---|
302 | (
|
---|
303 | cat << EOF
|
---|
304 | @( time { export LFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
|
---|
305 | echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/$this_script
|
---|
306 | EOF
|
---|
307 | ) >> $MKFILE.tmp
|
---|
308 | }
|
---|
309 |
|
---|
310 |
|
---|
311 | #----------------------------------#
|
---|
312 | wrt_run_as_root2() { #
|
---|
313 | #----------------------------------#
|
---|
314 | local this_script=$1
|
---|
315 | local file=$2
|
---|
316 | (
|
---|
317 | cat << EOF
|
---|
318 | @( time { source envars && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
|
---|
319 | echo -e "\nKB: \`du -skx --exclude=jhalfs \`\n" >>logs/$this_script
|
---|
320 | EOF
|
---|
321 | ) >> $MKFILE.tmp
|
---|
322 | }
|
---|
323 |
|
---|
324 |
|
---|
325 |
|
---|
326 | #----------------------------------#
|
---|
327 | wrt_run_as_chroot1() { #
|
---|
328 | #----------------------------------#
|
---|
329 | local this_script=$1
|
---|
330 | local file=$2
|
---|
331 | (
|
---|
332 | cat << EOF
|
---|
333 | @( time { \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
|
---|
334 | echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/${this_script}
|
---|
335 | EOF
|
---|
336 | ) >> $MKFILE.tmp
|
---|
337 | }
|
---|
338 |
|
---|
339 |
|
---|
340 | #----------------------------------#
|
---|
341 | wrt_run_as_chroot2() { #
|
---|
342 | #----------------------------------#
|
---|
343 | local this_script=$1
|
---|
344 | local file=$2
|
---|
345 | (
|
---|
346 | cat << EOF
|
---|
347 | @( time { \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
|
---|
348 | echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/${this_script}
|
---|
349 | EOF
|
---|
350 | ) >> $MKFILE.tmp
|
---|
351 | }
|
---|
352 |
|
---|
353 |
|
---|
354 | #----------------------------------#
|
---|
355 | wrt_copy_fstab() { #
|
---|
356 | #----------------------------------#
|
---|
357 | local i=$1
|
---|
358 | (
|
---|
359 | cat << EOF
|
---|
360 | @cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1
|
---|
361 | EOF
|
---|
362 | ) >> $MKFILE.tmp
|
---|
363 | }
|
---|
364 |
|
---|
365 | #----------------------------------#
|
---|
366 | wrt_copy_fstab2() { #
|
---|
367 | #----------------------------------#
|
---|
368 | local i=$1
|
---|
369 | (
|
---|
370 | cat << EOF
|
---|
371 | @cp -v /sources/fstab /etc/fstab >>logs/$i 2>&1
|
---|
372 | EOF
|
---|
373 | ) >> $MKFILE.tmp
|
---|
374 | }
|
---|
375 |
|
---|
376 |
|
---|
377 | #----------------------------------#
|
---|
378 | wrt_remove_build_dirs() { #
|
---|
379 | #----------------------------------#
|
---|
380 | local name=$1
|
---|
381 | (
|
---|
382 | cat << EOF
|
---|
383 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
384 | rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
|
---|
385 | if [ -e \$(MOUNT_PT)\$(SRC)/$name-build ]; then \\
|
---|
386 | rm -r \$(MOUNT_PT)\$(SRC)/$name-build; \\
|
---|
387 | fi;
|
---|
388 | EOF
|
---|
389 | ) >> $MKFILE.tmp
|
---|
390 | }
|
---|
391 |
|
---|
392 |
|
---|
393 | #----------------------------------#
|
---|
394 | wrt_remove_build_dirs2() { #
|
---|
395 | #----------------------------------#
|
---|
396 | local name=$1
|
---|
397 | (
|
---|
398 | cat << EOF
|
---|
399 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
400 | rm -r \$(SRC)/\$\$ROOT && \\
|
---|
401 | if [ -e \$(SRC)/$name-build ]; then \\
|
---|
402 | rm -r \$(SRC)/$name-build; \\
|
---|
403 | fi;
|
---|
404 | EOF
|
---|
405 | ) >> $MKFILE.tmp
|
---|
406 | }
|
---|
407 |
|
---|
408 |
|
---|
409 | #----------------------------------#
|
---|
410 | wrt_report() { #
|
---|
411 | #----------------------------------#
|
---|
412 | (
|
---|
413 | cat << EOF
|
---|
414 |
|
---|
415 | create-sbu_du-report: $PREV
|
---|
416 | @\$(call echo_message, Building)
|
---|
417 | @./create-sbu_du-report.sh logs $VERSION
|
---|
418 | @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
|
---|
419 | @touch \$@
|
---|
420 | EOF
|
---|
421 | ) >> $MKFILE.tmp
|
---|
422 |
|
---|
423 | chapter789="$chapter789 create-sbu_du-report"
|
---|
424 | }
|
---|
425 |
|
---|
426 |
|
---|
427 | #----------------------------#
|
---|
428 | run_make() { #
|
---|
429 | #----------------------------#
|
---|
430 | # Test if make must be run.
|
---|
431 | if [ "$RUNMAKE" = "1" ] ; then
|
---|
432 | # Test to make sure we're running the build as root
|
---|
433 | if [ "$UID" != "0" ] ; then
|
---|
434 | echo "You must be logged in as root to successfully build the system."
|
---|
435 | exit 1
|
---|
436 | fi
|
---|
437 | # Build the system
|
---|
438 | if [ -e $MKFILE ] ; then
|
---|
439 | echo -ne "Building the system...\n"
|
---|
440 | cd $JHALFSDIR && make
|
---|
441 | echo -ne "done\n"
|
---|
442 | fi
|
---|
443 | fi
|
---|
444 | }
|
---|
445 |
|
---|
446 |
|
---|
447 | #----------------------------#
|
---|
448 | clean_builddir() { #
|
---|
449 | #----------------------------#
|
---|
450 | # Test if the clean must be done.
|
---|
451 | if [ "$CLEAN" = "1" ] ; then
|
---|
452 | # Test to make sure we're running the clean as root
|
---|
453 | if [ "$UID" != "0" ] ; then
|
---|
454 | echo "You must be logged in as root to clean the build directory."
|
---|
455 | exit 1
|
---|
456 | fi
|
---|
457 | # Test to make sure that the build directory was populated by jhalfs
|
---|
458 | if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
|
---|
459 | echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
|
---|
460 | exit 1
|
---|
461 | else
|
---|
462 | # Clean the build directory
|
---|
463 | echo -ne "Cleaning $BUILDDIR...\n"
|
---|
464 | rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
|
---|
465 | echo -ne "Cleaning $JHALFSDIR...\n"
|
---|
466 | rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
|
---|
467 | echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
|
---|
468 | rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
|
---|
469 | echo -ne "done\n"
|
---|
470 | fi
|
---|
471 | fi
|
---|
472 | }
|
---|
473 |
|
---|
474 | #----------------------------#
|
---|
475 | get_book() { #
|
---|
476 | #----------------------------#
|
---|
477 | cd $JHALFSDIR
|
---|
478 |
|
---|
479 | if [ -z $WC ] ; then
|
---|
480 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
481 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
482 | exit 1"
|
---|
483 | echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
|
---|
484 |
|
---|
485 | case $PROGNAME in
|
---|
486 | lfs) svn_root="LFS" ;;
|
---|
487 | hlfs) svn_root="HLFS" ;;
|
---|
488 | clfs) svn_root="cross-lfs" ;;
|
---|
489 | blfs) svn_root="BLFS" ;;
|
---|
490 | *) echo "BOOK not defined in function <get_book>"
|
---|
491 | exit 1 ;;
|
---|
492 | esac
|
---|
493 | # Grab a fresh book if it's missing, otherwise, update it from the
|
---|
494 | # repo. If we've already extracted the commands, move on to getting the
|
---|
495 | # sources.
|
---|
496 | if [ -d ${PROGNAME}-$LFSVRS ] ; then
|
---|
497 | cd ${PROGNAME}-$LFSVRS
|
---|
498 | if LC_ALL=C svn up | grep -q At && test -d $JHALFSDIR/${PROGNAME}-commands && \
|
---|
499 | test -f $JHALFSDIR/packages ; then
|
---|
500 | echo -ne "done\n"
|
---|
501 | # Set the canonical book version
|
---|
502 | cd $JHALFSDIR
|
---|
503 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
504 | get_sources
|
---|
505 | else
|
---|
506 | echo -ne "done\n"
|
---|
507 | # Set the canonical book version
|
---|
508 | cd $JHALFSDIR
|
---|
509 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
510 | extract_commands
|
---|
511 | fi
|
---|
512 | else
|
---|
513 | case $LFSVRS in
|
---|
514 | development)
|
---|
515 | svn co $SVN/${svn_root}/trunk/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
|
---|
516 | esac
|
---|
517 | echo -ne "done\n"
|
---|
518 | # Set the canonical book version
|
---|
519 | cd $JHALFSDIR
|
---|
520 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
521 | extract_commands
|
---|
522 | fi
|
---|
523 | else
|
---|
524 | echo -ne "Using $BOOK as book's sources ...\n"
|
---|
525 | # Set the canonical book version
|
---|
526 | cd $JHALFSDIR
|
---|
527 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
528 | extract_commands
|
---|
529 | fi
|
---|
530 | }
|
---|
531 |
|
---|
532 | #----------------------------#
|
---|
533 | extract_commands() { #
|
---|
534 | #----------------------------#
|
---|
535 |
|
---|
536 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
537 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
538 | exit 1"
|
---|
539 |
|
---|
540 | cd $JHALFSDIR
|
---|
541 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
|
---|
542 |
|
---|
543 | # Start clean
|
---|
544 | if [ -d ${PROGNAME}-commands ]; then
|
---|
545 | rm -rf ${PROGNAME}-commands
|
---|
546 | mkdir -v ${PROGNAME}-commands
|
---|
547 | fi
|
---|
548 | echo -n "Extracting commands for"
|
---|
549 |
|
---|
550 | # Dump the commands in shell script form from the HLFS book.
|
---|
551 | case ${PROGNAME} in
|
---|
552 | clfs)
|
---|
553 | echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
|
---|
554 | xsltproc --nonet \
|
---|
555 | --xinclude \
|
---|
556 | --stringparam method $METHOD \
|
---|
557 | --stringparam testsuite $TEST \
|
---|
558 | --stringparam vim-lang $VIMLANG \
|
---|
559 | --stringparam timezone $TIMEZONE \
|
---|
560 | --stringparam page $PAGE \
|
---|
561 | --stringparam lang $LANG \
|
---|
562 | --stringparam keymap $KEYMAP \
|
---|
563 | -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
|
---|
564 | ;;
|
---|
565 | hlfs)
|
---|
566 | echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
|
---|
567 | xsltproc --nonet \
|
---|
568 | --xinclude \
|
---|
569 | --stringparam model $MODEL \
|
---|
570 | --stringparam testsuite $TEST \
|
---|
571 | --stringparam timezone $TIMEZONE \
|
---|
572 | --stringparam page $PAGE \
|
---|
573 | --stringparam lang $LANG \
|
---|
574 | --stringparam lc_all $LC_ALL \
|
---|
575 | --stringparam keymap $KEYMAP \
|
---|
576 | --stringparam grsecurity_host $GRSECURITY_HOST \
|
---|
577 | -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
578 | ;;
|
---|
579 | lfs)
|
---|
580 | echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
|
---|
581 | xsltproc --nonet \
|
---|
582 | --xinclude \
|
---|
583 | --stringparam testsuite $TEST \
|
---|
584 | --stringparam vim-lang $VIMLANG \
|
---|
585 | --stringparam timezone $TIMEZONE \
|
---|
586 | --stringparam page $PAGE \
|
---|
587 | --stringparam lang $LANG \
|
---|
588 | -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
589 | ;;
|
---|
590 | blfs)
|
---|
591 | echo -n " ${L_arrow}${BOLD}BLFS${R_arrow} build"
|
---|
592 | xsltproc --nonet \
|
---|
593 | --xinclude \
|
---|
594 | --stringparam testsuite $TEST \
|
---|
595 | --stringparam server $SERVER \
|
---|
596 | -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
597 | ;;
|
---|
598 | *) exit 1 ;;
|
---|
599 | esac
|
---|
600 |
|
---|
601 | echo " ...OK"
|
---|
602 |
|
---|
603 | # Make the scripts executable.
|
---|
604 | chmod -R +x $JHALFSDIR/${PROGNAME}-commands
|
---|
605 |
|
---|
606 | # Create the packages file. We need it for proper Makefile creation
|
---|
607 | rm -f packages
|
---|
608 | case "${PROGNAME}" in
|
---|
609 | clfs)
|
---|
610 | echo -n "Creating <${PROGNAME}> specific packages file"
|
---|
611 | grep "\-version " $BOOK/packages.ent | sed -e 's@<!ENTITY @@' \
|
---|
612 | -e 's@">@"@' \
|
---|
613 | -e '/generic/d' > packages
|
---|
614 | echo " ...OK"
|
---|
615 | ;;
|
---|
616 |
|
---|
617 | hlfs)
|
---|
618 | echo -n "Creating <${PROGNAME}> specific packages file"
|
---|
619 | grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
|
---|
620 | -e 's@">@"@' \
|
---|
621 | -e '/generic/d' >> packages
|
---|
622 | echo " ...OK"
|
---|
623 | ;;
|
---|
624 |
|
---|
625 | lfs)
|
---|
626 | echo -n "Creating <${PROGNAME}> specific packages file"
|
---|
627 | grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
|
---|
628 | -e 's@">@"@' \
|
---|
629 | -e '/generic/d' >> packages
|
---|
630 | echo " ...OK"
|
---|
631 | ;;
|
---|
632 | esac
|
---|
633 |
|
---|
634 | # Done. Moving on...
|
---|
635 | get_sources
|
---|
636 | }
|
---|
637 |
|
---|
638 | #----------------------------#
|
---|
639 | get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
|
---|
640 | #----------------------------#
|
---|
641 | local saveIFS=$IFS
|
---|
642 | local IFS line URL1 URL2 FILE MD5 HAVEMD5 fromARCHIVE
|
---|
643 |
|
---|
644 | # Test if the packages must be downloaded
|
---|
645 | [ ! "$GETPKG" = "1" ] && return
|
---|
646 |
|
---|
647 | gs_wrt_message(){
|
---|
648 | echo "${RED}$1${OFF}"
|
---|
649 | echo "$1" >> MISSING_FILES.DMP
|
---|
650 | }
|
---|
651 | # Housekeeping
|
---|
652 | [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
|
---|
653 | cd $BUILDDIR/sources
|
---|
654 | [[ -f MD5SUMS ]] && rm MD5SUMS
|
---|
655 | [[ -f MD5SUMS-$VERSION ]] && rm MD5SUMS-$VERSION
|
---|
656 | [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
|
---|
657 | [[ -f urls.lst ]] && rm urls.lst
|
---|
658 |
|
---|
659 | # Download a fresh MD5SUMS file
|
---|
660 | wget $SERVER/pub/lfs/conglomeration/MD5SUMS
|
---|
661 |
|
---|
662 | # Generate URLs file
|
---|
663 | create_urls
|
---|
664 |
|
---|
665 | IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
|
---|
666 | for line in `cat urls.lst`; do
|
---|
667 | IFS=$saveIFS # Restore the system defaults
|
---|
668 |
|
---|
669 | # Skip some packages if they aren't needed
|
---|
670 | case $line in
|
---|
671 | */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
|
---|
672 | [[ "$TEST" = "0" ]] && continue
|
---|
673 | ;;
|
---|
674 | */vim-*-lang* )
|
---|
675 | [[ "$VIMLANG" = "0" ]] && continue
|
---|
676 | ;;
|
---|
677 | esac
|
---|
678 |
|
---|
679 | # Locations
|
---|
680 | URL1=`echo $line | cut -d" " -f2` # Preferred URL
|
---|
681 | URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
|
---|
682 | FILE=`basename $URL2` # File name
|
---|
683 |
|
---|
684 | # Find the md5 sum for this package.
|
---|
685 | set +e
|
---|
686 | HAVEMD5=1 # Always assume we have a MD5SUM
|
---|
687 | MD5=`grep " $FILE" MD5SUMS`
|
---|
688 | if [ $? -ne 0 ]; then
|
---|
689 | set -e
|
---|
690 | gs_wrt_message "$FILE not found in MD5SUMS"
|
---|
691 | # IMPORTANT:: There is no MD5SUM for this file.
|
---|
692 | HAVEMD5=0
|
---|
693 | fi
|
---|
694 |
|
---|
695 | set -e
|
---|
696 | # If the file exists in the archive copy it to the
|
---|
697 | # $BUILDDIR/sources dir. MD5SUM will be validated later.
|
---|
698 | if [ ! -z ${SRC_ARCHIVE} ] &&
|
---|
699 | [ -d ${SRC_ARCHIVE} ] &&
|
---|
700 | [ -f ${SRC_ARCHIVE}/$FILE ]; then
|
---|
701 | cp ${SRC_ARCHIVE}/$FILE .
|
---|
702 | echo "$FILE: -- copied from $SRC_ARCHIVE"
|
---|
703 | fromARCHIVE=1
|
---|
704 | else
|
---|
705 | echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
|
---|
706 | fromARCHIVE=0
|
---|
707 | # If the file does not exist in /sources download a fresh one
|
---|
708 | if [ ! -f $FILE ] ; then
|
---|
709 | if ! wget $URL1 && ! wget $URL2 ; then
|
---|
710 | gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
|
---|
711 | continue
|
---|
712 | fi
|
---|
713 | fi
|
---|
714 | fi
|
---|
715 |
|
---|
716 | # Is there a MD5SUM to validate the file against.
|
---|
717 | if [[ "$HAVEMD5" = "1" ]] ; then
|
---|
718 | # IF the md5sum does not match the existing files
|
---|
719 | if ! echo "$MD5" | md5sum -c - >/dev/null ; then
|
---|
720 | [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
|
---|
721 | [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
|
---|
722 | # Remove the old file and download a new one
|
---|
723 | rm -fv $FILE
|
---|
724 | # Force generation of MD5SUM and storage in SRC_ARCHIVE
|
---|
725 | fromARCHIVE=0; HAVEMD5=0
|
---|
726 | # Try and retrieve the file
|
---|
727 | if ! wget -N $URL1 && ! wget -N $URL2 ; then
|
---|
728 | gs_wrt_message "$FILE not found on the servers.. SKIPPING"
|
---|
729 | continue
|
---|
730 | fi
|
---|
731 | fi
|
---|
732 | fi
|
---|
733 |
|
---|
734 | # Validate the MD5SUM one last time
|
---|
735 | if [[ "$HAVEMD5" = "1" ]] && ! echo "$MD5" | md5sum -c - >/dev/null ; then
|
---|
736 | gs_wrt_message "$FILE does not match MD5SUMS value"
|
---|
737 | fi
|
---|
738 |
|
---|
739 | # Generate a fresh MD5SUM for this file
|
---|
740 | if [[ "$HAVEMD5" = "0" ]] ; then
|
---|
741 | echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
|
---|
742 | echo "NEW MD5SUM $(md5sum $FILE)" >> MISSING_FILES.DMP
|
---|
743 | fi
|
---|
744 |
|
---|
745 | # Good or bad we write the original md5sum to a file
|
---|
746 | echo "$MD5" >> MD5SUMS-$VERSION
|
---|
747 |
|
---|
748 | # Copy the freshly downloaded file
|
---|
749 | # to the source archive.
|
---|
750 | if [ ! -z ${SRC_ARCHIVE} ] &&
|
---|
751 | [ -d ${SRC_ARCHIVE} ] &&
|
---|
752 | [ -w ${SRC_ARCHIVE} ] &&
|
---|
753 | [ "$fromARCHIVE" = "0" ] ; then
|
---|
754 | echo "Storing file:<$FILE> in the package archive"
|
---|
755 | cp -f $FILE ${SRC_ARCHIVE}
|
---|
756 | fi
|
---|
757 |
|
---|
758 | done
|
---|
759 |
|
---|
760 | if [[ -s MISSING_FILES.DMP ]]; then
|
---|
761 | echo -e "\n\n${tab_}${RED} One or more files were not retrieved or have a bad MD5SUMS chechsum.\n${tab_} Check ${L_arrow}$BUILDDIR/sources/MISSING_FILES.DMP${R_arrow} for names ${OFF}\n"
|
---|
762 | # Do not allow the automatic exection of the Makefile.
|
---|
763 | echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
|
---|
764 | RUNMAKE=0
|
---|
765 | fi
|
---|
766 | }
|
---|
767 |
|
---|
768 |
|
---|
769 | #----------------------------#
|
---|
770 | create_urls() { #
|
---|
771 | #----------------------------#
|
---|
772 | cd $JHALFSDIR
|
---|
773 |
|
---|
774 | case ${PROGNAME} in
|
---|
775 | clfs)
|
---|
776 | echo -n "Creating CLFS <${ARCH}> specific URLs file"
|
---|
777 | xsltproc --nonet --xinclude \
|
---|
778 | --stringparam server $SERVER \
|
---|
779 | -o $BUILDDIR/sources/urls.lst urls.xsl \
|
---|
780 | $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
|
---|
781 | echo " ...OK"
|
---|
782 | ;;
|
---|
783 | hlfs)
|
---|
784 | echo -n "Creating HLFS <${MODEL}> specific URLs file"
|
---|
785 | xsltproc --nonet --xinclude \
|
---|
786 | --stringparam server $SERVER \
|
---|
787 | --stringparam model $MODEL \
|
---|
788 | -o $BUILDDIR/sources/urls.lst urls.xsl \
|
---|
789 | $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
|
---|
790 | echo " ...OK"
|
---|
791 | ;;
|
---|
792 | lfs)
|
---|
793 | echo -n "Creating LFS specific URLs file"
|
---|
794 | xsltproc --nonet --xinclude \
|
---|
795 | --stringparam server $SERVER \
|
---|
796 | -o ../sources/urls.lst urls.xsl \
|
---|
797 | $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
|
---|
798 | echo " ...OK"
|
---|
799 | ;;
|
---|
800 | esac
|
---|
801 |
|
---|
802 | cd $BUILDDIR/sources
|
---|
803 | }
|
---|