source: common/common-functions@ d20c553

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

Merged r2633:2639 from trunk.

  • Property mode set to 100644
File size: 24.7 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
42${RED}IMPORTANT:${OFF} Only supported command line switches are listed here.
43 For more fine-grained setups you must edit the relevant
44 configuration files placed under ${BOLD}common/${OFF} and ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])/${OFF}
45
46Options:
47${BOLD} -h, --help${OFF}
48 print this help, then exit
49
50${BOLD} -V, --version${OFF}
51 print version information, then exit
52
53${BOLD} -B, --book VER${OFF}
54 use VER version of the book as the system to build.
55 Supported versions are: dev*, trunk, SVN
56 These are aliases for the Development version of {C,H,B}LFS
57
58${BOLD} -D --directory DIR${OFF}
59 use DIR directory for building ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF}; all files jhalfs-X produces
60 will be in the directory DIR/jhalfs.
61 The current setting for BUILDDIR is "$BUILDDIR"
62
63${BOLD} -G, --get-packages${OFF}
64 download the packages and patches. This assumes that the server declared
65 in the configuration file has the proper packages and patches for the
66 book version being processed.
67
68${BOLD} -T, --testsuites N ${OFF}
69 Run test suites [0-3]
70 0 = none
71 1 = only final system Glibc, GCC and Binutils testsuites
72 2 = all final system testsuites
73 3 = all temporary tools and final system testsuites
74 In CLFS, 3 is an alias to 2
75 In BLFS, 1, 2, and 3 are equivalents and means that the testsuites
76 will be run.
77
78${BOLD} -W, --working-copy DIR${OFF}
79 use the local working copy placed in DIR as the $(echo $PROGNAME | tr [a-z] [A-Z]) book
80-EOF-
81
82[[ ${PROGNAME} != "blfs" ]] &&
83cat <<- -EOF-
84
85${BOLD} -C, --comparasion TYPE${OFF}
86 do iterative comparison analysis. This extends the total build time
87 considerably because the entire final system will rebuild itself
88 the number of times specified by ITERATIONS in common/config.
89 Types allowed are:
90 ICA = do ICA as designed by Greg Schafer
91 farce = do the farce analysis designed by Ken Moffat
92 both = perfom both ICA and farce analysis
93
94${BOLD} -F, --fstab FILE${OFF}
95 use FILE as the /etc/fstab file for the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} system. If not specified,
96 a default /etc/fstab file with dummy values is created.
97
98${BOLD} -K, --kernel-config FILE${OFF}
99 use the kernel configuration file specified in FILE to build the kernel.
100 if the file is not found, or if not specified, the kernel build is skipped.
101
102${BOLD} -M, --run-make${OFF}
103 run make on the generated Makefile
104
105${BOLD} -R --rebuild${OFF}
106 clean the build directory before perfoming any other task. The directory
107 is cleaned only if it was populated by a previous jhalfs-X run.
108-EOF-
109
110[[ ${PROGNAME} = "clfs" ]] &&
111cat <<- -EOF-
112
113${BOLD} -A, --arch ARCH ${OFF}
114 Select the TARGET architecture, valid selections are:
115 32bit builds
116 x86, i486, i586, ppc, mips, mipsel, sparc
117 64bit builds
118 x86_64-64, mips64-64, mipsel64-64, sparc64-64, alpha
119 64bit multi-lib
120 x86_64, mips64, mipsel64, sparc64, ppc64
121
122${BOLD} --boot-config FILE ${OFF}
123 The configuration file for the bootstrap kernel if method=boot
124
125${BOLD} --method BUILDMETHOD ${OFF}
126 Select the build method, chroot or boot
127-EOF-
128
129[[ ${PROGNAME} = "hlfs" ]] &&
130cat <<- -EOF-
131
132${BOLD} --model STYLE ${OFF}
133 Select the library model for the HLFS system
134 Valid choices are: glibc or uclibc
135-EOF-
136
137[[ ${PROGNAME} = "blfs" ]] &&
138cat <<- -EOF-
139
140${BOLD} --dependencies 0/1/2${OFF}
141 add dependencies of type TYPE to the build tree.
142 If not set, both required and recommended are used.
143
144 Possible values are:
145 0 - required only required dependecies are used
146 1 - recommended both required a recommended dependencies are used
147 2 - optional all dependencies are used
148-EOF-
149
150cat <<- -EOF-
151${DD_BORDER}
152-EOF-
153 exit
154}
155
156version="
157${BOLD} \"jhalfs-X\"${OFF} builder tool (experimental) \$Rev$
158\$Date$
159
160${BOLD} \"${PROGNAME}\"${OFF} script module
161
162Written by George Boudreau,
163 Manuel Canales Esparcia,
164 Jeremy Huntwork
165
166This program is published under the ${BOLD}Gnu General Public License, Version 2.${OFF}
167"
168
169
170no_empty_builddir() {
171 'clear'
172cat <<- -EOF-
173${DD_BORDER}
174
175${tab_}${tab_}${BOLD}${RED}W A R N I N G${OFF}
176 Looks like the \$BUILDDIR directory contains subdirectories
177 from a previous HLFS build.
178
179 Please format the partition mounted on \$BUILDDIR or set
180 a different build directory before running jhalfs-X.
181${OFF}
182${DD_BORDER}
183-EOF-
184 exit
185}
186
187
188help="${nl_}Try '$0 --help' for more information."
189
190
191exit_missing_arg="\
192echo \"Option '\$1' requires an argument\" >&2
193echo \"\$help\" >&2
194exit 1"
195
196no_dl_client="\
197echo \"Could not find a way to download the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} sources.\" >&2
198echo \"Attempting to continue.\" >&2"
199
200HEADER="# This file is automatically generated by jhalfs-X
201# DO NOT EDIT THIS FILE MANUALLY
202#
203# Generated on `date \"+%F %X %Z\"`"
204
205
206
207#----------------------------------#
208wrt_target() { # Create target and initialize log file
209#----------------------------------#
210 local i=$1
211 local PREV=$2
212 case $i in
213 iteration* ) local LOGFILE=$this_script.log ;;
214 * ) local LOGFILE=$this_script ;;
215 esac
216(
217cat << EOF
218
219$i: $PREV
220 @\$(call echo_message, Building)
221 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >logs/$LOGFILE
222EOF
223) >> $MKFILE.tmp
224}
225
226
227#----------------------------------#
228wrt_unpack() { # Unpack and set 'ROOT' var
229#----------------------------------#
230 local FILE=$1
231(
232cat << EOF
233 @\$(call unpack,$FILE)
234 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
235 echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
236 chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT
237EOF
238) >> $MKFILE.tmp
239}
240
241
242#----------------------------------#
243wrt_unpack2() { #
244#----------------------------------#
245 local FILE=$1
246(
247cat << EOF
248 @\$(call unpack2,$FILE)
249 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
250 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
251EOF
252) >> $MKFILE.tmp
253}
254
255
256#----------------------------------#
257wrt_unpack3() { #
258#----------------------------------#
259 local FILE=$1
260(
261cat << EOF
262 @\$(call unpack3,$FILE)
263 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
264 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
265EOF
266) >> $MKFILE.tmp
267}
268
269
270#----------------------------------#
271wrt_target_vars() { # Target vars for hlfs (cross-build method)
272#----------------------------------#
273(
274cat << EOF
275 @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
276 echo "export ldso=/lib/${LOADER}" >> envars
277EOF
278) >> $MKFILE.tmp
279
280}
281
282
283#----------------------------------#
284wrt_optimize() { # Apply pkg specific opt's to build
285#----------------------------------#
286 local pkg=$1
287 local optLvl optVal OPT_VAR
288
289 optLvl=`awk -v pkg="$pkg" '$1 == pkg { print $2 }' $JHALFSDIR/opt_override`
290 if [[ "$optLvl" = "" ]] ; then
291 optLvl=$DEF_OPT_LVL;
292 fi
293
294 for OPT_VAR in CFLAGS CXXFLAGS LDFLAGS; do
295 eval optVal=\$${OPT_VAR}_$optLvl
296
297 if [[ "$optVal" != "unset" ]]; then
298 case $pkg in
299 *zlib* ) [[ "$OPT_VAR" != "LDFLAGS" ]] && optVal="$optVal -fPIC" ;;
300 esac
301(
302cat << EOF
303 @echo "export $OPT_VAR=\"$optVal\"" >> envars
304EOF
305) >> $MKFILE.tmp
306 else
307 continue
308 fi
309 done
310}
311
312
313#----------------------------------#
314wrt_run_as_su() { # Execute script inside time { }, footer to log file
315#----------------------------------#
316 local this_script=$1
317 local file=$2
318(
319cat << EOF
320 @( time { su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
321 echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/$this_script
322EOF
323) >> $MKFILE.tmp
324}
325
326
327#----------------------------------#
328wrt_run_as_root() { # Some scripts must be run as root..
329#----------------------------------#
330 local this_script=$1
331 local file=$2
332(
333cat << EOF
334 @( time { export LFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
335 echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/$this_script
336EOF
337) >> $MKFILE.tmp
338}
339
340
341#----------------------------------#
342wrt_run_as_root2() { #
343#----------------------------------#
344 local this_script=$1
345 local file=$2
346(
347cat << EOF
348 @( time { source envars && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
349 echo -e "\nKB: \`du -skx --exclude=jhalfs \`\n" >>logs/$this_script
350EOF
351) >> $MKFILE.tmp
352}
353
354
355
356#----------------------------------#
357wrt_run_as_chroot1() { #
358#----------------------------------#
359 local this_script=$1
360 local file=$2
361(
362 cat << EOF
363 @( time { \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
364 echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/${this_script}
365EOF
366) >> $MKFILE.tmp
367}
368
369
370#----------------------------------#
371wrt_run_as_chroot2() { #
372#----------------------------------#
373 local this_script=$1
374 local file=$2
375(
376cat << EOF
377 @( time { \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
378 echo -e "\nKB: \`du -skx --exclude=jhalfs \$(MOUNT_PT)\`\n" >>logs/${this_script}
379EOF
380) >> $MKFILE.tmp
381}
382
383
384#----------------------------------#
385wrt_copy_fstab() { #
386#----------------------------------#
387 local i=$1
388(
389 cat << EOF
390 @cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1
391EOF
392) >> $MKFILE.tmp
393}
394
395#----------------------------------#
396wrt_copy_fstab2() { #
397#----------------------------------#
398 local i=$1
399(
400 cat << EOF
401 @cp -v /sources/fstab /etc/fstab >>logs/$i 2>&1
402EOF
403) >> $MKFILE.tmp
404}
405
406
407#----------------------------------#
408wrt_remove_build_dirs() { #
409#----------------------------------#
410 local name=$1
411(
412cat << EOF
413 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
414 rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
415 if [ -e \$(MOUNT_PT)\$(SRC)/$name-build ]; then \\
416 rm -r \$(MOUNT_PT)\$(SRC)/$name-build; \\
417 fi;
418EOF
419) >> $MKFILE.tmp
420}
421
422
423#----------------------------------#
424wrt_remove_build_dirs2() { #
425#----------------------------------#
426 local name=$1
427(
428cat << EOF
429 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
430 rm -r \$(SRC)/\$\$ROOT && \\
431 if [ -e \$(SRC)/$name-build ]; then \\
432 rm -r \$(SRC)/$name-build; \\
433 fi;
434EOF
435) >> $MKFILE.tmp
436}
437
438
439#----------------------------------#
440wrt_report() { #
441#----------------------------------#
442(
443cat << EOF
444
445create-sbu_du-report: $PREV
446 @\$(call echo_message, Building)
447 @./create-sbu_du-report.sh logs $VERSION
448 @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
449 @touch \$@
450EOF
451) >> $MKFILE.tmp
452
453chapter789="$chapter789 create-sbu_du-report"
454}
455
456
457#----------------------------#
458run_make() { #
459#----------------------------#
460 # Test if make must be run.
461 if [ "$RUNMAKE" = "1" ] ; then
462 # Test to make sure we're running the build as root
463 if [ "$UID" != "0" ] ; then
464 echo "You must be logged in as root to successfully build the system."
465 exit 1
466 fi
467 # Build the system
468 if [ -e $MKFILE ] ; then
469 echo -ne "Building the system...\n"
470 cd $JHALFSDIR && make
471 echo -ne "done\n"
472 fi
473 fi
474}
475
476
477#----------------------------#
478clean_builddir() { #
479#----------------------------#
480 # Test if the clean must be done.
481 if [ "$CLEAN" = "1" ] ; then
482 # Test to make sure we're running the clean as root
483 if [ "$UID" != "0" ] ; then
484 echo "You must be logged in as root to clean the build directory."
485 exit 1
486 fi
487 # Test to make sure that the build directory was populated by jhalfs
488 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
489 echo "Looks like $BUILDDIR was not populated by a previous jhalfs-X run."
490 exit 1
491 else
492 # Clean the build directory
493 echo -ne "Cleaning $BUILDDIR...\n"
494 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
495 echo -ne "Cleaning $JHALFSDIR...\n"
496 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
497 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
498 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
499 echo -ne "done\n"
500 fi
501 fi
502}
503
504#----------------------------#
505get_book() { #
506#----------------------------#
507 cd $JHALFSDIR
508
509 if [ -z $WC ] ; then
510 # Check for Subversion instead of just letting the script hit 'svn' and fail.
511 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
512 exit 1"
513 echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
514
515 case $PROGNAME in
516 lfs) svn_root="LFS" ;;
517 hlfs) svn_root="HLFS" ;;
518 clfs) svn_root="cross-lfs" ;;
519 blfs) svn_root="BLFS" ;;
520 *) echo "BOOK not defined in function <get_book>"
521 exit 1 ;;
522 esac
523 # Grab a fresh book if it's missing, otherwise, update it from the
524 # repo. If we've already extracted the commands, move on to getting the
525 # sources.
526 if [ -d ${PROGNAME}-$LFSVRS ] ; then
527 cd ${PROGNAME}-$LFSVRS
528 if LC_ALL=C svn up | grep -q At && test -d $JHALFSDIR/${PROGNAME}-commands && \
529 test -f $JHALFSDIR/packages ; then
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 get_sources
535 else
536 echo -ne "done\n"
537 # Set the canonical book version
538 cd $JHALFSDIR
539 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
540 extract_commands
541 fi
542 else
543 case $LFSVRS in
544 development)
545 svn co $SVN/${svn_root}/trunk/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
546 esac
547 echo -ne "done\n"
548 # Set the canonical book version
549 cd $JHALFSDIR
550 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
551 extract_commands
552 fi
553 else
554 echo -ne "Using $BOOK as book's sources ...\n"
555 # Set the canonical book version
556 cd $JHALFSDIR
557 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
558 extract_commands
559 fi
560}
561
562#----------------------------#
563extract_commands() { #
564#----------------------------#
565
566 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
567 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
568 exit 1"
569
570 cd $JHALFSDIR
571 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
572
573 # Start clean
574 if [ -d ${PROGNAME}-commands ]; then
575 rm -rf ${PROGNAME}-commands
576 mkdir -v ${PROGNAME}-commands
577 fi
578 echo -n "Extracting commands for"
579
580 # Dump the commands in shell script form from the HLFS book.
581 case ${PROGNAME} in
582 clfs)
583 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
584 xsltproc --nonet \
585 --xinclude \
586 --stringparam method $METHOD \
587 --stringparam testsuite $TEST \
588 --stringparam vim-lang $VIMLANG \
589 --stringparam timezone $TIMEZONE \
590 --stringparam page $PAGE \
591 --stringparam lang $LANG \
592 --stringparam keymap $KEYMAP \
593 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
594 ;;
595 hlfs)
596 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
597 xsltproc --nonet \
598 --xinclude \
599 --stringparam model $MODEL \
600 --stringparam testsuite $TEST \
601 --stringparam timezone $TIMEZONE \
602 --stringparam page $PAGE \
603 --stringparam lang $LANG \
604 --stringparam lc_all $LC_ALL \
605 --stringparam keymap $KEYMAP \
606 --stringparam grsecurity_host $GRSECURITY_HOST \
607 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
608 ;;
609 lfs)
610 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
611 xsltproc --nonet \
612 --xinclude \
613 --stringparam testsuite $TEST \
614 --stringparam vim-lang $VIMLANG \
615 --stringparam timezone $TIMEZONE \
616 --stringparam page $PAGE \
617 --stringparam lang $LANG \
618 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
619 ;;
620 blfs)
621 echo -n " ${L_arrow}${BOLD}BLFS${R_arrow} build"
622 xsltproc --nonet \
623 --xinclude \
624 --stringparam testsuite $TEST \
625 --stringparam server $SERVER \
626 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
627 ;;
628 *) exit 1 ;;
629 esac
630
631 echo " ...OK"
632
633 # Make the scripts executable.
634 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
635
636 # Create the packages file. We need it for proper Makefile creation
637 rm -f packages
638 case "${PROGNAME}" in
639 clfs)
640 echo -n "Creating <${PROGNAME}> specific packages file"
641 grep "\-version " $BOOK/packages.ent | sed -e 's@<!ENTITY @@' \
642 -e 's@">@"@' \
643 -e '/generic/d' > packages
644 echo " ...OK"
645 ;;
646
647 hlfs)
648 echo -n "Creating <${PROGNAME}> specific packages file"
649 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
650 -e 's@">@"@' \
651 -e '/generic/d' >> packages
652 echo " ...OK"
653 ;;
654
655 lfs)
656 echo -n "Creating <${PROGNAME}> specific packages file"
657 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
658 -e 's@">@"@' \
659 -e '/generic/d' >> packages
660 echo " ...OK"
661 ;;
662 esac
663
664 # Done. Moving on...
665 get_sources
666}
667
668#----------------------------#
669get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
670#----------------------------#
671 local saveIFS=$IFS
672 local IFS line URL1 URL2 FILE MD5 HAVEMD5 fromARCHIVE
673
674 # Test if the packages must be downloaded
675 [ ! "$GETPKG" = "1" ] && return
676
677 gs_wrt_message(){
678 echo "${RED}$1${OFF}"
679 echo "$1" >> MISSING_FILES.DMP
680 }
681 # Housekeeping
682 [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
683 cd $BUILDDIR/sources
684 [[ -f MD5SUMS ]] && rm MD5SUMS
685 [[ -f MD5SUMS-$VERSION ]] && rm MD5SUMS-$VERSION
686 [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
687 [[ -f urls.lst ]] && rm urls.lst
688
689 # Download a fresh MD5SUMS file
690 wget $SERVER/pub/lfs/conglomeration/MD5SUMS
691
692 # Generate URLs file
693 create_urls
694
695 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
696 for line in `cat urls.lst`; do
697 IFS=$saveIFS # Restore the system defaults
698
699 # Skip some packages if they aren't needed
700 case $line in
701 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
702 [[ "$TEST" = "0" ]] && continue
703 ;;
704 */vim-*-lang* )
705 [[ "$VIMLANG" = "0" ]] && continue
706 ;;
707 esac
708
709 # Locations
710 URL1=`echo $line | cut -d" " -f2` # Preferred URL
711 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
712 FILE=`basename $URL2` # File name
713
714 # Find the md5 sum for this package.
715 set +e
716 HAVEMD5=1 # Always assume we have a MD5SUM
717 MD5=`grep " $FILE" MD5SUMS`
718 if [ $? -ne 0 ]; then
719 set -e
720 gs_wrt_message "$FILE not found in MD5SUMS"
721 # IMPORTANT:: There is no MD5SUM for this file.
722 HAVEMD5=0
723 fi
724
725 set -e
726 # If the file exists in the archive copy it to the
727 # $BUILDDIR/sources dir. MD5SUM will be validated later.
728 if [ ! -z ${SRC_ARCHIVE} ] &&
729 [ -d ${SRC_ARCHIVE} ] &&
730 [ -f ${SRC_ARCHIVE}/$FILE ]; then
731 cp ${SRC_ARCHIVE}/$FILE .
732 echo "$FILE: -- copied from $SRC_ARCHIVE"
733 fromARCHIVE=1
734 else
735 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
736 fromARCHIVE=0
737 # If the file does not exist in /sources download a fresh one
738 if [ ! -f $FILE ] ; then
739 if ! wget $URL1 && ! wget $URL2 ; then
740 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
741 continue
742 fi
743 fi
744 fi
745
746 # Is there a MD5SUM to validate the file against.
747 if [[ "$HAVEMD5" = "1" ]] ; then
748 # IF the md5sum does not match the existing files
749 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
750 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
751 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
752 # Remove the old file and download a new one
753 rm -fv $FILE
754 # Force generation of MD5SUM and storage in SRC_ARCHIVE
755 fromARCHIVE=0; HAVEMD5=0
756 # Try and retrieve the file
757 if ! wget -N $URL1 && ! wget -N $URL2 ; then
758 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
759 continue
760 fi
761 fi
762 fi
763
764 # Validate the MD5SUM one last time
765 if [[ "$HAVEMD5" = "1" ]] && ! echo "$MD5" | md5sum -c - >/dev/null ; then
766 gs_wrt_message "$FILE does not match MD5SUMS value"
767 fi
768
769 # Generate a fresh MD5SUM for this file
770 if [[ "$HAVEMD5" = "0" ]] ; then
771 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
772 echo "NEW MD5SUM $(md5sum $FILE)" >> MISSING_FILES.DMP
773 fi
774
775 # Good or bad we write the original md5sum to a file
776 echo "$MD5" >> MD5SUMS-$VERSION
777
778 # Copy the freshly downloaded file
779 # to the source archive.
780 if [ ! -z ${SRC_ARCHIVE} ] &&
781 [ -d ${SRC_ARCHIVE} ] &&
782 [ -w ${SRC_ARCHIVE} ] &&
783 [ "$fromARCHIVE" = "0" ] ; then
784 echo "Storing file:<$FILE> in the package archive"
785 cp -f $FILE ${SRC_ARCHIVE}
786 fi
787
788 done
789
790 if [[ -s MISSING_FILES.DMP ]]; then
791 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"
792 # Do not allow the automatic exection of the Makefile.
793 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
794 RUNMAKE=0
795 fi
796}
797
798
799#----------------------------#
800create_urls() { #
801#----------------------------#
802 cd $JHALFSDIR
803
804 case ${PROGNAME} in
805 clfs)
806 echo -n "Creating CLFS <${ARCH}> specific URLs file"
807 xsltproc --nonet --xinclude \
808 --stringparam server $SERVER \
809 -o $BUILDDIR/sources/urls.lst urls.xsl \
810 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
811 echo " ...OK"
812 ;;
813 hlfs)
814 echo -n "Creating HLFS <${MODEL}> specific URLs file"
815 xsltproc --nonet --xinclude \
816 --stringparam server $SERVER \
817 --stringparam model $MODEL \
818 -o $BUILDDIR/sources/urls.lst urls.xsl \
819 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
820 echo " ...OK"
821 ;;
822 lfs)
823 echo -n "Creating LFS specific URLs file"
824 xsltproc --nonet --xinclude \
825 --stringparam server $SERVER \
826 -o ../sources/urls.lst urls.xsl \
827 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
828 echo " ...OK"
829 ;;
830 esac
831
832 cd $BUILDDIR/sources
833}
Note: See TracBrowser for help on using the repository browser.