source: common/common-functions@ c205656

experimental
Last change on this file since c205656 was 7a100d96, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Merged r2658 from trunk.

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