source: common/common-functions@ e071571

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

Added support for MD5 values sets into the book sources.

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