source: common/common-functions@ ab7bac5

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

Added instructions to always remove source and -build directories before running specific package commands

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