source: common/common-functions@ b414549

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

Merged r2630 and r2631 from trunk.

  • Property mode set to 100644
File size: 24.4 KB
Line 
1#!/bin/bash
2
3# $Id$
4
5set +e
6
7# VT100 colors
8declare -r BLACK=$'\e[1;30m'
9declare -r DK_GRAY=$'\e[0;30m'
10
11declare -r RED=$'\e[31m'
12declare -r GREEN=$'\e[32m'
13declare -r YELLOW=$'\e[33m'
14declare -r BLUE=$'\e[34m'
15declare -r MAGENTA=$'\e[35m'
16declare -r CYAN=$'\e[36m'
17declare -r WHITE=$'\e[37m'
18
19declare -r OFF=$'\e[0m'
20declare -r BOLD=$'\e[1m'
21declare -r REVERSE=$'\e[7m'
22declare -r HIDDEN=$'\e[8m'
23
24declare -r tab_=$'\t'
25declare -r nl_=$'\n'
26
27declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
28declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
29declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
30
31# bold yellow > < pair
32declare -r R_arrow=$'\e[1;33m>\e[0m'
33declare -r L_arrow=$'\e[1;33m<\e[0m'
34
35
36usage() {
37cat <<- -EOF-
38${DD_BORDER}
39${BOLD}
40 Usage: $0 ${BOLD}[OPTION]
41
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
53${BOLD} -D --directory DIR${OFF}
54 use DIR directory for building ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF}; all files jhalfs-X produces
55 will be in the directory DIR/jhalfs.
56 The current setting for BUILDDIR is "$BUILDDIR"
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 analysis designed by Greg Schafer
85 farce = do the farce analysis designed by Ken Moffat
86 both = perfom both ICA and farce analysis
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#----------------------------------#
202wrt_target() { # Create target and initialize log file
203#----------------------------------#
204 local i=$1
205 local PREV=$2
206 case $i in
207 iteration* ) local LOGFILE=$this_script.log ;;
208 * ) local LOGFILE=$this_script ;;
209 esac
210(
211cat << EOF
212
213$i: $PREV
214 @\$(call echo_message, Building)
215 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >logs/$LOGFILE
216EOF
217) >> $MKFILE.tmp
218}
219
220
221#----------------------------------#
222wrt_unpack() { # Unpack and set 'ROOT' var
223#----------------------------------#
224 local FILE=$1
225(
226cat << EOF
227 @\$(call unpack,$FILE)
228 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
229 echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
230 chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT
231EOF
232) >> $MKFILE.tmp
233}
234
235
236#----------------------------------#
237wrt_unpack2() { #
238#----------------------------------#
239 local FILE=$1
240(
241cat << EOF
242 @\$(call unpack2,$FILE)
243 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
244 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
245EOF
246) >> $MKFILE.tmp
247}
248
249
250#----------------------------------#
251wrt_unpack3() { #
252#----------------------------------#
253 local FILE=$1
254(
255cat << EOF
256 @\$(call unpack3,$FILE)
257 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
258 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
259EOF
260) >> $MKFILE.tmp
261}
262
263
264#----------------------------------#
265wrt_target_vars() { # Target vars for hlfs (cross-build method)
266#----------------------------------#
267(
268cat << EOF
269 @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
270 echo "export ldso=/lib/${LOADER}" >> envars
271EOF
272) >> $MKFILE.tmp
273
274}
275
276
277#----------------------------------#
278wrt_optimize() { # Apply pkg specific opt's to build
279#----------------------------------#
280 local pkg=$1
281 local optLvl optVal OPT_VAR
282
283 optLvl=`awk -v pkg="$pkg" '$1 == pkg { print $2 }' $JHALFSDIR/opt_override`
284 if [[ "$optLvl" = "" ]] ; then
285 optLvl=$DEF_OPT_LVL;
286 fi
287
288 for OPT_VAR in CFLAGS CXXFLAGS LDFLAGS; do
289 eval optVal=\$${OPT_VAR}_$optLvl
290
291 if [[ "$optVal" != "unset" ]]; then
292 case $pkg in
293 *zlib* ) [[ "$OPT_VAR" != "LDFLAGS" ]] && optVal="$optVal -fPIC" ;;
294 esac
295(
296cat << EOF
297 @echo "export $OPT_VAR=\"$optVal\"" >> envars
298EOF
299) >> $MKFILE.tmp
300 else
301 continue
302 fi
303 done
304}
305
306
307#----------------------------------#
308wrt_run_as_su() { # Execute script inside time { }, footer to log file
309#----------------------------------#
310 local this_script=$1
311 local file=$2
312(
313cat << EOF
314 @( time { su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
315 echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/$this_script
316EOF
317) >> $MKFILE.tmp
318}
319
320
321#----------------------------------#
322wrt_run_as_root() { # Some scripts must be run as root..
323#----------------------------------#
324 local this_script=$1
325 local file=$2
326(
327cat << EOF
328 @( time { export LFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
329 echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/$this_script
330EOF
331) >> $MKFILE.tmp
332}
333
334
335#----------------------------------#
336wrt_run_as_root2() { #
337#----------------------------------#
338 local this_script=$1
339 local file=$2
340(
341cat << EOF
342 @( time { source envars && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
343 echo -e "\nKB: \`du -skx --exclude=jhalfs \`\n" >>logs/$this_script
344EOF
345) >> $MKFILE.tmp
346}
347
348
349
350#----------------------------------#
351wrt_run_as_chroot1() { #
352#----------------------------------#
353 local this_script=$1
354 local file=$2
355(
356 cat << EOF
357 @( time { \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
358 echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/${this_script}
359EOF
360) >> $MKFILE.tmp
361}
362
363
364#----------------------------------#
365wrt_run_as_chroot2() { #
366#----------------------------------#
367 local this_script=$1
368 local file=$2
369(
370cat << EOF
371 @( time { \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
372 echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/${this_script}
373EOF
374) >> $MKFILE.tmp
375}
376
377
378#----------------------------------#
379wrt_copy_fstab() { #
380#----------------------------------#
381 local i=$1
382(
383 cat << EOF
384 @cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1
385EOF
386) >> $MKFILE.tmp
387}
388
389#----------------------------------#
390wrt_copy_fstab2() { #
391#----------------------------------#
392 local i=$1
393(
394 cat << EOF
395 @cp -v /sources/fstab /etc/fstab >>logs/$i 2>&1
396EOF
397) >> $MKFILE.tmp
398}
399
400
401#----------------------------------#
402wrt_remove_build_dirs() { #
403#----------------------------------#
404 local name=$1
405(
406cat << EOF
407 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
408 rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
409 if [ -e \$(MOUNT_PT)\$(SRC)/$name-build ]; then \\
410 rm -r \$(MOUNT_PT)\$(SRC)/$name-build; \\
411 fi;
412EOF
413) >> $MKFILE.tmp
414}
415
416
417#----------------------------------#
418wrt_remove_build_dirs2() { #
419#----------------------------------#
420 local name=$1
421(
422cat << EOF
423 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
424 rm -r \$(SRC)/\$\$ROOT && \\
425 if [ -e \$(SRC)/$name-build ]; then \\
426 rm -r \$(SRC)/$name-build; \\
427 fi;
428EOF
429) >> $MKFILE.tmp
430}
431
432
433#----------------------------------#
434wrt_report() { #
435#----------------------------------#
436(
437cat << EOF
438
439create-sbu_du-report: $PREV
440 @\$(call echo_message, Building)
441 @./create-sbu_du-report.sh logs $VERSION
442 @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
443 @touch \$@
444EOF
445) >> $MKFILE.tmp
446
447chapter789="$chapter789 create-sbu_du-report"
448}
449
450
451#----------------------------#
452run_make() { #
453#----------------------------#
454 # Test if make must be run.
455 if [ "$RUNMAKE" = "1" ] ; then
456 # Test to make sure we're running the build as root
457 if [ "$UID" != "0" ] ; then
458 echo "You must be logged in as root to successfully build the system."
459 exit 1
460 fi
461 # Build the system
462 if [ -e $MKFILE ] ; then
463 echo -ne "Building the system...\n"
464 cd $JHALFSDIR && make
465 echo -ne "done\n"
466 fi
467 fi
468}
469
470
471#----------------------------#
472clean_builddir() { #
473#----------------------------#
474 # Test if the clean must be done.
475 if [ "$CLEAN" = "1" ] ; then
476 # Test to make sure we're running the clean as root
477 if [ "$UID" != "0" ] ; then
478 echo "You must be logged in as root to clean the build directory."
479 exit 1
480 fi
481 # Test to make sure that the build directory was populated by jhalfs
482 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
483 echo "Looks like $BUILDDIR was not populated by a previous jhalfs-X run."
484 exit 1
485 else
486 # Clean the build directory
487 echo -ne "Cleaning $BUILDDIR...\n"
488 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
489 echo -ne "Cleaning $JHALFSDIR...\n"
490 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
491 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
492 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
493 echo -ne "done\n"
494 fi
495 fi
496}
497
498#----------------------------#
499get_book() { #
500#----------------------------#
501 cd $JHALFSDIR
502
503 if [ -z $WC ] ; then
504 # Check for Subversion instead of just letting the script hit 'svn' and fail.
505 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
506 exit 1"
507 echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
508
509 case $PROGNAME in
510 lfs) svn_root="LFS" ;;
511 hlfs) svn_root="HLFS" ;;
512 clfs) svn_root="cross-lfs" ;;
513 blfs) svn_root="BLFS" ;;
514 *) echo "BOOK not defined in function <get_book>"
515 exit 1 ;;
516 esac
517 # Grab a fresh book if it's missing, otherwise, update it from the
518 # repo. If we've already extracted the commands, move on to getting the
519 # sources.
520 if [ -d ${PROGNAME}-$LFSVRS ] ; then
521 cd ${PROGNAME}-$LFSVRS
522 if LC_ALL=C svn up | grep -q At && test -d $JHALFSDIR/${PROGNAME}-commands && \
523 test -f $JHALFSDIR/packages ; then
524 echo -ne "done\n"
525 # Set the canonical book version
526 cd $JHALFSDIR
527 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
528 get_sources
529 else
530 echo -ne "done\n"
531 # Set the canonical book version
532 cd $JHALFSDIR
533 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
534 extract_commands
535 fi
536 else
537 case $LFSVRS in
538 development)
539 svn co $SVN/${svn_root}/trunk/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
540 esac
541 echo -ne "done\n"
542 # Set the canonical book version
543 cd $JHALFSDIR
544 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
545 extract_commands
546 fi
547 else
548 echo -ne "Using $BOOK as book's sources ...\n"
549 # Set the canonical book version
550 cd $JHALFSDIR
551 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
552 extract_commands
553 fi
554}
555
556#----------------------------#
557extract_commands() { #
558#----------------------------#
559
560 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
561 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
562 exit 1"
563
564 cd $JHALFSDIR
565 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
566
567 # Start clean
568 if [ -d ${PROGNAME}-commands ]; then
569 rm -rf ${PROGNAME}-commands
570 mkdir -v ${PROGNAME}-commands
571 fi
572 echo -n "Extracting commands for"
573
574 # Dump the commands in shell script form from the HLFS book.
575 case ${PROGNAME} in
576 clfs)
577 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
578 xsltproc --nonet \
579 --xinclude \
580 --stringparam method $METHOD \
581 --stringparam testsuite $TEST \
582 --stringparam vim-lang $VIMLANG \
583 --stringparam timezone $TIMEZONE \
584 --stringparam page $PAGE \
585 --stringparam lang $LANG \
586 --stringparam keymap $KEYMAP \
587 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
588 ;;
589 hlfs)
590 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
591 xsltproc --nonet \
592 --xinclude \
593 --stringparam model $MODEL \
594 --stringparam testsuite $TEST \
595 --stringparam timezone $TIMEZONE \
596 --stringparam page $PAGE \
597 --stringparam lang $LANG \
598 --stringparam lc_all $LC_ALL \
599 --stringparam keymap $KEYMAP \
600 --stringparam grsecurity_host $GRSECURITY_HOST \
601 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
602 ;;
603 lfs)
604 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
605 xsltproc --nonet \
606 --xinclude \
607 --stringparam testsuite $TEST \
608 --stringparam vim-lang $VIMLANG \
609 --stringparam timezone $TIMEZONE \
610 --stringparam page $PAGE \
611 --stringparam lang $LANG \
612 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
613 ;;
614 blfs)
615 echo -n " ${L_arrow}${BOLD}BLFS${R_arrow} build"
616 xsltproc --nonet \
617 --xinclude \
618 --stringparam testsuite $TEST \
619 --stringparam server $SERVER \
620 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
621 ;;
622 *) exit 1 ;;
623 esac
624
625 echo " ...OK"
626
627 # Make the scripts executable.
628 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
629
630 # Create the packages file. We need it for proper Makefile creation
631 rm -f packages
632 case "${PROGNAME}" in
633 clfs)
634 echo -n "Creating <${PROGNAME}> specific packages file"
635 grep "\-version " $BOOK/packages.ent | sed -e 's@<!ENTITY @@' \
636 -e 's@">@"@' \
637 -e '/generic/d' > packages
638 echo " ...OK"
639 ;;
640
641 hlfs)
642 echo -n "Creating <${PROGNAME}> specific packages file"
643 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
644 -e 's@">@"@' \
645 -e '/generic/d' >> packages
646 echo " ...OK"
647 ;;
648
649 lfs)
650 echo -n "Creating <${PROGNAME}> specific packages file"
651 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
652 -e 's@">@"@' \
653 -e '/generic/d' >> packages
654 echo " ...OK"
655 ;;
656 esac
657
658 # Done. Moving on...
659 get_sources
660}
661
662#----------------------------#
663get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
664#----------------------------#
665 local saveIFS=$IFS
666 local IFS line URL1 URL2 FILE MD5 HAVEMD5 fromARCHIVE
667
668 # Test if the packages must be downloaded
669 [ ! "$GETPKG" = "1" ] && return
670
671 gs_wrt_message(){
672 echo "${RED}$1${OFF}"
673 echo "$1" >> MISSING_FILES.DMP
674 }
675 # Housekeeping
676 [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
677 cd $BUILDDIR/sources
678 [[ -f MD5SUMS ]] && rm MD5SUMS
679 [[ -f MD5SUMS-$VERSION ]] && rm MD5SUMS-$VERSION
680 [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
681 [[ -f urls.lst ]] && rm urls.lst
682
683 # Download a fresh MD5SUMS file
684 wget $SERVER/pub/lfs/conglomeration/MD5SUMS
685
686 # Generate URLs file
687 create_urls
688
689 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
690 for line in `cat urls.lst`; do
691 IFS=$saveIFS # Restore the system defaults
692
693 # Skip some packages if they aren't needed
694 case $line in
695 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
696 [[ "$TEST" = "0" ]] && continue
697 ;;
698 */vim-*-lang* )
699 [[ "$VIMLANG" = "0" ]] && continue
700 ;;
701 esac
702
703 # Locations
704 URL1=`echo $line | cut -d" " -f2` # Preferred URL
705 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
706 FILE=`basename $URL2` # File name
707
708 # Find the md5 sum for this package.
709 set +e
710 HAVEMD5=1 # Always assume we have a MD5SUM
711 MD5=`grep " $FILE" MD5SUMS`
712 if [ $? -ne 0 ]; then
713 set -e
714 gs_wrt_message "$FILE not found in MD5SUMS"
715 # IMPORTANT:: There is no MD5SUM for this file.
716 HAVEMD5=0
717 fi
718
719 set -e
720 # If the file exists in the archive copy it to the
721 # $BUILDDIR/sources dir. MD5SUM will be validated later.
722 if [ ! -z ${SRC_ARCHIVE} ] &&
723 [ -d ${SRC_ARCHIVE} ] &&
724 [ -f ${SRC_ARCHIVE}/$FILE ]; then
725 cp ${SRC_ARCHIVE}/$FILE .
726 echo "$FILE: -- copied from $SRC_ARCHIVE"
727 fromARCHIVE=1
728 else
729 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
730 fromARCHIVE=0
731 # If the file does not exist in /sources download a fresh one
732 if [ ! -f $FILE ] ; then
733 if ! wget $URL1 && ! wget $URL2 ; then
734 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
735 continue
736 fi
737 fi
738 fi
739
740 # Is there a MD5SUM to validate the file against.
741 if [[ "$HAVEMD5" = "1" ]] ; then
742 # IF the md5sum does not match the existing files
743 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
744 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
745 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
746 # Remove the old file and download a new one
747 rm -fv $FILE
748 # Force generation of MD5SUM and storage in SRC_ARCHIVE
749 fromARCHIVE=0; HAVEMD5=0
750 # Try and retrieve the file
751 if ! wget -N $URL1 && ! wget -N $URL2 ; then
752 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
753 continue
754 fi
755 fi
756 fi
757
758 # Validate the MD5SUM one last time
759 if [[ "$HAVEMD5" = "1" ]] && ! echo "$MD5" | md5sum -c - >/dev/null ; then
760 gs_wrt_message "$FILE does not match MD5SUMS value"
761 fi
762
763 # Generate a fresh MD5SUM for this file
764 if [[ "$HAVEMD5" = "0" ]] ; then
765 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
766 echo "NEW MD5SUM $(md5sum $FILE)" >> MISSING_FILES.DMP
767 fi
768
769 # Good or bad we write the original md5sum to a file
770 echo "$MD5" >> MD5SUMS-$VERSION
771
772 # Copy the freshly downloaded file
773 # to the source archive.
774 if [ ! -z ${SRC_ARCHIVE} ] &&
775 [ -d ${SRC_ARCHIVE} ] &&
776 [ -w ${SRC_ARCHIVE} ] &&
777 [ "$fromARCHIVE" = "0" ] ; then
778 echo "Storing file:<$FILE> in the package archive"
779 cp -f $FILE ${SRC_ARCHIVE}
780 fi
781
782 done
783
784 if [[ -s MISSING_FILES.DMP ]]; then
785 echo -e "\n\n${tab_}${RED} One or more files were not retrieved or have a bad MD5SUMS chechsum.\n${tab_} Check ${L_arrow}$BUILDDIR/sources/MISSING_FILES.DMP${R_arrow} for names ${OFF}\n"
786 # Do not allow the automatic exection of the Makefile.
787 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
788 RUNMAKE=0
789 fi
790}
791
792
793#----------------------------#
794create_urls() { #
795#----------------------------#
796 cd $JHALFSDIR
797
798 case ${PROGNAME} in
799 clfs)
800 echo -n "Creating CLFS <${ARCH}> specific URLs file"
801 xsltproc --nonet --xinclude \
802 --stringparam server $SERVER \
803 -o $BUILDDIR/sources/urls.lst urls.xsl \
804 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
805 echo " ...OK"
806 ;;
807 hlfs)
808 echo -n "Creating HLFS <${MODEL}> specific URLs file"
809 xsltproc --nonet --xinclude \
810 --stringparam server $SERVER \
811 --stringparam model $MODEL \
812 -o $BUILDDIR/sources/urls.lst urls.xsl \
813 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
814 echo " ...OK"
815 ;;
816 lfs)
817 echo -n "Creating LFS specific URLs file"
818 xsltproc --nonet --xinclude \
819 --stringparam server $SERVER \
820 -o ../sources/urls.lst urls.xsl \
821 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
822 echo " ...OK"
823 ;;
824 esac
825
826 cd $BUILDDIR/sources
827}
Note: See TracBrowser for help on using the repository browser.