source: common/common-functions@ 17c7894

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

POC for optimizations code.

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