source: common/common-functions@ b90e260

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

more Text changes only

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