source: common/common-functions@ e2fa2bd

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since e2fa2bd was e2fa2bd, checked in by Jeremy Huntwork <jhuntwork@…>, 19 years ago

Re-worded some help descriptions

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