source: common/common-functions@ b7faa5a

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

Reverting r2729 until a better solution is found

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