source: common/common-functions@ e35e794

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

Merged r2750 from trunk.

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