source: common/common-functions@ bef0a98

experimental
Last change on this file since bef0a98 was bef0a98, checked in by George Boudreau <georgeb@…>, 19 years ago

Housekeeping for HLFS.. changes to common/common_funtions to get HLFS running

  • Property mode set to 100644
File size: 22.9 KB
Line 
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 chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT
221EOF
222) >> $MKFILE.tmp
223}
224
225
226#=============================#
227wrt_unpack3() { # Unpack and set 'ROOT' var
228#=============================#
229 local FILE=$1
230(
231cat << EOF
232 @\$(call unpack3,$FILE)
233 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
234 echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
235
236 chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT
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
256#=============================#
257wrt_unpack4() { # Unpack and set 'ROOT' var
258#=============================#
259 local FILE=$1
260(
261cat << EOF
262 @\$(call unpack4,$FILE)
263 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
264 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
265EOF
266) >> $MKFILE.tmp
267}
268
269
270
271#----------------------------------#
272wrt_target_vars() { # Target vars for hlfs (cross-build method)
273#----------------------------------#
274(
275cat << EOF
276 echo "export target=$(uname -m)-${TARGET}" >> envars && \\
277 echo "export ldso=/lib/${LOADER}" >> envars
278EOF
279) >> $MKFILE.tmp
280
281}
282
283
284#----------------------------------#
285wrt_run_as_su() { #
286#----------------------------------#
287 local this_script=$1
288 local file=$2
289(
290cat << EOF
291 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
292 su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 && \\
293 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
294EOF
295) >> $MKFILE.tmp
296}
297
298
299#==================================#
300wrt_run_as_lfs() { # header to log file, execute script, footer to log file
301#==================================#
302 local this_script=$1
303 local file=$2
304(
305cat << EOF
306 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
307 su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 && \\
308 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
309EOF
310) >> $MKFILE.tmp
311}
312
313
314#----------------------------------#
315wrt_run_as_root() { #
316#----------------------------------#
317 local this_script=$1
318 local file=$2
319(
320cat << EOF
321 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$this_script && \\
322 export LFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 && \\
323 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$this_script
324EOF
325) >> $MKFILE.tmp
326}
327
328
329#=============================#
330wrt_run_as_root2() { # Some scripts must be run as root..
331#=============================#
332 local this_script=$1
333 local file=$2
334(
335cat << EOF
336 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \`\n" >logs/$this_script && \\
337 source envars && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 && \\
338 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \`\n" >>logs/$this_script
339EOF
340) >> $MKFILE.tmp
341}
342
343
344#----------------------------------#
345wrt_remove_build_dirs() { #
346#----------------------------------#
347 local name=$1
348(
349cat << EOF
350 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
351 rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
352 if [ -e \$(MOUNT_PT)\$(SRC)/$name-build ]; then \\
353 rm -r \$(MOUNT_PT)\$(SRC)/$name-build; \\
354 fi;
355EOF
356) >> $MKFILE.tmp
357}
358
359
360#----------------------------------#
361wrt_remove_build_dirs2() { #
362#----------------------------------#
363 local name=$1
364(
365cat << EOF
366 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
367 rm -r \$(SRC)/\$\$ROOT && \\
368 if [ -e \$(SRC)/$name-build ]; then \\
369 rm -r \$(SRC)/$name-build; \\
370 fi;
371EOF
372) >> $MKFILE.tmp
373}
374
375
376
377#----------------------------------#
378wrt_run_as_chroot1() { #
379#----------------------------------#
380 local this_script=$1
381 local file=$2
382(
383 cat << EOF
384 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/${this_script} && \\
385 \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' && \\
386 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/${this_script}
387EOF
388) >> $MKFILE.tmp
389}
390
391
392#----------------------------------#
393wrt_run_as_chroot2() { #
394#----------------------------------#
395 local this_script=$1
396 local file=$2
397(
398cat << EOF
399 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/${this_script} && \\
400 \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/${PROGNAME}-commands/$file >>/jhalfs/logs/${this_script} 2>&1' && \\
401 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/${this_script}
402EOF
403) >> $MKFILE.tmp
404}
405
406
407#----------------------------------#
408wrt_copy_fstab() { #
409#----------------------------------#
410 local i=$1
411(
412 cat << EOF
413 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >logs/$i && \\
414 cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1 && \\
415 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(MOUNT_PT)\`\n" >>logs/$i
416EOF
417) >> $MKFILE.tmp
418}
419
420#----------------------------------#
421wrt_copy_fstab2() { #
422#----------------------------------#
423 local i=$1
424(
425 cat << EOF
426 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \`\n" >logs/$i && \\
427 cp -v $FSTAB /etc/fstab >>logs/$i 2>&1 && \\
428 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \`\n" >>logs/$i
429EOF
430) >> $MKFILE.tmp
431}
432
433
434#----------------------------------#
435wrt_export_timezone() { #
436#----------------------------------#
437 echo -e '\t@echo "export TIMEZONE=$(TIMEZONE)" >> envars' >> $MKFILE.tmp
438}
439
440
441#----------------------------------#
442wrt_export_pagesize() { #
443#----------------------------------#
444 echo -e '\t@echo "export PAGE=$(PAGE)" >> envars' >> $MKFILE.tmp
445}
446
447
448#----------------------------------#
449wrt_export_pkgdir() { #
450#----------------------------------#
451(
452 cat << EOF
453 @echo "export PKGDIR=\$(SRC)/binutils-build" > envars
454EOF
455) >> $MKFILE.tmp
456}
457
458
459#----------------------------#
460run_make() {
461#----------------------------#
462 # Test if make must be run.
463 if [ "$RUNMAKE" = "1" ] ; then
464 # Test to make sure we're running the build as root
465 if [ "$UID" != "0" ] ; then
466 echo "You must be logged in as root to successfully build LFS."
467 exit 1
468 fi
469 # Build the system
470 if [ -e $MKFILE ] ; then
471 echo -ne "Building the LFS system...\n"
472 cd $JHALFSDIR && make -f ${PROGNAME}-Makefile
473 echo -ne "done\n"
474 fi
475 fi
476}
477
478
479#----------------------------#
480clean_builddir() {
481#----------------------------#
482 # Test if the clean must be done.
483 if [ "$CLEAN" = "1" ] ; then
484 # Test to make sure we're running the clean as root
485 if [ "$UID" != "0" ] ; then
486 echo "You must be logged in as root to clean the build directory."
487 exit 1
488 fi
489 # Test to make sure that the build directory was populated by jhalfs
490 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
491 echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
492 exit 1
493 else
494 # Clean the build directory
495 echo -ne "Cleaning $BUILDDIR...\n"
496 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,usr,var}
497 echo -ne "Cleaning $JHALFSDIR...\n"
498 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,commands,logs,Makefile,dump-lfs-scripts.xsl,functions,packages,patches}
499 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
500 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
501 echo -ne "done\n"
502 fi
503 fi
504}
505
506#----------------------------#
507get_book() {
508#----------------------------#
509 cd $JHALFSDIR
510
511 if [ -z $WC ] ; then
512 # Check for Subversion instead of just letting the script hit 'svn' and fail.
513 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
514 exit 1"
515 echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
516
517 case $PROGNAME in
518 lfs) svn_root="LFS" ;;
519 hlfs) svn_root="HLFS" ;;
520 clfs) svn_root="cross-lfs" ;;
521 blfs) svn_root="BLFS" ;;
522 *) echo "BOOK not defined in function <get_book>"
523 exit 1 ;;
524 esac
525 # Grab a fresh LFS book if it's missing, otherwise, update it from the
526 # repo. If we've already extracted the commands, move on to getting the
527 # sources.
528 if [ -d ${PROGNAME}-$LFSVRS ] ; then
529 cd ${PROGNAME}-$LFSVRS
530 if LC_ALL=C svn up | grep -q At && test -d $JHALFSDIR/commands && \
531 test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
532 echo -ne "done\n"
533 # Set the canonical book version
534 cd $JHALFSDIR
535 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
536 get_sources
537 else
538 echo -ne "done\n"
539 # Set the canonical book version
540 cd $JHALFSDIR
541 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
542 extract_commands
543 fi
544 else
545 case $LFSVRS in
546 development)
547 svn co $SVN/${svn_root}/trunk/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
548 alphabetical)
549 svn co $SVN/${svn_root}/branches/$LFSVRS/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
550 esac
551 echo -ne "done\n"
552 # Set the canonical book version
553 cd $JHALFSDIR
554 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
555 extract_commands
556 fi
557 else
558 echo -ne "Using $BOOK as book's sources ...\n"
559 # Set the canonical book version
560 cd $JHALFSDIR
561 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
562 extract_commands
563 fi
564}
565
566
567#----------------------------#
568build_patches_file() { # Supply a suitably formated list of patches.
569#----------------------------#
570 local IFS
571 echo -ne "Creating the patch file list "
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 patcheslist.xsl \
583 $BOOK/index.xml
584 #> /dev/null 2>&1
585
586 rm -f patches
587
588 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
589 for f in `cat packages`; do
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 rm -f patcheslist_.wget
603 echo "...OK"
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 for"
624
625 # Dump the commands in shell script form from the HLFS book.
626 case ${PROGNAME} in
627 clfs)
628 echo -n "${tab_} ${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 -n "${tab_} ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS architecture"
636 xsltproc --nonet \
637 --xinclude \
638 --stringparam model $MODEL \
639 --stringparam testsuite $TEST \
640 --stringparam testchaintest 0 \
641 --stringparam vim-lang $VIMLANG \
642 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
643 ;;
644 lfs)
645 echo -n "${tab_} ${L_arrow}${BOLD}LFS${R_arrow} build"
646 xsltproc --nonet \
647 --xinclude \
648 --stringparam testsuite $TEST \
649 --stringparam vim-lang $VIMLANG \
650 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
651 ;;
652 blfs)
653 echo -n "${tab_} ${L_arrow}${BOLD}BLFS${R_arrow} build"
654 xsltproc --nonet \
655 --xinclude \
656 --stringparam testsuite $TEST \
657 --stringparam server $SERVER \
658 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
659 ;;
660 *) exit 1
661 esac
662
663 echo " ...OK"
664
665 # Make the scripts executable.
666 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
667
668 # Grab the patches and package names.
669 cd $JHALFSDIR
670 for i in patches packages ; do rm -f $i ; done
671 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
672 -e '/generic/d' >> packages
673
674 # Download the vim-lang package if it must be installed
675 if [ "$VIMLANG" = "1" ] ; then
676 echo `grep "vim" packages | sed 's@vim@&-lang@'` >> packages
677 fi
678 echo `grep "udev-config-file" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@'` >> packages
679
680 # There is no HLFS patches.ent file so we will create one.
681
682 case "${PROGNAME}" in
683 hlfs) build_patches_file ;;
684 clfs) ;;
685 lfs) ;;
686 blfs) ;;
687 *) exit 1
688 esac
689
690 # Done. Moving on...
691 get_sources
692}
693
694
695#----------------------------#
696download() { # Download file, write name to MISSING_FILES.DMP if an error
697#----------------------------#
698 cd $BUILDDIR/sources
699
700 # Hackish fix for the bash-doc, glibc-{linuxthreads,libidn}
701 # that don't conform to norms in the URL scheme.
702 DIR=`echo $1 | sed 's@-doc@@;s@-linuxthreads@@;s@-libidn@@;s@-testsuite@@'`
703
704 # Find the md5 sum for this package.
705 if [ $2 != MD5SUMS ] ; then
706 set +e
707 MD5=`grep " $2" MD5SUMS`
708 if [ $? -ne 0 ]; then
709 set -e
710 echo "${RED}$2 not found in MD5SUMS${OFF}"
711 echo "$2 not found in MD5SUMS" >> MISSING_FILES.DMP
712 return
713 fi
714 set -e
715 fi
716
717 if [ ! -f $2 ] ; then
718 case $DL in
719 wget ) wget --passive $FTP/$DIR/$2 ;;
720 curl ) `curl -# $FTP/$DIR/$2 -o $2` ;;
721 * ) echo "$DL not supported at this time." ;;
722 esac
723 elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
724 case $DL in
725 wget ) wget --passive -c $FTP/$DIR/$2 ;;
726 curl ) `curl -# -C - $FTP/$DIR/$2 -o $2` ;;
727 * ) echo "$DL not supported at this time." ;;
728 esac
729 fi
730
731 if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
732 exit 1
733 fi
734 if [ $2 != MD5SUMS ] ; then
735 echo `grep "$MD5" MD5SUMS` >> MD5SUMS-$VERSION
736 fi
737}
738
739
740#----------------------------#
741get_sources() {
742#----------------------------#
743
744 # Test if the packages must be downloaded
745 if [ "$HPKG" = "1" ] ; then
746
747 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
748 # separates each iteration by lines. It is necessary to have the second
749 # ' on the next line.
750 IFS='
751'
752
753 if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
754 cd $BUILDDIR/sources
755 if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
756 if [ -f MD5SUMS-$VERSION ] ; then rm MD5SUMS-$VERSION ; fi
757
758 download "" MD5SUMS
759
760 # Iterate through each package and grab it, along with any patches it needs.
761 for i in `cat $JHALFSDIR/packages` ; do
762 PKG=`echo $i | sed -e 's/-version.*//' -e 's/-file.*//'`
763
764 # There are some entities that aren't valid packages.
765 if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
766
767 VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
768 case $PKG in
769 tcl) FILE="$PKG$VRS-src.tar.bz2" ;;
770 vim-lang) PKG="vim"
771 FILE="vim-$VRS-lang.tar.bz2" ;;
772 udev-config) PKG="udev"
773 FILE="$VRS" ;;
774 *) FILE="$PKG-$VRS.tar.bz2" ;;
775 esac
776 download $PKG $FILE
777
778 # Download any associated patches
779 for patch in `grep "&$PKG-version" $JHALFSDIR/patches` ; do
780 PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
781 download $PKG $PATCH
782 done
783 done
784 fi
785}
786
787#-----------------------------------------------#
788_IS_() # Function to test build scripts names
789#-----------------------------------------------#
790{
791 # Returns substr $2 or null str
792 # Must use string testing
793 case $1 in
794 *$2*) echo "$2" ;;
795 *) echo "" ;;
796 esac
797}
Note: See TracBrowser for help on using the repository browser.