source: common/common-functions@ 6b1576a

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

common/common-functions, _IS_ is history

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