source: common/common-functions@ a9429d5

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

Added jhalfs configuration settings to the sbu_du report header.

  • Property mode set to 100644
File size: 25.5 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#----------------------------------#
394wrt_report() { #
395#----------------------------------#
396(
397cat << EOF
398
399create-sbu_du-report: $PREV
400 @\$(call echo_message, Building)
401 @./create-sbu_du-report.sh logs $VERSION
402 @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
403 @touch \$@
404EOF
405) >> $MKFILE.tmp
406
407chapter789="$chapter789 create-sbu_du-report"
408}
409
410
411#----------------------------#
412run_make() {
413#----------------------------#
414 # Test if make must be run.
415 if [ "$RUNMAKE" = "1" ] ; then
416 # Test to make sure we're running the build as root
417 if [ "$UID" != "0" ] ; then
418 echo "You must be logged in as root to successfully build the system."
419 exit 1
420 fi
421 # Build the system
422 if [ -e $MKFILE ] ; then
423 echo -ne "Building the system...\n"
424 cd $JHALFSDIR && make
425 echo -ne "done\n"
426 fi
427 fi
428}
429
430
431#----------------------------#
432clean_builddir() {
433#----------------------------#
434 # Test if the clean must be done.
435 if [ "$CLEAN" = "1" ] ; then
436 # Test to make sure we're running the clean as root
437 if [ "$UID" != "0" ] ; then
438 echo "You must be logged in as root to clean the build directory."
439 exit 1
440 fi
441 # Test to make sure that the build directory was populated by jhalfs
442 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
443 echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
444 exit 1
445 else
446 # Clean the build directory
447 echo -ne "Cleaning $BUILDDIR...\n"
448 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
449 echo -ne "Cleaning $JHALFSDIR...\n"
450 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
451 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
452 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
453 echo -ne "done\n"
454 fi
455 fi
456}
457
458#----------------------------#
459get_book() {
460#----------------------------#
461 cd $JHALFSDIR
462
463 if [ -z $WC ] ; then
464 # Check for Subversion instead of just letting the script hit 'svn' and fail.
465 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
466 exit 1"
467 echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
468
469 case $PROGNAME in
470 lfs) svn_root="LFS" ;;
471 hlfs) svn_root="HLFS" ;;
472 clfs) svn_root="cross-lfs" ;;
473 blfs) svn_root="BLFS" ;;
474 *) echo "BOOK not defined in function <get_book>"
475 exit 1 ;;
476 esac
477 # Grab a fresh book if it's missing, otherwise, update it from the
478 # repo. If we've already extracted the commands, move on to getting the
479 # sources.
480 if [ -d ${PROGNAME}-$LFSVRS ] ; then
481 cd ${PROGNAME}-$LFSVRS
482 if LC_ALL=C svn up | grep -q At && test -d $JHALFSDIR/commands && \
483 test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
484 echo -ne "done\n"
485 # Set the canonical book version
486 cd $JHALFSDIR
487 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
488 get_sources
489 else
490 echo -ne "done\n"
491 # Set the canonical book version
492 cd $JHALFSDIR
493 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
494 extract_commands
495 fi
496 else
497 case $LFSVRS in
498 development)
499 svn co $SVN/${svn_root}/trunk/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
500 alphabetical)
501 svn co $SVN/${svn_root}/branches/$LFSVRS/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
502 udev_update)
503 svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
504 esac
505 echo -ne "done\n"
506 # Set the canonical book version
507 cd $JHALFSDIR
508 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
509 extract_commands
510 fi
511 else
512 echo -ne "Using $BOOK as book's sources ...\n"
513 # Set the canonical book version
514 cd $JHALFSDIR
515 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
516 extract_commands
517 fi
518}
519
520
521#----------------------------#
522build_patches_file() { # Supply a suitably formated list of patches.
523#----------------------------#
524 local saveIFS=$IFS
525 local IFS
526
527 rm -f patches
528
529 LOC_add_patches_entry() {
530 for f in `grep "/$1-" patcheslist_.wget`; do
531 basename $f | sed "s|${2}|\&${1}-version;|" >> patches
532 done
533 }
534
535 case ${PROGNAME} in
536 hlfs)
537 echo -n "Creating the HLFS ${L_arrow}${BOLD}$MODEL${R_arrow} specific patches file"
538 xsltproc --nonet \
539 --xinclude \
540 --stringparam model $MODEL \
541 -o patcheslist_.wget \
542 patcheslist.xsl \
543 $BOOK/chapter04/patches.xml
544 #> /dev/null 2>&1
545
546 # .... U G L Y .... what to do with the grsecurity patch to the kernel..
547 for f in `grep "/grsecurity-" patcheslist_.wget`; do
548 basename $f >> patches
549 done
550 ;;
551
552 clfs) # Pull out a list of arch specific patches
553 echo -n "Creating CLFS ${L_arrow}${BOLD}$ARCH${R_arrow} specific patches file"
554 xsltproc -xinclude \
555 -o patcheslist_.wget \
556 patcheslist.xsl \
557 $BOOK/materials/${ARCH}-chapter.xml
558 ;;
559 *) return
560 esac
561
562
563 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
564 for f in `cat packages`; do
565 IFS=$saveIFS # Restore the system defaults
566 LOC_add_patches_entry \
567 `echo $f | sed -e 's/-version//' \
568 -e 's/-file.*//' \
569 -e 's/"//g' \
570 -e 's/uclibc/uClibc/'`
571 done
572
573 rm -f patcheslist_.wget
574
575 echo " ...OK"
576}
577
578
579#----------------------------#
580extract_commands() { #
581#----------------------------#
582 local saveIFS=$IFS
583
584 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
585 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
586 exit 1"
587
588 cd $JHALFSDIR
589 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
590
591 # Start clean
592 if [ -d ${PROGNAME}-commands ]; then
593 rm -rf ${PROGNAME}-commands
594 mkdir -v ${PROGNAME}-commands
595 fi
596 echo -n "Extracting commands for"
597
598 # Dump the commands in shell script form from the HLFS book.
599 case ${PROGNAME} in
600 clfs)
601 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
602 xsltproc --nonet \
603 --xinclude \
604 --stringparam method $METHOD \
605 --stringparam testsuite $TEST \
606 --stringparam vim-lang $VIMLANG \
607 --stringparam timezone $TIMEZONE \
608 --stringparam page $PAGE \
609 --stringparam lang $LANG \
610 --stringparam keymap $KEYMAP \
611 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
612 ;;
613 hlfs)
614 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
615 xsltproc --nonet \
616 --xinclude \
617 --stringparam model $MODEL \
618 --stringparam testsuite $TEST \
619 --stringparam timezone $TIMEZONE \
620 --stringparam page $PAGE \
621 --stringparam lang $LANG \
622 --stringparam lc_all $LC_ALL \
623 --stringparam keymap $KEYMAP \
624 --stringparam grsecurity_host $GRSECURITY_HOST \
625 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
626 ;;
627 lfs)
628 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
629 xsltproc --nonet \
630 --xinclude \
631 --stringparam testsuite $TEST \
632 --stringparam vim-lang $VIMLANG \
633 --stringparam timezone $TIMEZONE \
634 --stringparam page $PAGE \
635 --stringparam lang $LANG \
636 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
637 ;;
638 blfs)
639 echo -n " ${L_arrow}${BOLD}BLFS${R_arrow} build"
640 xsltproc --nonet \
641 --xinclude \
642 --stringparam testsuite $TEST \
643 --stringparam server $SERVER \
644 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
645 ;;
646 *) exit 1
647 esac
648
649 echo " ...OK"
650
651 # Make the scripts executable.
652 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
653
654 # Grab the patches and package names.
655 for i in patches packages ; do
656 rm -f $i
657 done
658 #
659 case "${PROGNAME}" in
660 clfs)
661 ################################
662 # A LOCAL function
663 # xx_.wget contains arch specific files but in URL format
664 # Build a file with only arch specific files.. small ugly..
665 LOC_add_packages_entry() {
666 local fileMATCH aFILE
667
668 # Deal with a non-standard format
669 if [[ "$1" = "clfs-bootscripts" ]]; then
670 set -- "bootscripts-cross-lfs" $2
671 fi
672 fileMATCH="/$1"
673
674 # format.. Filename-Version or FilenameVersion
675 for aFILE in `grep ${fileMATCH}-*[[:digit:]] packageslist_.wget`; do
676 # Block vim-x.x-lang file, will add it later based on config flag
677 if [[ ! "${aFILE}" =~ "vim-$2-lang" ]]; then
678 echo "$1-version \"$2\"" >> packages
679 fi
680 done
681 }
682 #################################
683
684 # We only want a list arch specific files..
685 # Unfortunately this script produces URL's which must be converted to a std format
686 echo -n "Creating CLFS ${L_arrow}${BOLD}${ARCH}${R_arrow} specific packages file"
687 xsltproc -xinclude \
688 -o packageslist_.wget \
689 packageslist.xsl \
690 $BOOK/materials/${ARCH}-chapter.xml
691
692 # This has the correct format but contains packages from every book
693 grep "\-version " $BOOK/packages.ent | sed -e 's@<!ENTITY @@' \
694 -e 's@">@"@' \
695 -e '/generic/d' > packages.tmp
696 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
697 # separates each iteration by lines.
698 # Modify the 'internal field separator' to break on 'LF' only
699 IFS=$'\x0A'
700 for f in `cat packages.tmp`; do
701 IFS=$saveIFS # Restore the system defaults
702 LOC_add_packages_entry \
703 `echo $f | sed -e 's/-version//' \
704 -e 's/-file.*//' \
705 -e 's/"//g'`
706 done
707
708 rm -f packageslist_.wget packages.tmp
709
710 echo " ...OK"
711 ;;
712
713 hlfs)
714 echo -n "Creating <${PROGNAME}> specific packages file"
715 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
716 -e 's@">@"@' \
717 -e '/generic/d' >> packages
718 echo " ...OK"
719 ;;
720
721 lfs)
722 echo -n "Creating <${PROGNAME}> specific packages file"
723 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
724 -e 's@">@"@' \
725 -e '/generic/d' >> packages
726 echo `grep "glibc" packages | sed 's@glibc@glibc-libidn@'` >> packages
727 echo `grep "udev-config-file" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@'` >> packages
728 echo " ...OK"
729 ;;
730 esac
731
732 # Download the vim-lang package if it must be installed
733 if [ "$VIMLANG" = "1" ] && [ ! "$PROGNAME" = "hlfs" ] ; then
734 echo `grep "vim" packages | sed 's@vim@&-lang@'` >> packages
735 fi
736
737 # Create the patches file
738 case "${PROGNAME}" in
739 hlfs)
740 build_patches_file ;;
741 clfs )
742 build_patches_file ;;
743 lfs)
744 grep "^<\!ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
745 ;;
746 blfs) ;;
747 *) exit 1
748 esac
749
750 # Done. Moving on...
751 get_sources
752}
753
754
755#----------------------------#
756download() { # Download file, write name to MISSING_FILES.DMP if an error
757#----------------------------#
758 cd $BUILDDIR/sources
759
760 # Hackish fix for the bash-doc, glibc-{linuxthreads,libidn}
761 # that don't conform to norms in the URL scheme.
762 DIR=`echo $1 | sed 's@-doc@@;s@-linuxthreads@@;s@-libidn@@;s@-testsuite@@'`
763
764 # If the file exists in the archive copy it to the $BUILDDIR/sources dir
765 # MD5SUM is assumed to be correct from previous download
766 if [ ! -z ${SRC_ARCHIVE} ] &&
767 [ -d ${SRC_ARCHIVE} ] &&
768 [ -f ${SRC_ARCHIVE}/$2 ]; then
769 cp ${SRC_ARCHIVE}/$2 .
770 echo "$2: -- ok"
771 return
772 fi
773
774 # Find the md5 sum for this package.
775 if [ $2 != MD5SUMS ] ; then
776 set +e
777 MD5=`grep " $2" MD5SUMS`
778 if [ $? -ne 0 ]; then
779 set -e
780 echo "${RED}$2 not found in MD5SUMS${OFF}"
781 echo "$2 not found in MD5SUMS" >> MISSING_FILES.DMP
782 return
783 fi
784 set -e
785 fi
786
787 if [ ! -f $2 ] ; then
788 case $DL in
789 wgetFTP ) wget --passive $FTP/$DIR/$2 ;;
790 wget ) wget $HTTP/$DIR/$2 ;;
791 curl ) `curl -# $FTP/$DIR/$2 -o $2` ;;
792 * ) echo "$DL not supported at this time." ;;
793 esac
794 elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
795 case $DL in
796 wgetFTP ) wget --passive -c $FTP/$DIR/$2 ;;
797 wget ) wget -c $HTTP/$DIR/$2 ;;
798 curl ) `curl -# -C - $FTP/$DIR/$2 -o $2` ;;
799 * ) echo "$DL not supported at this time." ;;
800 esac
801 fi
802
803 if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
804 exit 1
805 fi
806 if [ $2 != MD5SUMS ] ; then
807 echo `grep "$MD5" MD5SUMS` >> MD5SUMS-$VERSION
808 fi
809
810 # If we make it this far we should copy the freshly downloaded file
811 # to the source archive.
812 if [ ! -z ${SRC_ARCHIVE} ] &&
813 [ -d ${SRC_ARCHIVE} ] &&
814 [ -w ${SRC_ARCHIVE} ] &&
815 [ $2 != MD5SUMS ]; then
816 echo "Store file:<$2> in package archive"
817 cp -v $2 ${SRC_ARCHIVE}
818 fi
819
820}
821
822
823#----------------------------#
824get_sources() {
825#----------------------------#
826
827 # Test if the packages must be downloaded
828 if [ "$HPKG" = "1" ] ; then
829
830 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
831 # separates each iteration by lines.
832 # Modify the 'internal field separator' to break on 'LF' only
833 IFS=$'\x0A'
834
835 if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
836 cd $BUILDDIR/sources
837 if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
838 if [ -f MD5SUMS-$VERSION ] ; then rm MD5SUMS-$VERSION ; fi
839 if [ -f MISSING_FILES.DMP ] ; then rm MISSING_FILES.DMP ; fi
840
841 download "" MD5SUMS
842
843 # Iterate through each package and grab it, along with any patches it needs.
844 for i in `cat $JHALFSDIR/packages` ; do
845 PKG=`echo $i | sed -e 's/-version.*//' -e 's/-file.*//'`
846
847 # There are some entities that aren't valid packages.
848 if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
849
850 VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
851 case $PKG in
852 tcl) FILE="$PKG$VRS-src.tar.bz2" ;;
853 vim-lang) PKG="vim"
854 FILE="vim-$VRS-lang.tar.bz2" ;;
855 udev-config) PKG="udev"
856 FILE="$VRS" ;;
857 *) FILE="$PKG-$VRS.tar.bz2" ;;
858 esac
859 download $PKG $FILE
860
861 # Download any associated patches
862 for patch in `grep "&$PKG-version" $JHALFSDIR/patches` ; do
863 PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
864 download $PKG $PATCH
865 done
866 done
867 if [[ -s $BUILDDIR/sources/MISSING_FILES.DMP ]]; then
868 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"
869 fi
870 fi
871}
872
Note: See TracBrowser for help on using the repository browser.