source: common/common-functions@ 3a321ea

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 3a321ea was 3a321ea, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Changed how build time and disk usage is dumped to the logs.

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