source: common/common-functions@ e2b5b99

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

Removed the clear from usage and pipping -h output throught more.

  • Property mode set to 100644
File size: 26.6 KB
Line 
1#!/bin/bash
2
3# $Id$
4
5set +e
6
7# VT100 colors
8declare -r BLACK=$'\e[1;30m'
9declare -r DK_GRAY=$'\e[0;30m'
10
11declare -r RED=$'\e[31m'
12declare -r GREEN=$'\e[32m'
13declare -r YELLOW=$'\e[33m'
14declare -r BLUE=$'\e[34m'
15declare -r MAGENTA=$'\e[35m'
16declare -r CYAN=$'\e[36m'
17declare -r WHITE=$'\e[37m'
18
19declare -r OFF=$'\e[0m'
20declare -r BOLD=$'\e[1m'
21declare -r REVERSE=$'\e[7m'
22declare -r HIDDEN=$'\e[8m'
23
24declare -r tab_=$'\t'
25declare -r nl_=$'\n'
26
27declare -r DD_BORDER="${BOLD}${WHITE}==============================================================================${OFF}"
28declare -r SD_BORDER="${BOLD}${WHITE}------------------------------------------------------------------------------${OFF}"
29declare -r STAR_BORDER="${BOLD}${WHITE}******************************************************************************${OFF}"
30
31# bold yellow > < pair
32declare -r R_arrow=$'\e[1;33m>\e[0m'
33declare -r L_arrow=$'\e[1;33m<\e[0m'
34
35
36usage() {
37cat <<- -EOF-
38${DD_BORDER}
39${BOLD}
40 Usage: $0 ${BOLD}[OPTION]
41
42Options:
43${BOLD} -h, --help${OFF}
44 print this help, then exit
45${BOLD} -V, --version${OFF}
46 print version information, then exit
47${BOLD} -D --directory DIR${OFF}
48 use DIR directory for building ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF}; all files jhalfs produces will be
49 in the directory DIR/jhalfs.
50${BOLD} -R --rebuild${OFF}
51 clean the build directory before to perfom any other task. The directory
52 is cleaned only if it was populated by a previous jhalfs run.
53${BOLD} -G, --get-packages${OFF}
54 download the packages and patches. This assumes that the server declared in the
55 conf file has the proper packages and patches for the book version being processed.
56${BOLD} -T, --testsuites N ${OFF}
57 Run test suites [0-3]
58 0 = none
59 1 = only chapter06 Glibc, GCC and Binutils testsuites
60 2 = all chapter06 testsuites
61 3 = all chapter05 and chapter06 testsuites
62${BOLD} -W, --working-copy DIR${OFF}
63 use the local working copy placed in DIR as the $(echo $PROGNAME | tr [a-z] [A-Z]) book
64${BOLD} -B, --book VER${OFF}
65 checkout VER version of the LFS book. Supported versions at this time are:
66 dev* | trunk | SVN aliases for Development {C,H,B}LFS
67 alpha* aliases for the LFS alphabetical branch
68 udev* aliases for the LFS udev_update branch
69${BOLD} -F, --fstab FILE${OFF}
70 use FILE as the /etc/fstab file for the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} system. If not specified,
71 a default /etc/fstab file with dummy values is created.
72${BOLD} -K, --kernel-config FILE${OFF}
73 use the kernel configuration file specified in FILE to build the kernel.
74 if the file is not found, or if not specified, the kernel build is skipped.
75${BOLD} -M, --run-make${OFF}
76 run make on the generated Makefile
77-EOF-
78
79[[ ${PROGNAME} = "clfs" ]] &&
80cat <<- -EOF-
81
82${BOLD} -A, --arch ARCH ${OFF}
83 Select the TARGET architecture, valid selections are:
84 32bit builds
85 x86, i486, i586, ppc, mips, mipsel, sparc, sparcv8
86 64bit builds
87 x86_64-64, mips64-64, mipsel64-64, sparc64-64, alpha
88 64bit multi-lib
89 x86_64, mips64, mipsel64, sparc64, ppc64
90${BOLD} --method BUILDMETHOD ${OFF}
91 Select the build method, chroot or boot
92${BOLD} --boot_config FILE ${OFF}
93 The configuration file for the bootstrap kernel if method=boot
94-EOF-
95
96[[ ${PROGNAME} = "hlfs" ]] &&
97cat <<- -EOF-
98
99${BOLD} --model STYLE ${OFF}
100 Select the library model for the HLFS system
101 Valid choices are: glibc or uclibc
102-EOF-
103
104[[ ${PROGNAME} = "blfs" ]] &&
105cat <<- -EOF-
106
107${BOLD} --dependencies 0/1/2${OFF}
108 add dependencies of type TYPE to the build tree.
109 If not set, both required and recommended are used.
110
111 Possible values are:
112 0 - required only required dependecies are used
113 1 - recommended both required a recommended dependencies are used
114 2 - optional all dependencies are used
115-EOF-
116
117cat <<- -EOF-
118${DD_BORDER}
119-EOF-
120 exit
121}
122
123version="
124${BOLD} \"jhalfs-X\"${OFF} builder tool (development) \$Rev$
125\$Date$
126
127${BOLD} \"${PROGNAME}\"${OFF} script module
128
129Written by Jeremy Huntwork,
130 Manuel Canales Esparcia,
131 George Boudreau
132
133This program is published under the ${BOLD}Gnu General Public License, Version 2.${OFF}
134"
135
136
137no_empty_builddir() {
138 'clear'
139cat <<- -EOF-
140${DD_BORDER}
141
142${tab_}${tab_}${BOLD}${RED}W A R N I N G${OFF}
143 Looks like the \$BUILDDIR directory contains subdirectories
144 from a previous HLFS build.
145
146 Please format the partition mounted on \$BUILDDIR or set
147 a different build directory before running jhahlfs.
148${OFF}
149${DD_BORDER}
150-EOF-
151 exit
152}
153
154
155help="${nl_}Try '$0 --help' for more information."
156
157
158exit_missing_arg="\
159echo \"Option '\$1' requires an argument\" >&2
160echo \"\$help\" >&2
161exit 1"
162
163no_dl_client="\
164echo \"Could not find a way to download the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} sources.\" >&2
165echo \"Attempting to continue.\" >&2"
166
167HEADER="# This file is automatically generated by jhalfs
168# DO NOT EDIT THIS FILE MANUALLY
169#
170# Generated on `date \"+%F %X %Z\"`"
171
172
173
174
175
176#----------------------------------#
177wrt_target() { #
178#----------------------------------#
179 local i=$1
180 local PREV=$2
181(
182cat << EOF
183
184$i: $PREV
185 @\$(call echo_message, Building)
186EOF
187) >> $MKFILE.tmp
188}
189
190
191#----------------------------------#
192wrt_unpack() { #
193#----------------------------------#
194 local FILE=$1
195(
196cat << EOF
197 @\$(call unpack,$FILE)
198 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
199 echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
200 chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
201EOF
202) >> $MKFILE.tmp
203}
204
205
206#----------------------------------#
207wrt_unpack2() { #
208#----------------------------------#
209 local FILE=$1
210(
211cat << EOF
212 @\$(call unpack2,$FILE)
213 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
214 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
215EOF
216) >> $MKFILE.tmp
217}
218
219
220#=============================#
221wrt_unpack3() { # Unpack and set 'ROOT' var
222#=============================#
223 local FILE=$1
224(
225cat << EOF
226 @\$(call unpack3,$FILE)
227 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
228 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
229EOF
230) >> $MKFILE.tmp
231}
232
233
234
235#----------------------------------#
236wrt_target_vars() { # Target vars for hlfs (cross-build method)
237#----------------------------------#
238(
239cat << EOF
240 @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
241 echo "export ldso=/lib/${LOADER}" >> envars
242EOF
243) >> $MKFILE.tmp
244
245}
246
247
248#----------------------------------#
249wrt_run_as_su() { #
250#----------------------------------#
251 local this_script=$1
252 local file=$2
253(
254cat << EOF
255 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
256 su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 && \\
257 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
258EOF
259) >> $MKFILE.tmp
260}
261
262
263#==================================#
264wrt_run_as_lfs() { # header to log file, execute script, footer to log file
265#==================================#
266 local this_script=$1
267 local file=$2
268(
269cat << EOF
270 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
271 su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 && \\
272 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
273EOF
274) >> $MKFILE.tmp
275}
276
277
278#----------------------------------#
279wrt_run_as_root() { #
280#----------------------------------#
281 local this_script=$1
282 local file=$2
283(
284cat << EOF
285 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
286 export LFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 && \\
287 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
288EOF
289) >> $MKFILE.tmp
290}
291
292
293#=============================#
294wrt_run_as_root2() { # Some scripts must be run as root..
295#=============================#
296 local this_script=$1
297 local file=$2
298(
299cat << EOF
300 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \`\n" >logs/$this_script && \\
301 source envars && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 && \\
302 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \`\n" >>logs/$this_script
303EOF
304) >> $MKFILE.tmp
305}
306
307
308#----------------------------------#
309wrt_remove_build_dirs() { #
310#----------------------------------#
311 local name=$1
312(
313cat << EOF
314 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
315 rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
316 if [ -e \$(MOUNT_PT)\$(SRC)/$name-build ]; then \\
317 rm -r \$(MOUNT_PT)\$(SRC)/$name-build; \\
318 fi;
319EOF
320) >> $MKFILE.tmp
321}
322
323
324#----------------------------------#
325wrt_remove_build_dirs2() { #
326#----------------------------------#
327 local name=$1
328(
329cat << EOF
330 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
331 rm -r \$(SRC)/\$\$ROOT && \\
332 if [ -e \$(SRC)/$name-build ]; then \\
333 rm -r \$(SRC)/$name-build; \\
334 fi;
335EOF
336) >> $MKFILE.tmp
337}
338
339
340
341#----------------------------------#
342wrt_run_as_chroot1() { #
343#----------------------------------#
344 local this_script=$1
345 local file=$2
346(
347 cat << EOF
348 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/${this_script} && \\
349 \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' && \\
350 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/${this_script}
351EOF
352) >> $MKFILE.tmp
353}
354
355
356#----------------------------------#
357wrt_run_as_chroot2() { #
358#----------------------------------#
359 local this_script=$1
360 local file=$2
361(
362cat << EOF
363 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/${this_script} && \\
364 \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' && \\
365 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/${this_script}
366EOF
367) >> $MKFILE.tmp
368}
369
370
371#----------------------------------#
372wrt_copy_fstab() { #
373#----------------------------------#
374 local i=$1
375(
376 cat << EOF
377 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$i && \\
378 cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1 && \\
379 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$i
380EOF
381) >> $MKFILE.tmp
382}
383
384#----------------------------------#
385wrt_copy_fstab2() { #
386#----------------------------------#
387 local i=$1
388(
389 cat << EOF
390 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \`\n" >logs/$i && \\
391 cp -v /sources/fstab /etc/fstab >>logs/$i 2>&1 && \\
392 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \`\n" >>logs/$i
393EOF
394) >> $MKFILE.tmp
395}
396
397
398#----------------------------------#
399wrt_export_pkgdir() { #
400#----------------------------------#
401(
402 cat << EOF
403 @echo "export PKGDIR=\$(SRC)/binutils-build" > envars
404EOF
405) >> $MKFILE.tmp
406}
407
408
409#----------------------------#
410run_make() {
411#----------------------------#
412 # Test if make must be run.
413 if [ "$RUNMAKE" = "1" ] ; then
414 # Test to make sure we're running the build as root
415 if [ "$UID" != "0" ] ; then
416 echo "You must be logged in as root to successfully build LFS."
417 exit 1
418 fi
419 # Build the system
420 if [ -e $MKFILE ] ; then
421 echo -ne "Building the LFS system...\n"
422 cd $JHALFSDIR && make -f ${PROGNAME}-Makefile
423 echo -ne "done\n"
424 fi
425 fi
426}
427
428
429#----------------------------#
430clean_builddir() {
431#----------------------------#
432 # Test if the clean must be done.
433 if [ "$CLEAN" = "1" ] ; then
434 # Test to make sure we're running the clean as root
435 if [ "$UID" != "0" ] ; then
436 echo "You must be logged in as root to clean the build directory."
437 exit 1
438 fi
439 # Test to make sure that the build directory was populated by jhalfs
440 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
441 echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
442 exit 1
443 else
444 # Clean the build directory
445 echo -ne "Cleaning $BUILDDIR...\n"
446 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
447 echo -ne "Cleaning $JHALFSDIR...\n"
448 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
449 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
450 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
451 echo -ne "done\n"
452 fi
453 fi
454}
455
456#----------------------------#
457get_book() {
458#----------------------------#
459 cd $JHALFSDIR
460
461 if [ -z $WC ] ; then
462 # Check for Subversion instead of just letting the script hit 'svn' and fail.
463 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
464 exit 1"
465 echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
466
467 case $PROGNAME in
468 lfs) svn_root="LFS" ;;
469 hlfs) svn_root="HLFS" ;;
470 clfs) svn_root="cross-lfs" ;;
471 blfs) svn_root="BLFS" ;;
472 *) echo "BOOK not defined in function <get_book>"
473 exit 1 ;;
474 esac
475 # Grab a fresh LFS book if it's missing, otherwise, update it from the
476 # repo. If we've already extracted the commands, move on to getting the
477 # sources.
478 if [ -d ${PROGNAME}-$LFSVRS ] ; then
479 cd ${PROGNAME}-$LFSVRS
480 if LC_ALL=C svn up | grep -q At && test -d $JHALFSDIR/commands && \
481 test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
482 echo -ne "done\n"
483 # Set the canonical book version
484 cd $JHALFSDIR
485 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
486 get_sources
487 else
488 echo -ne "done\n"
489 # Set the canonical book version
490 cd $JHALFSDIR
491 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
492 extract_commands
493 fi
494 else
495 case $LFSVRS in
496 development)
497 svn co $SVN/${svn_root}/trunk/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
498 alphabetical)
499 svn co $SVN/${svn_root}/branches/$LFSVRS/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
500 udev_update)
501 svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
502 esac
503 echo -ne "done\n"
504 # Set the canonical book version
505 cd $JHALFSDIR
506 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
507 extract_commands
508 fi
509 else
510 echo -ne "Using $BOOK as book's sources ...\n"
511 # Set the canonical book version
512 cd $JHALFSDIR
513 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
514 extract_commands
515 fi
516}
517
518
519#----------------------------#
520build_patches_file() { # Supply a suitably formated list of patches.
521#----------------------------#
522 local saveIFS=$IFS
523 local IFS
524
525 rm -f patches
526
527 LOC_add_patches_entry() {
528 for f in `grep "/$1-" patcheslist_.wget`; do
529 basename $f | sed "s|${2}|\&${1}-version;|" >> patches
530 done
531 }
532
533 case ${PROGNAME} in
534 hlfs)
535 echo -n "Creating the ${L_arrow}${BOLD}HLFS${R_arrow} specific patcheslist_.wget file"
536 xsltproc --nonet \
537 --xinclude \
538 --stringparam model $MODEL \
539 -o patcheslist_.wget \
540 patcheslist.xsl \
541 $BOOK/chapter04/patches.xml
542 #> /dev/null 2>&1
543
544 # .... U G L Y .... what to do with the grsecurity patch to the kernel..
545 for f in `grep "/grsecurity-" patcheslist_.wget`; do
546 basename $f >> patches
547 done
548 ;;
549
550 clfs) # Pull out a list of arch specific patches
551 echo -n "Creating CLFS ${L_arrow}${BOLD}$ARCH${R_arrow} specific patcheslist_.wget file"
552 xsltproc -xinclude \
553 -o patcheslist_.wget \
554 patcheslist.xsl \
555 $BOOK/materials/${ARCH}-chapter.xml
556 ;;
557 *) return
558 esac
559
560
561 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
562 for f in `cat packages`; do
563 IFS=$saveIFS # Restore the system defaults
564 LOC_add_patches_entry \
565 `echo $f | sed -e 's/-version//' \
566 -e 's/-file.*//' \
567 -e 's/"//g' \
568 -e 's/uclibc/uClibc/'`
569 done
570
571 echo " ...OK"
572}
573
574
575#----------------------------#
576extract_commands() { #
577#----------------------------#
578 local saveIFS=$IFS
579
580 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
581 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
582 exit 1"
583
584 cd $JHALFSDIR
585 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
586
587 # Start clean
588 if [ -d commands ]; then
589 rm -rf commands
590 mkdir -v commands
591 fi
592 echo -n "Extracting commands for"
593
594 # Dump the commands in shell script form from the HLFS book.
595 case ${PROGNAME} in
596 clfs)
597 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
598 xsltproc --nonet \
599 --xinclude \
600 --stringparam method $METHOD \
601 --stringparam testsuite $TEST \
602 --stringparam vim-lang $VIMLANG \
603 --stringparam timezone $TIMEZONE \
604 --stringparam page $PAGE \
605 --stringparam lang $LANG \
606 --stringparam keymap $KEYMAP \
607 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
608 ;;
609 hlfs)
610 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS architecture"
611 xsltproc --nonet \
612 --xinclude \
613 --stringparam model $MODEL \
614 --stringparam testsuite $TEST \
615 --stringparam timezone $TIMEZONE \
616 --stringparam page $PAGE \
617 --stringparam lang $LANG \
618 --stringparam lc_all $LC_ALL \
619 --stringparam keymap $KEYMAP \
620 --stringparam grsecurity_host $GRSECURITY_HOST \
621 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
622 ;;
623 lfs)
624 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
625 xsltproc --nonet \
626 --xinclude \
627 --stringparam testsuite $TEST \
628 --stringparam vim-lang $VIMLANG \
629 --stringparam timezone $TIMEZONE \
630 --stringparam page $PAGE \
631 --stringparam lang $LANG \
632 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
633 ;;
634 blfs)
635 echo -n " ${L_arrow}${BOLD}BLFS${R_arrow} build"
636 xsltproc --nonet \
637 --xinclude \
638 --stringparam testsuite $TEST \
639 --stringparam server $SERVER \
640 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
641 ;;
642 *) exit 1
643 esac
644
645 echo " ...OK"
646
647 # Make the scripts executable.
648 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
649
650 # Grab the patches and package names.
651 for i in patches packages ; do
652 rm -f $i
653 done
654 #
655 case "${PROGNAME}" in
656 clfs)
657 ################################
658 # A LOCAL function
659 # xx_.wget contains arch specific files but in URL format
660 # Build a file with only arch specific files.. small ugly..
661 LOC_add_packages_entry() {
662 local fileMATCH aFILE
663
664 # Deal with a non-standard format
665 if [[ "$1" = "clfs-bootscripts" ]]; then
666 set -- "bootscripts-cross-lfs" $2
667 fi
668 fileMATCH="/$1"
669
670 # format.. Filename-Version or FilenameVersion
671 for aFILE in `grep ${fileMATCH}-*[[:digit:]] packageslist_.wget`; do
672 # Block vim-x.x-lang file, will add it later based on config flag
673 if [[ ! "${aFILE}" =~ "vim-$2-lang" ]]; then
674 echo "$1-version \"$2\"" >> packages
675 fi
676 done
677 }
678 #################################
679
680 # We only want a list arch specific files..
681 # Unfortunately this script produces URL's which must be converted to a std format
682 echo -n "Creating CLFS ${L_arrow}${BOLD}${ARCH}${R_arrow} specific packageslist_.wget file"
683 xsltproc -xinclude \
684 -o packageslist_.wget \
685 packageslist.xsl \
686 $BOOK/materials/${ARCH}-chapter.xml
687
688 # This has the correct format but contains packages from every book
689 grep "\-version " $BOOK/packages.ent | sed -e 's@<!ENTITY @@' \
690 -e 's@">@"@' \
691 -e '/generic/d' > packages.tmp
692 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
693 # separates each iteration by lines.
694 # Modify the 'internal field separator' to break on 'LF' only
695 IFS=$'\x0A'
696 for f in `cat packages.tmp`; do
697 IFS=$saveIFS # Restore the system defaults
698 LOC_add_packages_entry \
699 `echo $f | sed -e 's/-version//' \
700 -e 's/-file.*//' \
701 -e 's/"//g'`
702 done
703 echo " ...OK"
704 ;;
705
706 hlfs)
707 echo -n "Creating <${PROGNAME}> specific packageslist_.wget file"
708 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
709 -e 's@">@"@' \
710 -e '/generic/d' >> packages
711 echo " ...OK"
712 ;;
713
714 lfs)
715 echo -n "Creating <${PROGNAME}> specific packageslist_.wget file"
716 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' \
717 -e 's@">@"@' \
718 -e '/generic/d' >> packages
719 echo `grep "glibc" packages | sed 's@glibc@glibc-libidn@'` >> packages
720 echo `grep "udev-config-file" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@'` >> packages
721 echo " ...OK"
722 ;;
723 esac
724
725 # Download the vim-lang package if it must be installed
726 if [ "$VIMLANG" = "1" ] && [ ! "$PROGNAME" = "hlfs" ] ; then
727 echo `grep "vim" packages | sed 's@vim@&-lang@'` >> packages
728 fi
729
730 # There is no useful patches.ent file so we will create one.
731 case "${PROGNAME}" in
732 hlfs)
733 build_patches_file ;;
734 clfs )
735 build_patches_file ;;
736 lfs)
737 grep "^<\!ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
738 ;;
739 blfs) ;;
740 *) exit 1
741 esac
742
743 # Done. Moving on...
744 get_sources
745}
746
747
748#----------------------------#
749download() { # Download file, write name to MISSING_FILES.DMP if an error
750#----------------------------#
751 cd $BUILDDIR/sources
752
753 # Hackish fix for the bash-doc, glibc-{linuxthreads,libidn}
754 # that don't conform to norms in the URL scheme.
755 DIR=`echo $1 | sed 's@-doc@@;s@-linuxthreads@@;s@-libidn@@;s@-testsuite@@'`
756
757 # If the file exists in the archive copy it to the $BUILDDIR/sources dir
758 # MD5SUM is assumed to be correct from previous download
759 if [ ! -z ${SRC_ARCHIVE} ] &&
760 [ -d ${SRC_ARCHIVE} ] &&
761 [ -f ${SRC_ARCHIVE}/$2 ]; then
762 cp ${SRC_ARCHIVE}/$2 .
763 echo "$2: -- ok"
764 return
765 fi
766
767 # Find the md5 sum for this package.
768 if [ $2 != MD5SUMS ] ; then
769 set +e
770 MD5=`grep " $2" MD5SUMS`
771 if [ $? -ne 0 ]; then
772 set -e
773 echo "${RED}$2 not found in MD5SUMS${OFF}"
774 echo "$2 not found in MD5SUMS" >> MISSING_FILES.DMP
775 return
776 fi
777 set -e
778 fi
779
780 if [ ! -f $2 ] ; then
781 case $DL in
782 wgetFTP ) wget --passive $FTP/$DIR/$2 ;;
783 wget ) wget $HTTP/$DIR/$2 ;;
784 curl ) `curl -# $FTP/$DIR/$2 -o $2` ;;
785 * ) echo "$DL not supported at this time." ;;
786 esac
787 elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
788 case $DL in
789 wgetFTP ) wget --passive -c $FTP/$DIR/$2 ;;
790 wget ) wget -c $HTTP/$DIR/$2 ;;
791 curl ) `curl -# -C - $FTP/$DIR/$2 -o $2` ;;
792 * ) echo "$DL not supported at this time." ;;
793 esac
794 fi
795
796 if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
797 exit 1
798 fi
799 if [ $2 != MD5SUMS ] ; then
800 echo `grep "$MD5" MD5SUMS` >> MD5SUMS-$VERSION
801 fi
802
803 # If we make it this far we should copy the freshly downloaded file
804 # to the source archive.
805 if [ ! -z ${SRC_ARCHIVE} ] &&
806 [ -d ${SRC_ARCHIVE} ] &&
807 [ -w ${SRC_ARCHIVE} ] &&
808 [ $2 != MD5SUMS ]; then
809 echo "Store file:<$2> in package archive"
810 cp -v $2 ${SRC_ARCHIVE}
811 fi
812
813}
814
815
816#----------------------------#
817get_sources() {
818#----------------------------#
819
820 # Test if the packages must be downloaded
821 if [ "$HPKG" = "1" ] ; then
822
823 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
824 # separates each iteration by lines.
825 # Modify the 'internal field separator' to break on 'LF' only
826 IFS=$'\x0A'
827
828 if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
829 cd $BUILDDIR/sources
830 if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
831 if [ -f MD5SUMS-$VERSION ] ; then rm MD5SUMS-$VERSION ; fi
832 if [ -f MISSING_FILES.DMP ] ; then rm MISSING_FILES.DMP ; fi
833
834 download "" MD5SUMS
835
836 # Iterate through each package and grab it, along with any patches it needs.
837 for i in `cat $JHALFSDIR/packages` ; do
838 PKG=`echo $i | sed -e 's/-version.*//' -e 's/-file.*//'`
839
840 # There are some entities that aren't valid packages.
841 if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
842
843 VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
844 case $PKG in
845 tcl) FILE="$PKG$VRS-src.tar.bz2" ;;
846 vim-lang) PKG="vim"
847 FILE="vim-$VRS-lang.tar.bz2" ;;
848 udev-config) PKG="udev"
849 FILE="$VRS" ;;
850 *) FILE="$PKG-$VRS.tar.bz2" ;;
851 esac
852 download $PKG $FILE
853
854 # Download any associated patches
855 for patch in `grep "&$PKG-version" $JHALFSDIR/patches` ; do
856 PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
857 download $PKG $PATCH
858 done
859 done
860 if [[ -s $BUILDDIR/sources/MISSING_FILES.DMP ]]; then
861 echo -e "\n\n${tab_}${RED} One or more files were not retrieved.\n${tab_} Check ${L_arrow}$BUILDDIR/sources/MISSING_FILES.DMP${R_arrow} for names ${OFF}\n\n"
862 fi
863 fi
864}
865
866#-----------------------------------------------#
867_IS_() # Function to test build scripts names
868#-----------------------------------------------#
869{
870 # Returns substr $2 or null str
871 # Must use string testing
872 case $1 in
873 *$2*) echo "$2" ;;
874 *) echo "" ;;
875 esac
876}
Note: See TracBrowser for help on using the repository browser.