source: common/common-functions@ fe187bf

experimental
Last change on this file since fe187bf was fe187bf, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Merged r2547 from trunk (removal of sparcv8 arch in CLFS)

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