source: common/common-functions@ 0bdf6ed

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

Changing how build time and disk usage is dumped to the logs. Fisrt set.
Removed an obsolete function.
Placed together wrt_run_as_* functions.

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