source: common/common-functions@ 26053c4

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

Added support for MD5 values sets into the book sources.

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