source: common/common-functions@ 3570c1c

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 3570c1c was 73e5448, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

The tool in trunk is called "jhalfs"

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