source: common/common-functions@ addb529

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

Correct small typo in clfs.xsl

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