source: common/common-functions@ 22670f4

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

Added base files from George's jhalfs-experimental-2 POC.
WARNING: This code is broken due files renaming.

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