source: common/common-functions@ 190d3a2

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

Creating "unpacked" inside souces dir instead /tmp and referencing it via envar.

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