source: common/common-functions@ 1a1f099

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 1a1f099 was 1a1f099, checked in by George Boudreau <georgeb@…>, 18 years ago

jhalfs directory usage has been replaced by

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