source: common/common-functions@ ae0172b

1.0
Last change on this file since ae0172b was 9357c13, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Ported LUSER code to 1.0 branch.

  • Property mode set to 100644
File size: 27.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}==============================================================================${OFF}"
28declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
29declare -r STAR_BORDER="${BOLD}******************************************************************************${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
42${RED}IMPORTANT:${OFF} Only supported command line switches are listed here.
43 For more fine-grained setups you must edit the relevant
44 configuration files placed under ${BOLD}common/${OFF} and ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])/${OFF}
45
46Options:
47${BOLD} -h, --help${OFF}
48 print this help, then exit
49
50${BOLD} -V, --version${OFF}
51 print version information, then exit
52
53${BOLD} -B, --book VER${OFF}
54 use VER version of the book as the system to build.
55 Supported VER values are:
56 dev*, trunk, SVN = aliases for the Development version of {C,H}LFS
57 branch-NAME = a branch of name NAME
58 VERSION = the version of a stable released book
59 To know what branches and stable books work with this version of jhalfs
60 please see http://wiki.linuxfromscratch.org/alfs/wiki/SupportedBooks
61
62${BOLD} -D --directory DIR${OFF}
63 use DIR directory for building ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF}; all files jhalfs produces
64 will be in the directory DIR/${SCRIPT_ROOT}.
65 The current setting for BUILDDIR is "$BUILDDIR"
66
67${BOLD} -G, --get-packages${OFF}
68 download the packages and patches. This assumes that the server declared
69 in the configuration file has the proper packages and patches for the
70 book version being processed.
71
72${BOLD} -O, --optimize${OFF}
73 Optimize [0-2]
74 0 = no optimization
75 1 = optimize final system only
76 2 = optimize both temporary tools and final system
77 Edit common/opt_config{,.d/*} and common/opt_override as desired.
78
79${BOLD} -T, --testsuites N ${OFF}
80 Run test suites [0-3]
81 0 = none
82 1 = only final system Glibc, GCC and Binutils testsuites
83 2 = all final system testsuites
84 3 = all temporary tools and final system testsuites
85 In CLFS and HLFS, 3 is an alias to 2
86
87${BOLD} -W, --working-copy DIR${OFF}
88 use the local working copy placed in DIR as the $(echo $PROGNAME | tr [a-z] [A-Z]) book
89
90${BOLD} -C, --comparison TYPE${OFF}
91 do iterative comparison analysis. This extends the total build time
92 considerably because the entire final system will rebuild itself
93 the number of times specified by ITERATIONS in common/config.
94 Types allowed are:
95 ICA = do ICA as designed by Greg Schafer
96 farce = do the farce analysis designed by Ken Moffat
97 both = perform both ICA and farce analysis
98
99${BOLD} -F, --fstab FILE${OFF}
100 use FILE as the /etc/fstab file for the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} system. If not specified,
101 a default /etc/fstab file with dummy values is created.
102
103${BOLD} -K, --kernel-config FILE${OFF}
104 use the kernel configuration file specified in FILE to build the kernel.
105 if the file is not found, or if not specified, the kernel build is skipped.
106
107${BOLD} -M, --run-make${OFF}
108 run make on the generated Makefile
109
110${BOLD} -R --rebuild${OFF}
111 clean the build directory before performing any other task. The directory
112 is cleaned only if it was populated by a previous jhalfs run.
113-EOF-
114
115[[ ${PROGNAME} = "clfs" ]] &&
116cat <<- -EOF-
117
118${BOLD} -A, --arch ARCH ${OFF}
119 Select the TARGET architecture, valid selections are:
120 32bit builds
121 x86, i486, i586, ppc, mips, mipsel, sparc
122 64bit builds
123 x86_64-64, mips64-64, mipsel64-64, sparc64-64, alpha
124 64bit multi-lib
125 x86_64, mips64, mipsel64, sparc64, ppc64
126
127${BOLD} --boot-config FILE ${OFF}
128 The configuration file for the bootstrap kernel if method=boot
129
130${BOLD} --method BUILDMETHOD ${OFF}
131 Select the build method, chroot or boot
132-EOF-
133
134[[ ${PROGNAME} = "hlfs" ]] &&
135cat <<- -EOF-
136
137${BOLD} --model STYLE ${OFF}
138 Select the library model for the HLFS system
139 Valid choices are: glibc or uclibc
140-EOF-
141
142cat <<- -EOF-
143${DD_BORDER}
144-EOF-
145 exit
146}
147
148version="
149${BOLD} \"jhalfs\"${OFF} builder tool (branch 1.0.x) \$Rev$
150\$Date$
151
152${BOLD} \"${PROGNAME}\"${OFF} script module
153
154Written by George Boudreau,
155 Manuel Canales Esparcia,
156 Jeremy Huntwork
157
158This program is published under the ${BOLD}Gnu General Public License, Version 2.${OFF}
159"
160
161
162no_empty_builddir() {
163 'clear'
164cat <<- -EOF-
165${DD_BORDER}
166
167${tab_}${tab_}${BOLD}${RED}W A R N I N G${OFF}
168 Looks like the \$BUILDDIR directory contains subdirectories
169 from a previous HLFS build.
170
171 Please format the partition mounted on \$BUILDDIR or set
172 a different build directory before running jhalfs.
173${OFF}
174${DD_BORDER}
175-EOF-
176 exit
177}
178
179
180help="${nl_}Try '$0 --help' for more information."
181
182exit_missing_arg="\
183echo \"Option '\$1' requires an argument\" >&2
184echo \"\$help\" >&2
185exit 1"
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#----------------------------------#
195wrt_target() { # Create target and initialize log file
196#----------------------------------#
197 local i=$1
198 local PREV=$2
199 case $i in
200 iteration* ) local LOGFILE=$this_script.log ;;
201 * ) local LOGFILE=$this_script ;;
202 esac
203(
204cat << EOF
205
206$i: $PREV
207 @\$(call echo_message, Building)
208 @./progress_bar.sh \$@ &
209 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >logs/$LOGFILE
210EOF
211) >> $MKFILE.tmp
212}
213
214
215#----------------------------------#
216wrt_target_boot() { # Create target and initialize log file
217#----------------------------------#
218 local i=$1
219 local PREV=$2
220 case $i in
221 iteration* ) local LOGFILE=$this_script.log ;;
222 * ) local LOGFILE=$this_script ;;
223 esac
224(
225cat << EOF
226
227$i: $PREV
228 @\$(call echo_message, Building)
229 @./progress_bar.sh \$@ &
230 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT}\`\n" >logs/$LOGFILE
231EOF
232) >> $MKFILE.tmp
233}
234
235#----------------------------#
236get_package_tarball_name() { #
237#----------------------------#
238 local script_name=$1
239
240 # The use of 'head' is necessary to limit the return value to the FIRST match..
241 # hopefully this will not cause problems.
242 #
243 case $script_name in
244 tcl) echo $(grep "^tcl" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
245 linux-headers) echo $(grep "^linux-headers.*.bz2" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
246 *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
247 esac
248
249}
250
251#----------------------------------#
252wrt_remove_existing_dirs() { #
253#----------------------------------#
254 local PKG_NAME=$1
255(
256cat << EOF
257 @PKG_PATH=\`ls -t \$(MOUNT_PT)\$(SRC)/${PKG_NAME} | head -n1\` && \\
258 ROOT=\`tar -tf \$\$PKG_PATH | head -n1 | sed -e 's@^./@@;s@/.*@@'\` && \\
259 [[ -n \$\$ROOT ]] && \\
260 rm -rf \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
261 if [ -e \$(MOUNT_PT)\$(SRC)/${PKG_NAME%-*}-build ]; then \\
262 rm -rf \$(MOUNT_PT)\$(SRC)/${PKG_NAME%-*}-build; \\
263 fi;
264EOF
265) >> $MKFILE.tmp
266}
267
268#----------------------------------#
269wrt_remove_existing_dirs2() { #
270#----------------------------------#
271 local PKG_NAME=$1
272(
273cat << EOF
274 @PKG_PATH=\`ls -t \$(SRC)/${PKG_NAME} | head -n1\` && \\
275 ROOT=\`tar -tf \$\$PKG_PATH | head -n1 | sed -e 's@^./@@;s@/.*@@'\` && \\
276 [[ -n \$\$ROOT ]] && \\
277 rm -rf \$(SRC)/\$\$ROOT && \\
278 if [ -e \$(SRC)/${PKG_NAME%-*}-build ]; then \\
279 rm -rf \$(SRC)/${PKG_NAME%-*}-build; \\
280 fi;
281EOF
282) >> $MKFILE.tmp
283}
284
285
286
287#----------------------------------#
288wrt_unpack() { # Unpack and set 'ROOT' var
289#----------------------------------#
290 local FILE=$1
291 local optSAVE_PREVIOUS=$2
292
293 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
294 wrt_remove_existing_dirs "$FILE"
295 fi
296(
297cat << EOF
298 @\$(call unpack,$FILE)
299 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
300 echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
301 chown -R \$(LUSER) \$(MOUNT_PT)\$(SRC)/\$\$ROOT
302EOF
303) >> $MKFILE.tmp
304}
305
306
307#----------------------------------#
308wrt_unpack2() { #
309#----------------------------------#
310 local FILE=$1
311 local optSAVE_PREVIOUS=$2
312
313 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
314 wrt_remove_existing_dirs "$FILE"
315 fi
316(
317cat << EOF
318 @\$(call unpack2,$FILE)
319 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
320 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
321EOF
322) >> $MKFILE.tmp
323}
324
325
326#----------------------------------#
327wrt_unpack3() { #
328#----------------------------------#
329 local FILE=$1
330 local optSAVE_PREVIOUS=$2
331
332 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
333 wrt_remove_existing_dirs2 "$FILE"
334 fi
335(
336cat << EOF
337 @\$(call unpack3,$FILE)
338 @ROOT=\`head -n1 \$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
339 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
340EOF
341) >> $MKFILE.tmp
342}
343
344#----------------------------------#
345wrt_test_log() { # Initialize testsuite log file
346#----------------------------------#
347 local TESTLOGFILE=$1
348(
349cat << EOF
350 @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
351 su - \$(LUSER) -c "echo -e '\n\`date\`\n' >$TESTLOGDIR/$TESTLOGFILE"
352EOF
353) >> $MKFILE.tmp
354}
355
356#----------------------------------#
357wrt_test_log2() { #
358#----------------------------------#
359 local TESTLOGFILE=$1
360(
361cat << EOF
362 @echo "export TEST_LOG=/$SCRIPT_ROOT/test-logs/$TESTLOGFILE" >> envars && \\
363 echo -e "\n\`date\`\n" >test-logs/$TESTLOGFILE
364EOF
365) >> $MKFILE.tmp
366}
367
368#----------------------------------#
369wrt_target_vars() { # Target vars for hlfs (cross-build method)
370#----------------------------------#
371(
372cat << EOF
373 @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
374 echo "export ldso=/lib/${LOADER}" >> envars
375EOF
376) >> $MKFILE.tmp
377
378}
379
380
381#----------------------------------#
382wrt_RunAsUser() { # Execute script inside time { }, footer to log file
383#----------------------------------#
384 local this_script=$1
385 local file=$2
386(
387cat << EOF
388 @( time { su - \$(LUSER) -c "source /home/\$(LUSER)/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
389 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
390EOF
391) >> $MKFILE.tmp
392}
393
394
395#----------------------------------#
396wrt_RunAsRoot() { # Some scripts must be run as root..
397#----------------------------------#
398 local ENV_MOUNT
399 local this_script=$1
400 local file=$2
401
402 case ${PROGNAME} in
403 lfs ) MOUNT_ENV="LFS" ;;
404 blfs ) MOUNT_ENV="BLFS" ;;
405 clfs ) MOUNT_ENV="CLFS" ;;
406 clfs2 ) MOUNT_ENV="CLFS" ;;
407 hlfs ) MOUNT_ENV="HLFS" ;;
408 *) echo "undefined progname $PROGNAME"; exit 1
409 esac
410
411(
412cat << EOF
413 @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
414 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
415EOF
416) >> $MKFILE.tmp
417}
418
419
420#----------------------------------#
421wrt_run_as_root2() { #
422#----------------------------------#
423 local this_script=$1
424 local file=$2
425(
426cat << EOF
427 @( time { source envars && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
428 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \`\n" >>logs/$this_script
429EOF
430) >> $MKFILE.tmp
431}
432
433
434#----------------------------------#
435wrt_run_as_chroot1() { #
436#----------------------------------#
437 local this_script=$1
438 local file=$2
439(
440 cat << EOF
441 @( time { \$(CHROOT1) 'cd /${SCRIPT_ROOT} && source envars && /${SCRIPT_ROOT}/${PROGNAME}-commands/$file >>/${SCRIPT_ROOT}/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
442 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/${this_script}
443EOF
444) >> $MKFILE.tmp
445}
446
447
448#----------------------------------#
449wrt_run_as_chroot2() { #
450#----------------------------------#
451 local this_script=$1
452 local file=$2
453(
454cat << EOF
455 @( time { \$(CHROOT2) 'cd /${SCRIPT_ROOT} && source envars && /${SCRIPT_ROOT}/${PROGNAME}-commands/$file >>/${SCRIPT_ROOT}/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
456 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/${this_script}
457EOF
458) >> $MKFILE.tmp
459}
460
461
462#----------------------------------#
463wrt_copy_fstab() { #
464#----------------------------------#
465 local i=$1
466(
467 cat << EOF
468 @cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1
469EOF
470) >> $MKFILE.tmp
471}
472
473#----------------------------------#
474wrt_copy_fstab2() { #
475#----------------------------------#
476 local i=$1
477(
478 cat << EOF
479 @cp -v /sources/fstab /etc/fstab >>logs/$i 2>&1
480EOF
481) >> $MKFILE.tmp
482}
483
484
485#----------------------------------#
486wrt_remove_build_dirs() { #
487#----------------------------------#
488 local name=$1
489(
490cat << EOF
491 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
492 rm -rf \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
493 if [ -e \$(MOUNT_PT)\$(SRC)/$name-build ]; then \\
494 rm -rf \$(MOUNT_PT)\$(SRC)/$name-build; \\
495 fi;
496EOF
497) >> $MKFILE.tmp
498}
499
500
501#----------------------------------#
502wrt_remove_build_dirs2() { #
503#----------------------------------#
504 local name=$1
505(
506cat << EOF
507 @ROOT=\`head -n1 \$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
508 rm -rf \$(SRC)/\$\$ROOT && \\
509 if [ -e \$(SRC)/$name-build ]; then \\
510 rm -rf \$(SRC)/$name-build; \\
511 fi;
512EOF
513) >> $MKFILE.tmp
514}
515
516
517#----------------------------------#
518wrt_touch() { #
519#----------------------------------#
520(
521cat << EOF
522 @touch \$@ && \\
523 sleep .25 && \\
524 echo -e "\n\n "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
525 echo --------------------------------------------------------------------------------\$(WHITE)
526EOF
527) >> $MKFILE.tmp
528}
529
530
531#----------------------------------#
532wrt_report() { #
533#----------------------------------#
534(
535cat << EOF
536
537create-sbu_du-report: $PREV
538 @\$(call echo_message, Building)
539 @./create-sbu_du-report.sh logs $VERSION
540 @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
541 @touch \$@
542EOF
543) >> $MKFILE.tmp
544
545chapter789="$chapter789 create-sbu_du-report"
546}
547
548
549#----------------------------#
550run_make() { #
551#----------------------------#
552 # Test if make must be run.
553 if [ "$RUNMAKE" = "1" ] ; then
554 # Test to make sure we're running the build as root
555 if [ "$UID" != "0" ] ; then
556 echo "You must be logged in as root to successfully build the system."
557 exit 1
558 fi
559 # Build the system
560 if [ -e $MKFILE ] ; then
561 echo -ne "Building the system...\n"
562 cd $JHALFSDIR && make
563 echo -ne "done\n"
564 fi
565 fi
566}
567
568
569#----------------------------#
570clean_builddir() { #
571#----------------------------#
572 # Test if the clean must be done.
573 if [ "$CLEAN" = "1" ] ; then
574 # Test to make sure we're running the clean as root
575 if [ "$UID" != "0" ] ; then
576 echo "You must be logged in as root to clean the build directory."
577 exit 1
578 fi
579 # Test to make sure that the build directory was populated by jhalfs
580 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
581 echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
582 exit 1
583 else
584 # Clean the build directory
585 echo -ne "Cleaning $BUILDDIR...\n"
586 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
587 echo -ne "Cleaning $JHALFSDIR...\n"
588 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,*logs,Makefile,*.xsl,makefile-functions,pkg_tarball_list,*.config,*.sh}
589 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
590 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
591 echo -ne "done\n"
592 fi
593 fi
594}
595
596#----------------------------#
597get_book() { #
598#----------------------------#
599 cd $JHALFSDIR
600
601 if [ -z $WC ] ; then
602 # Check for Subversion instead of just letting the script hit 'svn' and fail.
603 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
604 exit 1"
605 echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
606
607 case $PROGNAME in
608 lfs) svn_root="LFS" ;;
609 hlfs) svn_root="HLFS" ;;
610 clfs) svn_root="cross-lfs" ;;
611 *) echo "BOOK not defined in function <get_book>"
612 exit 1 ;;
613 esac
614 # Grab a fresh book if it's missing, otherwise, update it from the
615 # repo. If we've already extracted the commands, move on to getting the
616 # sources.
617 if [ -d ${PROGNAME}-$LFSVRS ] ; then
618 cd ${PROGNAME}-$LFSVRS
619 if LC_ALL=C svn up | grep -q At && \
620 test -d $JHALFSDIR/${PROGNAME}-commands && \
621 test -f $JHALFSDIR/pkg_tarball_list ; then
622 # Set the canonical book version
623 echo -ne "done\n"
624 cd $JHALFSDIR
625 case $PROGNAME in
626 clfs)
627 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
628 *)
629 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
630 esac
631 get_sources
632 else
633 echo -ne "done\n"
634 extract_commands
635 fi
636 else
637 svn co $SVN/${svn_root}/${TREE} ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1
638 echo -ne "done\n"
639 extract_commands
640 fi
641
642 else
643 echo -ne "Using $BOOK as book's sources ...\n"
644 extract_commands
645 fi
646 echo -ne " Document version ${L_arrow}${BOLD}${VERSION}${R_arrow}\n"
647}
648
649#----------------------------#
650extract_commands() { #
651#----------------------------#
652
653 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
654 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
655 exit 1"
656
657 cd $JHALFSDIR
658 case $PROGNAME in
659 clfs)
660 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
661 *)
662 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
663 esac
664
665 # Start clean
666 if [ -d ${PROGNAME}-commands ]; then
667 rm -rf ${PROGNAME}-commands
668 mkdir -v ${PROGNAME}-commands
669 fi
670 echo -n "Extracting commands for"
671
672 # Dump the commands in shell script form from the HLFS book.
673 case ${PROGNAME} in
674 clfs)
675 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
676 xsltproc --nonet \
677 --xinclude \
678 --stringparam method $METHOD \
679 --stringparam testsuite $TEST \
680 --stringparam bomb-testsuite $BOMB_TEST \
681 --stringparam vim-lang $VIMLANG \
682 --stringparam timezone $TIMEZONE \
683 --stringparam page $PAGE \
684 --stringparam lang $LANG \
685 --stringparam keymap $KEYMAP \
686 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
687 ;;
688 hlfs)
689 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
690 xsltproc --nonet \
691 --xinclude \
692 --stringparam model $MODEL \
693 --stringparam testsuite $TEST \
694 --stringparam bomb-testsuite $BOMB_TEST \
695 --stringparam timezone $TIMEZONE \
696 --stringparam page $PAGE \
697 --stringparam lang $LANG \
698 --stringparam lc_all $LC_ALL \
699 --stringparam keymap $KEYMAP \
700 --stringparam grsecurity_host $GRSECURITY_HOST \
701 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
702 ;;
703 lfs)
704 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
705 xsltproc --nonet \
706 --xinclude \
707 --stringparam testsuite $TEST \
708 --stringparam bomb-testsuite $BOMB_TEST \
709 --stringparam vim-lang $VIMLANG \
710 --stringparam timezone $TIMEZONE \
711 --stringparam page $PAGE \
712 --stringparam lang $LANG \
713 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
714 ;;
715 *) exit 1 ;;
716 esac
717
718 echo " ...OK"
719
720 # Make the scripts executable.
721 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
722
723 # Create the packages file. We need it for proper Makefile creation
724 create_package_list
725
726 # Done. Moving on...
727 get_sources
728}
729
730#----------------------------#
731create_package_list() { #
732#----------------------------#
733
734 # Create the packages file. We need it for proper Makefile creation
735 rm -f pkg_tarball_list
736 echo -n "Creating <${PROGNAME}> list of tarball names for $BOOK $ARCH"
737 case ${PROGNAME} in
738 clfs)
739 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
740 $BOOK/materials/${ARCH}-chapter.xml >>$LOGDIR/$LOG 2>&1
741 ;;
742 hlfs)
743 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
744 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
745 ;;
746 lfs)
747 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
748 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
749 ;;
750 esac
751 echo " ...OK"
752
753}
754
755
756#----------------------------#
757get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
758#----------------------------#
759 local saveIFS=$IFS
760 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE
761
762 # Test if the packages must be downloaded
763 [ ! "$GETPKG" = "1" ] && return
764
765 gs_wrt_message(){
766 echo "${RED}$1${OFF}"
767 echo "$1" >> MISSING_FILES.DMP
768 }
769 # Housekeeping
770 [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
771 cd $BUILDDIR/sources
772 [[ -f MD5SUMS ]] && rm MD5SUMS
773 [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
774 [[ -f urls.lst ]] && rm urls.lst
775
776 # Generate URLs file
777 create_urls
778
779 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
780 for line in `cat urls.lst`; do
781 IFS=$saveIFS # Restore the system defaults
782
783 # Skip some packages if they aren't needed
784 case $line in
785 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
786 [[ "$TEST" = "0" ]] && continue
787 ;;
788 */vim-*-lang* )
789 [[ "$VIMLANG" = "0" ]] && continue
790 ;;
791 *linux/linux-* )
792 [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
793 [[ "$GETKERNEL" = "0" ]] && continue
794 ;;
795 esac
796
797 # Locations
798 URL1=`echo $line | cut -d" " -f2` # Preferred URL
799 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
800 FILE=`basename $URL1` # File name
801 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
802
803 # Validation pair
804 MD5="$BOOKMD5 $FILE"
805 HAVEMD5=1
806
807 set -e
808 # If the file exists in the archive copy it to the
809 # $BUILDDIR/sources dir. MD5SUM will be validated later.
810 if [ ! -z ${SRC_ARCHIVE} ] &&
811 [ -d ${SRC_ARCHIVE} ] &&
812 [ -f ${SRC_ARCHIVE}/$FILE ]; then
813 cp ${SRC_ARCHIVE}/$FILE .
814 echo "$FILE: -- copied from $SRC_ARCHIVE"
815 fromARCHIVE=1
816 else
817 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
818 fromARCHIVE=0
819 # If the file does not exist yet in /sources download a fresh one
820 if [ ! -f $FILE ] ; then
821 if ! wget $URL1 && ! wget $URL2 ; then
822 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
823 continue
824 fi
825 fi
826 fi
827
828 # IF the md5sum does not match the existing files
829 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
830 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
831 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
832 # Remove the old file and download a new one
833 rm -fv $FILE
834 # Force storage in SRC_ARCHIVE
835 fromARCHIVE=0;
836 # Try to retrieve again the file. Servers in reverse order.
837 if ! wget $URL2 && ! wget $URL1 ; then
838 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
839 continue
840 fi
841 fi
842
843 # Validate the MD5SUM one last time
844 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
845 gs_wrt_message "$FILE does not match MD5SUMS value"
846 # Force generation of MD5SUM
847 HAVEMD5=0
848 fi
849
850 # Generate a fresh MD5SUM for this file
851 if [[ "$HAVEMD5" = "0" ]] ; then
852 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
853 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
854 fi
855
856 # Good or bad we write the original md5sum to a file
857 echo "$MD5" >> MD5SUMS
858
859 # Copy the freshly downloaded file
860 # to the source archive.
861 if [ ! -z ${SRC_ARCHIVE} ] &&
862 [ -d ${SRC_ARCHIVE} ] &&
863 [ -w ${SRC_ARCHIVE} ] &&
864 [ "$fromARCHIVE" = "0" ] ; then
865 echo "Storing file:<$FILE> in the package archive"
866 cp -f $FILE ${SRC_ARCHIVE}
867 fi
868
869 done
870
871 if [[ -s MISSING_FILES.DMP ]]; then
872 echo -e "\n\n${tab_}${RED} One or more files were not retrieved or have bad MD5SUMS.\n${tab_} Check ${L_arrow}$BUILDDIR/sources/MISSING_FILES.DMP${R_arrow} for names ${OFF}\n"
873 # Do not allow the automatic execution of the Makefile.
874 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
875 RUNMAKE=0
876 fi
877}
878
879#----------------------------#
880create_urls() { #
881#----------------------------#
882 cd $JHALFSDIR
883
884 case ${PROGNAME} in
885 clfs)
886 echo -n "Creating CLFS <${ARCH}> specific URLs file"
887 xsltproc --nonet --xinclude \
888 --stringparam server $SERVER \
889 -o $BUILDDIR/sources/urls.lst urls.xsl \
890 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
891 echo " ...OK"
892 ;;
893 hlfs)
894 echo -n "Creating HLFS <${MODEL}> specific URLs file"
895 xsltproc --nonet --xinclude \
896 --stringparam server $SERVER \
897 --stringparam model $MODEL \
898 -o $BUILDDIR/sources/urls.lst urls.xsl \
899 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
900 echo " ...OK"
901 ;;
902 lfs)
903 echo -n "Creating LFS specific URLs file"
904 xsltproc --nonet --xinclude \
905 --stringparam server $SERVER \
906 -o ../sources/urls.lst urls.xsl \
907 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
908 echo " ...OK"
909 ;;
910 esac
911
912 cd $BUILDDIR/sources
913}
Note: See TracBrowser for help on using the repository browser.