source: common/common-functions@ d20c553

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

Merged r2633:2639 from trunk.

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