source: common/common-functions@ 17c7894

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

POC for optimizations code.

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