source: common/common-functions@ fb42452

experimental
Last change on this file since fb42452 was 74faad1, checked in by George Boudreau <georgeb@…>, 18 years ago

Corrected typo in chroot2 function, thanks Tor

  • Property mode set to 100644
File size: 27.1 KB
Line 
1#!/bin/bash
2
3# $Id$
4
5set +e
6
7# VT100 colors
8declare -r BLACK=$'\e[1;30m'
9declare -r DK_GRAY=$'\e[0;30m'
10
11declare -r RED=$'\e[31m'
12declare -r GREEN=$'\e[32m'
13declare -r YELLOW=$'\e[33m'
14declare -r BLUE=$'\e[34m'
15declare -r MAGENTA=$'\e[35m'
16declare -r CYAN=$'\e[36m'
17declare -r WHITE=$'\e[37m'
18
19declare -r OFF=$'\e[0m'
20declare -r BOLD=$'\e[1m'
21declare -r REVERSE=$'\e[7m'
22declare -r HIDDEN=$'\e[8m'
23
24declare -r tab_=$'\t'
25declare -r nl_=$'\n'
26
27declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
28declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
29declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
30
31# bold yellow > < pair
32declare -r R_arrow=$'\e[1;33m>\e[0m'
33declare -r L_arrow=$'\e[1;33m<\e[0m'
34
35
36usage() {
37cat <<- -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 edit the relevant
44 configuration files placed under ${BOLD}common/${OFF} and ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])/${OFF}
45
46Options:
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 VER values are:
56 dev*, trunk, SVN = aliases for the Development version of {C,H}LFS
57 branch-NAME = a branch of name NAME
58 VERSION = the version of a stable released book
59 To know what branches and stable books work with this version of jhalfs
60 please see http://wiki.linuxfromscratch.org/alfs/wiki/SupportedBooks
61
62${BOLD} -D --directory DIR${OFF}
63 use DIR directory for building ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF}; all files jhalfs-X produces
64 will be in the directory DIR/${SCRIPT_ROOT}.
65 The current setting for BUILDDIR is "$BUILDDIR"
66
67${BOLD} -G, --get-packages${OFF}
68 download the packages and patches. This assumes that the server declared
69 in the configuration file has the proper packages and patches for the
70 book version being processed.
71
72${BOLD} -O, --optimize${OFF}
73 Optimize [0-2]
74 0 = no optimization
75 1 = optimize final system only
76 2 = optimize both temporary tools and final system
77 Edit common/opt_config{,.d/*} and common/opt_override as desired.
78
79${BOLD} -T, --testsuites N ${OFF}
80 Run test suites [0-3]
81 0 = none
82 1 = only final system Glibc, GCC and Binutils testsuites
83 2 = all final system testsuites
84 3 = all temporary tools and final system testsuites
85 In CLFS and HLFS, 3 is an alias to 2
86
87${BOLD} -W, --working-copy DIR${OFF}
88 use the local working copy placed in DIR as the $(echo $PROGNAME | tr [a-z] [A-Z]) book
89
90${BOLD} -C, --comparison TYPE${OFF}
91 do iterative comparison analysis. This extends the total build time
92 considerably because the entire final system will rebuild itself
93 the number of times specified by ITERATIONS in common/config.
94 Types allowed are:
95 ICA = do ICA as designed by Greg Schafer
96 farce = do the farce analysis designed by Ken Moffat
97 both = perform both ICA and farce analysis
98
99${BOLD} -F, --fstab FILE${OFF}
100 use FILE as the /etc/fstab file for the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} system. If not specified,
101 a default /etc/fstab file with dummy values is created.
102
103${BOLD} -K, --kernel-config FILE${OFF}
104 use the kernel configuration file specified in FILE to build the kernel.
105 if the file is not found, or if not specified, the kernel build is skipped.
106
107${BOLD} -M, --run-make${OFF}
108 run make on the generated Makefile
109
110${BOLD} -R --rebuild${OFF}
111 clean the build directory before performing any other task. The directory
112 is cleaned only if it was populated by a previous jhalfs-X run.
113-EOF-
114
115[[ ${PROGNAME} = "clfs" ]] &&
116cat <<- -EOF-
117
118${BOLD} -A, --arch ARCH ${OFF}
119 Select the TARGET architecture, valid selections are:
120 32bit builds
121 x86, i486, i586, ppc, mips, mipsel, sparc
122 64bit builds
123 x86_64-64, mips64-64, mipsel64-64, sparc64-64, alpha
124 64bit multi-lib
125 x86_64, mips64, mipsel64, sparc64, ppc64
126
127${BOLD} --boot-config FILE ${OFF}
128 The configuration file for the bootstrap kernel if method=boot
129
130${BOLD} --method BUILDMETHOD ${OFF}
131 Select the build method, chroot or boot
132-EOF-
133
134[[ ${PROGNAME} = "clfs2" ]] &&
135cat <<- -EOF-
136
137${BOLD} -A, --arch ARCH ${OFF}
138 Select the TARGET architecture, valid selections are:
139 32bit builds
140 arm
141 64bit builds
142
143 64bit multi-lib
144-EOF-
145
146[[ ${PROGNAME} = "hlfs" ]] &&
147cat <<- -EOF-
148
149${BOLD} --model STYLE ${OFF}
150 Select the library model for the HLFS system
151 Valid choices are: glibc or uclibc
152-EOF-
153
154cat <<- -EOF-
155${DD_BORDER}
156-EOF-
157 exit
158}
159
160version="
161${BOLD} \"jhalfs-X\"${OFF} builder tool (experimental) \$Rev$
162\$Date$
163
164${BOLD} \"${PROGNAME}\"${OFF} script module
165
166Written by George Boudreau,
167 Manuel Canales Esparcia,
168 Jeremy Huntwork
169
170This program is published under the ${BOLD}Gnu General Public License, Version 2.${OFF}
171"
172
173
174no_empty_builddir() {
175 'clear'
176cat <<- -EOF-
177${DD_BORDER}
178
179${tab_}${tab_}${BOLD}${RED}W A R N I N G${OFF}
180 Looks like the \$BUILDDIR directory contains subdirectories
181 from a previous HLFS build.
182
183 Please format the partition mounted on \$BUILDDIR or set
184 a different build directory before running jhalfs-X.
185${OFF}
186${DD_BORDER}
187-EOF-
188 exit
189}
190
191
192help="${nl_}Try '$0 --help' for more information."
193
194exit_missing_arg="\
195echo \"Option '\$1' requires an argument\" >&2
196echo \"\$help\" >&2
197exit 1"
198
199HEADER="# This file is automatically generated by jhalfs-X
200# DO NOT EDIT THIS FILE MANUALLY
201#
202# Generated on `date \"+%F %X %Z\"`"
203
204
205
206#----------------------------------#
207wrt_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(
216cat << EOF
217
218$i: $PREV
219 @\$(call echo_message, Building)
220 @./progress_bar.sh \$@ &
221 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >logs/$LOGFILE
222EOF
223) >> $MKFILE.tmp
224}
225
226
227#----------------------------------#
228wrt_target_boot() { # Create target and initialize log file
229#----------------------------------#
230 local i=$1
231 local PREV=$2
232 case $i in
233 iteration* ) local LOGFILE=$this_script.log ;;
234 * ) local LOGFILE=$this_script ;;
235 esac
236(
237cat << EOF
238
239$i: $PREV
240 @\$(call echo_message, Building)
241 @./progress_bar.sh \$@ &
242 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT}\`\n" >logs/$LOGFILE
243EOF
244) >> $MKFILE.tmp
245}
246
247#----------------------------#
248get_package_tarball_name() { #
249#----------------------------#
250 local script_name=$1
251
252 # The use of 'head' is necessary to limit the return value to the FIRST match..
253 # hopefully this will not cause problems.
254 #
255 case $script_name in
256 tcl) echo $(grep "^tcl" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
257 linux-headers) echo $(grep "^linux-headers.*.bz2" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
258 *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
259 esac
260
261}
262
263
264#----------------------------------#
265wrt_test_log() { # Initialize testsuite log file
266#----------------------------------#
267 local TESTLOGFILE=$1
268(
269cat << EOF
270 @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
271 su - \$(LUSER) -c "echo -e '\n\`date\`\n' >$TESTLOGDIR/$TESTLOGFILE"
272EOF
273) >> $MKFILE.tmp
274}
275
276#----------------------------------#
277wrt_test_log2() { #
278#----------------------------------#
279 local TESTLOGFILE=$1
280(
281cat << EOF
282 @echo "export TEST_LOG=/$SCRIPT_ROOT/test-logs/$TESTLOGFILE" >> envars && \\
283 echo -e "\n\`date\`\n" >test-logs/$TESTLOGFILE
284EOF
285) >> $MKFILE.tmp
286}
287
288#----------------------------------#
289wrt_target_vars() { # Target vars for hlfs (cross-build method)
290#----------------------------------#
291(
292cat << EOF
293 @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
294 echo "export ldso=/lib/${LOADER}" >> envars
295EOF
296) >> $MKFILE.tmp
297
298}
299
300
301#----------------------------------#
302wrt_copy_fstab() { #
303#----------------------------------#
304 local i=$1
305(
306 cat << EOF
307 @cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1
308EOF
309) >> $MKFILE.tmp
310}
311
312
313#----------------------------------#
314wrt_copy_fstab2() { #
315#----------------------------------#
316 local i=$1
317(
318 cat << EOF
319 @cp -v /sources/fstab /etc/fstab >>logs/$i 2>&1
320EOF
321) >> $MKFILE.tmp
322}
323
324
325#----------------------------------#
326wrt_report() { #
327#----------------------------------#
328(
329cat << EOF
330
331create-sbu_du-report: $PREV
332 @\$(call echo_message, Building)
333 @./create-sbu_du-report.sh logs $VERSION
334 @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
335 @touch \$@
336EOF
337) >> $MKFILE.tmp
338
339chapter789="$chapter789 create-sbu_du-report"
340}
341
342unset wrt_unpack
343#----------------------------------#
344wrt_unpack() { # Unpack and set 'ROOT' var
345#----------------------------------#
346 local FILE=$1
347 local optSAVE_PREVIOUS=$2
348
349 if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
350(
351cat << EOF
352 @\$(call remove_existing_dirs,$FILE)
353EOF
354) >> $MKFILE.tmp
355 fi
356
357(
358cat << EOF
359 @\$(call unpack,$FILE)
360 @\$(call get_pkg_root)
361EOF
362) >> $MKFILE.tmp
363
364}
365
366unset wrt_unpack2
367#----------------------------------#
368wrt_unpack2() { #
369#----------------------------------#
370 local FILE=$1
371 local optSAVE_PREVIOUS=$2
372
373 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
374(
375cat << EOF
376 @\$(call remove_existing_dirs,$FILE)
377EOF
378) >> $MKFILE.tmp
379 fi
380(
381cat << EOF
382 @\$(call unpack2,$FILE)
383 @\$(call get_pkg_root,nouser)
384EOF
385) >> $MKFILE.tmp
386}
387
388#----------------------------------#
389wrt_unpack3() { #
390#----------------------------------#
391 local FILE=$1
392 local optSAVE_PREVIOUS=$2
393
394 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
395(
396cat << EOF
397 @\$(call remove_existing_dirs2,$FILE)
398EOF
399) >> $MKFILE.tmp
400 fi
401(
402cat << EOF
403 @\$(call unpack3,$FILE)
404 @\$(call get_pkg_root2)
405EOF
406) >> $MKFILE.tmp
407}
408
409
410unset wrt_remove_build_dirs
411#----------------------------------#
412wrt_remove_build_dirs() { #
413#----------------------------------#
414 local name=$1
415(
416cat << EOF
417 @\$(call remove_build_dirs,$name)
418EOF
419) >> $MKFILE.tmp
420}
421
422#----------------------------------#
423wrt_remove_build_dirs2() { #
424#----------------------------------#
425 local name=$1
426(
427cat << EOF
428 @\$(call remove_build_dirs2,$name)
429EOF
430) >> $MKFILE.tmp
431}
432
433
434
435unset wrt_touch
436#----------------------------------#
437wrt_touch() { #
438#----------------------------------#
439(
440cat << EOF
441 @\$(call housekeeping)
442EOF
443) >> $MKFILE.tmp
444}
445
446unset wrt_RunAsUser
447#----------------------------------#
448wrt_RunAsUser() { # Execute script inside time { }, footer to log file
449#----------------------------------#
450 local this_script=$1
451 local file=$2
452
453(
454cat << EOF
455 @( time { \$(SU_LUSER) "source \$(LUSER_HOME)/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@" >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\
456 \$(PRT_DU) >> logs/\$@
457EOF
458) >> $MKFILE.tmp
459}
460
461
462#----------------------------------#
463wrt_RunAsRoot() { # Some scripts must be run as root..
464#----------------------------------#
465 local ENV_MOUNT
466 local this_script=$1
467 local file=$2
468
469 case ${PROGNAME} in
470 lfs ) MOUNT_ENV="LFS" ;;
471 blfs ) MOUNT_ENV="BLFS" ;;
472 clfs ) MOUNT_ENV="CLFS" ;;
473 clfs2 ) MOUNT_ENV="CLFS" ;;
474 hlfs ) MOUNT_ENV="HLFS" ;;
475 *) echo "undefined progname $PROGNAME"; exit 1
476 esac
477
478(
479cat << EOF
480 @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
481 \$(PRT_DU_CR) >>logs/\$@
482EOF
483) >> $MKFILE.tmp
484}
485
486#----------------------------------#
487wrt_run_as_root2() { #
488#----------------------------------#
489 local this_script=$1
490 local file=$2
491(
492cat << EOF
493 @( time { source envars && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
494 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \`\n" >>logs/\$@
495EOF
496) >> $MKFILE.tmp
497}
498
499
500unset wrt_run_as_chroot1
501#----------------------------------#
502wrt_run_as_chroot1() { #
503#----------------------------------#
504 local this_script=$1
505 local file=$2
506(
507cat << EOF
508 @( time { \$(CHROOT1) 'cd \$(SCRIPT_ROOT) && source envars && \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@ 2>&1' ; } ) 2>>logs/\$@ && \\
509 \$(PRT_DU_CR) >> logs/\$@
510EOF
511) >> $MKFILE.tmp
512}
513
514unset wrt_run_as_chroot2
515#----------------------------------#
516wrt_run_as_chroot2() { #
517#----------------------------------#
518 local this_script=$1
519 local file=$2
520(
521cat << EOF
522 @( time { \$(CHROOT2) 'cd \$(SCRIPT_ROOT) && source envars && \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@ 2>&1' ; } ) 2>>logs/\$@ && \\
523 \$(PRT_DU_CR) >> logs/\$@
524EOF
525) >> $MKFILE.tmp
526}
527
528unset wrt_target
529#----------------------------------#
530wrt_target() { # Create target and initialize log file
531#----------------------------------#
532 local i=$1
533 local PREV=$2
534 case $i in
535 iteration* ) local LOGFILE="\$@.log" ;;
536 * ) local LOGFILE="\$@" ;;
537 esac
538(
539cat << EOF
540
541$i: $PREV
542 @\$(call echo_message, Building)
543 @./progress_bar.sh \$@ &
544 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >logs/$LOGFILE
545EOF
546) >> $MKFILE.tmp
547}
548
549#----------------------------------#
550wrt_target_boot() { # Create target and initialize log file
551#----------------------------------#
552 local i=$1
553 local PREV=$2
554 case $i in
555 iteration* ) local LOGFILE="\$@.log" ;;
556 * ) local LOGFILE="\$@" ;;
557 esac
558(
559cat << EOF
560
561$i: $PREV
562 @\$(call echo_message, Building)
563 @./progress_bar.sh \$@ &
564 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT}\`\n" >logs/$LOGFILE
565EOF
566) >> $MKFILE.tmp
567}
568
569
570
571#----------------------------#
572run_make() { #
573#----------------------------#
574 # Test if make must be run.
575 if [ "$RUNMAKE" = "y" ] ; then
576 # Test to make sure we're running the build as root
577 if [ "$UID" != "0" ] ; then
578 echo "You must be logged in as root to successfully build the system."
579 exit 1
580 fi
581 # Build the system
582 if [ -e $MKFILE ] ; then
583 echo -ne "Building the system...\n"
584 cd $JHALFSDIR && make
585 echo -ne "done\n"
586 fi
587 fi
588}
589
590
591#----------------------------#
592clean_builddir() { #
593#----------------------------#
594 # Test if the clean must be done.
595 if [ "${CLEAN}" = "y" ]; then
596 # Test to make sure we're running the clean as root
597 if [ "$UID" != "0" ] ; then
598 echo "You must be logged in as root to clean the build directory."
599 exit 1
600 fi
601 # Test to make sure that the build directory was populated by jhalfs
602 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
603 echo "Looks like $BUILDDIR was not populated by a previous jhalfs-X run."
604 exit 1
605 else
606 # Clean the build directory
607 echo -ne "Cleaning $BUILDDIR...\n"
608 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
609 echo -ne "Cleaning $JHALFSDIR...\n"
610 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,*logs,Makefile,*.xsl,makefile-functions,pkg_tarball_list,*.config,*.sh}
611 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
612 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
613 echo -ne "done\n"
614 fi
615 fi
616}
617
618#----------------------------#
619get_book() { #
620#----------------------------#
621 cd $JHALFSDIR
622
623 if [ -z $WC ] ; then
624 # Check for Subversion instead of just letting the script hit 'svn' and fail.
625 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
626 exit 1"
627 echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
628
629 case $PROGNAME in
630 lfs) svn_root="LFS" ;;
631 hlfs) svn_root="HLFS" ;;
632 clfs) svn_root="cross-lfs" ;;
633 clfs2) svn_root="cross-lfs" ;;
634 *) echo "BOOK not defined in function <get_book>"
635 exit 1 ;;
636 esac
637 # Grab a fresh book if it's missing, otherwise, update it from the
638 # repo. If we've already extracted the commands, move on to getting the
639 # sources.
640 if [ -d ${PROGNAME}-$LFSVRS ] ; then
641 cd ${PROGNAME}-$LFSVRS
642 if LC_ALL=C svn up | grep -q At && \
643 test -d $JHALFSDIR/${PROGNAME}-commands && \
644 test -f $JHALFSDIR/pkg_tarball_list ; then
645 # Set the canonical book version
646 echo -ne "done\n"
647 cd $JHALFSDIR
648 case $PROGNAME in
649 clfs | clfs2)
650 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
651 *)
652 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
653 esac
654 get_sources
655 else
656 echo -ne "done\n"
657 extract_commands
658 fi
659 else
660 svn co $SVN/${svn_root}/${TREE} ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1
661 echo -ne "done\n"
662 extract_commands
663 fi
664
665 else
666 echo -ne "Using $BOOK as book's sources ...\n"
667 extract_commands
668 fi
669 echo -ne " Document version ${L_arrow}${BOLD}${VERSION}${R_arrow}\n"
670}
671
672#----------------------------#
673extract_commands() { #
674#----------------------------#
675
676 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
677 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
678 exit 1"
679
680 cd $JHALFSDIR
681 case $PROGNAME in
682 clfs | clfs2 )
683 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
684 *)
685 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
686 esac
687
688 # Start clean
689 if [ -d ${PROGNAME}-commands ]; then
690 rm -rf ${PROGNAME}-commands
691 mkdir -v ${PROGNAME}-commands
692 fi
693 echo -n "Extracting commands for"
694
695 # Dump the commands in shell script form from the HLFS book.
696 case ${PROGNAME} in
697 clfs)
698 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
699 xsltproc --nonet \
700 --xinclude \
701 --stringparam method $METHOD \
702 --stringparam testsuite $TEST \
703 --stringparam bomb-testsuite $BOMB_TEST \
704 --stringparam vim-lang $VIMLANG \
705 --stringparam timezone $TIMEZONE \
706 --stringparam page $PAGE \
707 --stringparam lang $LANG \
708 --stringparam keymap $KEYMAP \
709 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
710 ;;
711
712 clfs2)
713 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
714 xsltproc --nonet \
715 --xinclude \
716 --stringparam vim-lang $VIMLANG \
717 --stringparam timezone $TIMEZONE \
718 --stringparam page $PAGE \
719 --stringparam lang $LANG \
720 --stringparam keymap $KEYMAP \
721 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
722 ;;
723 hlfs)
724 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
725 xsltproc --nonet \
726 --xinclude \
727 --stringparam model $MODEL \
728 --stringparam testsuite $TEST \
729 --stringparam bomb-testsuite $BOMB_TEST \
730 --stringparam timezone $TIMEZONE \
731 --stringparam page $PAGE \
732 --stringparam lang $LANG \
733 --stringparam lc_all $LC_ALL \
734 --stringparam keymap $KEYMAP \
735 --stringparam grsecurity_host $GRSECURITY_HOST \
736 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
737 ;;
738 lfs)
739 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
740 xsltproc --nonet \
741 --xinclude \
742 --stringparam testsuite $TEST \
743 --stringparam bomb-testsuite $BOMB_TEST \
744 --stringparam vim-lang $VIMLANG \
745 --stringparam timezone $TIMEZONE \
746 --stringparam page $PAGE \
747 --stringparam lang $LANG \
748 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
749 ;;
750 *) exit 1 ;;
751 esac
752
753 echo " ...OK"
754
755 # Make the scripts executable.
756 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
757
758 # Create the packages file. We need it for proper Makefile creation
759 create_package_list
760
761 # Done. Moving on...
762 get_sources
763}
764
765#----------------------------#
766create_package_list() { #
767#----------------------------#
768
769 # Create the packages file. We need it for proper Makefile creation
770 rm -f pkg_tarball_list
771 echo -n "Creating <${PROGNAME}> list of tarball names for $BOOK $ARCH"
772 case ${PROGNAME} in
773 clfs | clfs2)
774 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
775 $BOOK/materials/${ARCH}-chapter.xml >>$LOGDIR/$LOG 2>&1
776 ;;
777 hlfs)
778 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
779 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
780 ;;
781 lfs)
782 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
783 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
784 ;;
785 esac
786 echo " ...OK"
787
788}
789
790
791#----------------------------#
792get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
793#----------------------------#
794 local saveIFS=$IFS
795 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE
796
797 # Test if the packages must be downloaded
798 [ ! "$GETPKG" = "y" ] && return
799
800 gs_wrt_message(){
801 echo "${RED}$1${OFF}"
802 echo "$1" >> MISSING_FILES.DMP
803 }
804 # Housekeeping
805 [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
806 cd $BUILDDIR/sources
807 [[ -f MD5SUMS ]] && rm MD5SUMS
808 [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
809 [[ -f urls.lst ]] && rm urls.lst
810
811 # Generate URLs file
812 create_urls
813
814 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
815 for line in `cat urls.lst`; do
816 IFS=$saveIFS # Restore the system defaults
817
818 # Skip some packages if they aren't needed
819 case $line in
820 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
821 [[ "$TEST" = "0" ]] && continue
822 ;;
823 */vim-*-lang* )
824 [[ "$VIMLANG" = "0" ]] && continue
825 ;;
826 *linux/linux-* )
827 [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
828 [[ "$GETKERNEL" = "n" ]] && continue
829 ;;
830 esac
831
832 # Locations
833 URL1=`echo $line | cut -d" " -f2` # Preferred URL
834 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
835 FILE=`basename $URL1` # File name
836 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
837
838 # Validation pair
839 MD5="$BOOKMD5 $FILE"
840 HAVEMD5=1
841
842 set -e
843 # If the file exists in the archive copy it to the
844 # $BUILDDIR/sources dir. MD5SUM will be validated later.
845 if [ ! -z ${SRC_ARCHIVE} ] &&
846 [ -d ${SRC_ARCHIVE} ] &&
847 [ -f ${SRC_ARCHIVE}/$FILE ]; then
848 cp ${SRC_ARCHIVE}/$FILE .
849 echo "$FILE: -- copied from $SRC_ARCHIVE"
850 fromARCHIVE=1
851 else
852 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
853 fromARCHIVE=0
854 # If the file does not exist yet in /sources download a fresh one
855 if [ ! -f $FILE ] ; then
856 if ! wget $URL1 && ! wget $URL2 ; then
857 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
858 continue
859 fi
860 fi
861 fi
862
863 # IF the md5sum does not match the existing files
864 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
865 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
866 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
867 # Remove the old file and download a new one
868 rm -fv $FILE
869 # Force storage in SRC_ARCHIVE
870 fromARCHIVE=0;
871 # Try to retrieve again the file. Servers in reverse order.
872 if ! wget $URL2 && ! wget $URL1 ; then
873 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
874 continue
875 fi
876 fi
877
878 # Validate the MD5SUM one last time
879 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
880 gs_wrt_message "$FILE does not match MD5SUMS value"
881 # Force generation of MD5SUM
882 HAVEMD5=0
883 fi
884
885 # Generate a fresh MD5SUM for this file
886 if [[ "$HAVEMD5" = "0" ]] ; then
887 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
888 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
889 fi
890
891 # Good or bad we write the original md5sum to a file
892 echo "$MD5" >> MD5SUMS
893
894 # Copy the freshly downloaded file
895 # to the source archive.
896 if [ ! -z ${SRC_ARCHIVE} ] &&
897 [ -d ${SRC_ARCHIVE} ] &&
898 [ -w ${SRC_ARCHIVE} ] &&
899 [ "$fromARCHIVE" = "0" ] ; then
900 echo "Storing file:<$FILE> in the package archive"
901 cp -f $FILE ${SRC_ARCHIVE}
902 fi
903
904 done
905
906 if [[ -s MISSING_FILES.DMP ]]; then
907 echo -e "\n\n${tab_}${RED} One or more files were not retrieved or have bad MD5SUMS.\n${tab_} Check ${L_arrow}$BUILDDIR/sources/MISSING_FILES.DMP${R_arrow} for names ${OFF}\n"
908 # Do not allow the automatic execution of the Makefile.
909 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
910 RUNMAKE="n"
911 fi
912}
913
914#----------------------------#
915create_urls() { #
916#----------------------------#
917 cd $JHALFSDIR
918
919 case ${PROGNAME} in
920 clfs)
921 echo -n "Creating CLFS <${ARCH}> specific URLs file"
922 xsltproc --nonet --xinclude \
923 --stringparam server $SERVER \
924 -o $BUILDDIR/sources/urls.lst urls.xsl \
925 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
926 echo " ...OK"
927 ;;
928 clfs2)
929 echo -n "Creating CLFS2 <${ARCH}> specific URLs file"
930 xsltproc --nonet --xinclude \
931 --stringparam server $SERVER \
932 -o $BUILDDIR/sources/urls.lst urls.xsl \
933 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
934 echo " ...OK"
935 ;;
936 hlfs)
937 echo -n "Creating HLFS <${MODEL}> specific URLs file"
938 xsltproc --nonet --xinclude \
939 --stringparam server $SERVER \
940 --stringparam model $MODEL \
941 -o $BUILDDIR/sources/urls.lst urls.xsl \
942 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
943 echo " ...OK"
944 ;;
945 lfs)
946 echo -n "Creating LFS specific URLs file"
947 xsltproc --nonet --xinclude \
948 --stringparam server $SERVER \
949 -o ../sources/urls.lst urls.xsl \
950 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
951 echo " ...OK"
952 ;;
953 esac
954
955 cd $BUILDDIR/sources
956}
Note: See TracBrowser for help on using the repository browser.