source: common/common-functions@ 4edf3b7

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

Changed a hack by proper code.

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