source: common/common-functions@ 0306777

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 0306777 was 401f81e, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Ported Makefile clean-up and 0/1 to n/y migration code from experimental.
There is no obvious bugs, let users to find hidden bugs.

  • Property mode set to 100644
File size: 27.1 KB
RevLine 
[877cc6a]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
[47e524f]27declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
28declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
29declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
[877cc6a]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
[efc0d1e]42${RED}IMPORTANT:${OFF} Only supported command line switches are listed here.
[4dd25a1]43 For more fine-grained setups you must edit the relevant
[efc0d1e]44 configuration files placed under ${BOLD}common/${OFF} and ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])/${OFF}
45
[877cc6a]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}
[e2fa2bd]54 use VER version of the book as the system to build.
[a6655ff]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
[d385453]59 To know what branches and stable books work with this version of jhalfs
[a6655ff]60 please see http://wiki.linuxfromscratch.org/alfs/wiki/SupportedBooks
[877cc6a]61
62${BOLD} -D --directory DIR${OFF}
[73e5448]63 use DIR directory for building ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF}; all files jhalfs produces
[1a1f099]64 will be in the directory DIR/${SCRIPT_ROOT}.
[511923a]65 The current setting for BUILDDIR is "$BUILDDIR"
[877cc6a]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
[1b65a84]72${BOLD} -O, --optimize${OFF}
73 Optimize [0-2]
74 0 = no optimization
[1ec8fce]75 1 = optimize final system only
76 2 = optimize both temporary tools and final system
[1b65a84]77 Edit common/opt_config{,.d/*} and common/opt_override as desired.
78
[877cc6a]79${BOLD} -T, --testsuites N ${OFF}
80 Run test suites [0-3]
81 0 = none
[0755d1a]82 1 = only final system Glibc, GCC and Binutils testsuites
83 2 = all final system testsuites
[b240ee6]84 3 = all temporary tools and final system testsuites
[d81c640]85 In CLFS and HLFS, 3 is an alias to 2
[877cc6a]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
[d385453]90${BOLD} -C, --comparison TYPE${OFF}
[e2fa2bd]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.
[6dcfd53]94 Types allowed are:
[e2fa2bd]95 ICA = do ICA as designed by Greg Schafer
[0ad851d]96 farce = do the farce analysis designed by Ken Moffat
[d385453]97 both = perform both ICA and farce analysis
[45f82718]98
[877cc6a]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}
[d385453]111 clean the build directory before performing any other task. The directory
[73e5448]112 is cleaned only if it was populated by a previous jhalfs run.
[877cc6a]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
[b0dd4bd]121 x86, i486, i586, ppc, mips, mipsel, sparc
[877cc6a]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
[c7c5a53]127${BOLD} --boot-config FILE ${OFF}
[877cc6a]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
[7432834]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
[877cc6a]146[[ ${PROGNAME} = "hlfs" ]] &&
147cat <<- -EOF-
148
149${BOLD} --model STYLE ${OFF}
150 Select the library model for the HLFS system
151 Valid choices are: glibc or uclibc
152-EOF-
153
154cat <<- -EOF-
155${DD_BORDER}
156-EOF-
157 exit
158}
159
160version="
[73e5448]161${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
[877cc6a]162\$Date$
163
164${BOLD} \"${PROGNAME}\"${OFF} script module
165
166Written by George Boudreau,
167 Manuel Canales Esparcia,
168 Jeremy Huntwork
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
[73e5448]184 a different build directory before running jhalfs.
[877cc6a]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
[73e5448]199HEADER="# This file is automatically generated by jhalfs
[877cc6a]200# DO NOT EDIT THIS FILE MANUALLY
201#
202# Generated on `date \"+%F %X %Z\"`"
203
204
205
206#----------------------------------#
[3a321ea]207wrt_target() { # Create target and initialize log file
[877cc6a]208#----------------------------------#
209 local i=$1
210 local PREV=$2
[4edf3b7]211 case $i in
212 iteration* ) local LOGFILE=$this_script.log ;;
213 * ) local LOGFILE=$this_script ;;
214 esac
[877cc6a]215(
216cat << EOF
217
218$i: $PREV
219 @\$(call echo_message, Building)
[46758a2]220 @./progress_bar.sh \$@ &
[1a1f099]221 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >logs/$LOGFILE
[877cc6a]222EOF
223) >> $MKFILE.tmp
224}
225
[7eb9402]226
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
[dd29d02]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
[6ad5a2f]256 tcl) echo $(grep "^tcl" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
[983db9f]257 linux-headers) echo $(grep "^linux-headers.*.bz2" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
[6ad5a2f]258 *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
[dd29d02]259 esac
260
261}
[877cc6a]262
[401f81e]263
[5842156]264#----------------------------------#
[401f81e]265wrt_test_log() { # Initialize testsuite log file
[5842156]266#----------------------------------#
[401f81e]267 local TESTLOGFILE=$1
[5842156]268(
[401f81e]269cat << EOF
270 @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
271 su - \$(LUSER) -c "echo -e '\n\`date\`\n' >$TESTLOGDIR/$TESTLOGFILE"
[5842156]272EOF
273) >> $MKFILE.tmp
274}
275
276#----------------------------------#
[401f81e]277wrt_test_log2() { #
[5842156]278#----------------------------------#
[401f81e]279 local TESTLOGFILE=$1
[5842156]280(
[401f81e]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
[5842156]320EOF
321) >> $MKFILE.tmp
322}
323
324
[401f81e]325#----------------------------------#
326wrt_report() { #
327#----------------------------------#
328(
329cat << EOF
[5842156]330
[401f81e]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
[877cc6a]343#----------------------------------#
344wrt_unpack() { # Unpack and set 'ROOT' var
345#----------------------------------#
346 local FILE=$1
[5842156]347 local optSAVE_PREVIOUS=$2
[82eb8c1]348
[401f81e]349 if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
350(
351cat << EOF
352 @\$(call remove_existing_dirs,$FILE)
353EOF
354) >> $MKFILE.tmp
[5842156]355 fi
[401f81e]356
[877cc6a]357(
358cat << EOF
359 @\$(call unpack,$FILE)
[401f81e]360 @\$(call get_pkg_root)
[e5f5970]361EOF
362) >> $MKFILE.tmp
363
[401f81e]364}
[e5f5970]365
[401f81e]366unset wrt_unpack2
[877cc6a]367#----------------------------------#
368wrt_unpack2() { #
369#----------------------------------#
370 local FILE=$1
[5842156]371 local optSAVE_PREVIOUS=$2
372
373 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
[401f81e]374(
375cat << EOF
376 @\$(call remove_existing_dirs,$FILE)
377EOF
378) >> $MKFILE.tmp
[5842156]379 fi
[877cc6a]380(
381cat << EOF
382 @\$(call unpack2,$FILE)
[401f81e]383 @\$(call get_pkg_root,nouser)
[877cc6a]384EOF
385) >> $MKFILE.tmp
386}
387
[261eea6]388#----------------------------------#
389wrt_unpack3() { #
390#----------------------------------#
[877cc6a]391 local FILE=$1
[5842156]392 local optSAVE_PREVIOUS=$2
393
394 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
[401f81e]395(
396cat << EOF
397 @\$(call remove_existing_dirs2,$FILE)
398EOF
399) >> $MKFILE.tmp
[5842156]400 fi
[877cc6a]401(
402cat << EOF
403 @\$(call unpack3,$FILE)
[401f81e]404 @\$(call get_pkg_root2)
[877cc6a]405EOF
406) >> $MKFILE.tmp
407}
408
[401f81e]409
410unset wrt_remove_build_dirs
[a229600]411#----------------------------------#
[401f81e]412wrt_remove_build_dirs() { #
[a229600]413#----------------------------------#
[401f81e]414 local name=$1
[a229600]415(
[401f81e]416cat << EOF
417 @\$(call remove_build_dirs,$name)
[a229600]418EOF
419) >> $MKFILE.tmp
420}
421
422#----------------------------------#
[401f81e]423wrt_remove_build_dirs2() { #
[a229600]424#----------------------------------#
[401f81e]425 local name=$1
[a229600]426(
[401f81e]427cat << EOF
428 @\$(call remove_build_dirs2,$name)
[a229600]429EOF
430) >> $MKFILE.tmp
431}
432
[401f81e]433
434
435unset wrt_touch
[877cc6a]436#----------------------------------#
[401f81e]437wrt_touch() { #
[877cc6a]438#----------------------------------#
439(
[401f81e]440cat << EOF
441 @\$(call housekeeping)
[877cc6a]442EOF
443) >> $MKFILE.tmp
444}
445
[401f81e]446unset wrt_RunAsUser
[877cc6a]447#----------------------------------#
[6ad5a2f]448wrt_RunAsUser() { # Execute script inside time { }, footer to log file
[877cc6a]449#----------------------------------#
450 local this_script=$1
451 local file=$2
[401f81e]452
[877cc6a]453(
454cat << EOF
[401f81e]455 @( time { \$(SU_LUSER) "source \$(LUSER_HOME)/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@" >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\
456 \$(PRT_DU) >> logs/\$@
[877cc6a]457EOF
458) >> $MKFILE.tmp
459}
460
461
[e5f5970]462#----------------------------------#
[6ad5a2f]463wrt_RunAsRoot() { # Some scripts must be run as root..
[e5f5970]464#----------------------------------#
[6ad5a2f]465 local ENV_MOUNT
[e5f5970]466 local this_script=$1
467 local file=$2
468
[6ad5a2f]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
[e5f5970]477
[ac1d897]478(
479cat << EOF
[401f81e]480 @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
481 \$(PRT_DU_CR) >>logs/\$@
[ac1d897]482EOF
483) >> $MKFILE.tmp
484}
485
[261eea6]486#----------------------------------#
487wrt_run_as_root2() { #
488#----------------------------------#
[877cc6a]489 local this_script=$1
490 local file=$2
491(
492cat << EOF
[401f81e]493 @( time { source envars && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
494 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \`\n" >>logs/\$@
[877cc6a]495EOF
496) >> $MKFILE.tmp
497}
498
499
[401f81e]500unset wrt_run_as_chroot1
[877cc6a]501#----------------------------------#
502wrt_run_as_chroot1() { #
503#----------------------------------#
504 local this_script=$1
505 local file=$2
506(
[401f81e]507cat << EOF
508 @( time { \$(CHROOT1) 'cd \$(SCRIPT_ROOT) && source envars && \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@ 2>&1' ; } ) 2>>logs/\$@ && \\
509 \$(PRT_DU_CR) >> logs/\$@
[877cc6a]510EOF
511) >> $MKFILE.tmp
512}
513
[401f81e]514unset wrt_run_as_chroot2
[877cc6a]515#----------------------------------#
516wrt_run_as_chroot2() { #
517#----------------------------------#
518 local this_script=$1
519 local file=$2
520(
521cat << EOF
[401f81e]522 @( time { \$(CHROOT2) 'cd \$(SCRIPT_ROOT) && source envars && \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\@ 2>&1' ; } ) 2>>logs/\@ && \\
523 \$(PRT_DU_CR) >> logs/\$@
[877cc6a]524EOF
525) >> $MKFILE.tmp
526}
527
[401f81e]528unset wrt_target
[877cc6a]529#----------------------------------#
[401f81e]530wrt_target() { # Create target and initialize log file
[877cc6a]531#----------------------------------#
532 local i=$1
[401f81e]533 local PREV=$2
534 case $i in
535 iteration* ) local LOGFILE="\$@.log" ;;
536 * ) local LOGFILE="\$@" ;;
537 esac
[0bdf6ed]538(
539cat << EOF
[877cc6a]540
[401f81e]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
[e2ef100]545EOF
546) >> $MKFILE.tmp
547}
548
[453bef0]549#----------------------------------#
[401f81e]550wrt_target_boot() { # Create target and initialize log file
[453bef0]551#----------------------------------#
[401f81e]552 local i=$1
553 local PREV=$2
554 case $i in
555 iteration* ) local LOGFILE="\$@.log" ;;
556 * ) local LOGFILE="\$@" ;;
557 esac
[453bef0]558(
559cat << EOF
560
[401f81e]561$i: $PREV
[453bef0]562 @\$(call echo_message, Building)
[401f81e]563 @./progress_bar.sh \$@ &
564 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT}\`\n" >logs/$LOGFILE
[453bef0]565EOF
566) >> $MKFILE.tmp
567}
568
569
[401f81e]570
[877cc6a]571#----------------------------#
[261eea6]572run_make() { #
[877cc6a]573#----------------------------#
574 # Test if make must be run.
[401f81e]575 if [ "$RUNMAKE" = "y" ] ; then
[877cc6a]576 # Test to make sure we're running the build as root
577 if [ "$UID" != "0" ] ; then
578 echo "You must be logged in as root to successfully build the system."
579 exit 1
580 fi
581 # Build the system
582 if [ -e $MKFILE ] ; then
583 echo -ne "Building the system...\n"
[a167246]584 cd $JHALFSDIR && make
[877cc6a]585 echo -ne "done\n"
586 fi
587 fi
588}
589
590
591#----------------------------#
[261eea6]592clean_builddir() { #
[877cc6a]593#----------------------------#
594 # Test if the clean must be done.
[401f81e]595 if [ "${CLEAN}" = "y" ]; then
[877cc6a]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
[73e5448]603 echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
[877cc6a]604 exit 1
605 else
606 # Clean the build directory
607 echo -ne "Cleaning $BUILDDIR...\n"
608 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
609 echo -ne "Cleaning $JHALFSDIR...\n"
[dd29d02]610 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,*logs,Makefile,*.xsl,makefile-functions,pkg_tarball_list,*.config,*.sh}
[877cc6a]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#----------------------------#
[261eea6]619get_book() { #
[877cc6a]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" ;;
[7432834]633 clfs2) svn_root="cross-lfs" ;;
[877cc6a]634 *) echo "BOOK not defined in function <get_book>"
635 exit 1 ;;
636 esac
637 # Grab a fresh book if it's missing, otherwise, update it from the
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
[1ff6768]642 if LC_ALL=C svn up | grep -q At && \
643 test -d $JHALFSDIR/${PROGNAME}-commands && \
644 test -f $JHALFSDIR/pkg_tarball_list ; then
[877cc6a]645 # Set the canonical book version
[a6655ff]646 echo -ne "done\n"
[877cc6a]647 cd $JHALFSDIR
[1ff6768]648 case $PROGNAME in
[7432834]649 clfs | clfs2)
[1ff6768]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
[877cc6a]654 get_sources
655 else
656 echo -ne "done\n"
657 extract_commands
658 fi
659 else
[cb39f79]660 svn co $SVN/${svn_root}/${TREE} ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1
[877cc6a]661 echo -ne "done\n"
662 extract_commands
663 fi
[1ff6768]664
[877cc6a]665 else
666 echo -ne "Using $BOOK as book's sources ...\n"
667 extract_commands
668 fi
[a6655ff]669 echo -ne " Document version ${L_arrow}${BOLD}${VERSION}${R_arrow}\n"
[877cc6a]670}
671
672#----------------------------#
673extract_commands() { #
674#----------------------------#
675
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
[1ff6768]681 case $PROGNAME in
[7432834]682 clfs | clfs2 )
[1ff6768]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
[877cc6a]687
688 # Start clean
[bfc07d6]689 if [ -d ${PROGNAME}-commands ]; then
690 rm -rf ${PROGNAME}-commands
691 mkdir -v ${PROGNAME}-commands
[877cc6a]692 fi
693 echo -n "Extracting commands for"
694
695 # Dump the commands in shell script form from the HLFS book.
696 case ${PROGNAME} in
697 clfs)
698 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
699 xsltproc --nonet \
700 --xinclude \
701 --stringparam method $METHOD \
702 --stringparam testsuite $TEST \
[28f4756]703 --stringparam bomb-testsuite $BOMB_TEST \
[877cc6a]704 --stringparam vim-lang $VIMLANG \
705 --stringparam timezone $TIMEZONE \
706 --stringparam page $PAGE \
707 --stringparam lang $LANG \
[401f81e]708 --stringparam keymap $KEYMAP \
[877cc6a]709 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
710 ;;
[7432834]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 \
[401f81e]720 --stringparam keymap $KEYMAP \
[7432834]721 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
722 ;;
[877cc6a]723 hlfs)
724 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
725 xsltproc --nonet \
726 --xinclude \
727 --stringparam model $MODEL \
728 --stringparam testsuite $TEST \
[28f4756]729 --stringparam bomb-testsuite $BOMB_TEST \
[877cc6a]730 --stringparam timezone $TIMEZONE \
731 --stringparam page $PAGE \
732 --stringparam lang $LANG \
733 --stringparam lc_all $LC_ALL \
[401f81e]734 --stringparam keymap $KEYMAP \
[877cc6a]735 --stringparam grsecurity_host $GRSECURITY_HOST \
736 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
737 ;;
738 lfs)
739 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
740 xsltproc --nonet \
741 --xinclude \
742 --stringparam testsuite $TEST \
[28f4756]743 --stringparam bomb-testsuite $BOMB_TEST \
[877cc6a]744 --stringparam vim-lang $VIMLANG \
745 --stringparam timezone $TIMEZONE \
746 --stringparam page $PAGE \
747 --stringparam lang $LANG \
748 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
749 ;;
[15cad16]750 *) exit 1 ;;
[877cc6a]751 esac
752
753 echo " ...OK"
754
755 # Make the scripts executable.
756 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
757
[15cad16]758 # Create the packages file. We need it for proper Makefile creation
[dd29d02]759 create_package_list
[877cc6a]760
761 # Done. Moving on...
762 get_sources
763}
764
[dd29d02]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
[7432834]773 clfs | clfs2)
[dd29d02]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
[877cc6a]791#----------------------------#
[15cad16]792get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
[93135fd]793#----------------------------#
794 local saveIFS=$IFS
[26053c4]795 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE
[93135fd]796
797 # Test if the packages must be downloaded
[401f81e]798 [ ! "$GETPKG" = "y" ] && return
[93135fd]799
800 gs_wrt_message(){
801 echo "${RED}$1${OFF}"
[c7dbe78]802 echo "$1" >> MISSING_FILES.DMP
803 }
[93135fd]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
810
811 # Generate URLs file
812 create_urls
813
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
817
818 # Skip some packages if they aren't needed
819 case $line in
820 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
821 [[ "$TEST" = "0" ]] && continue
822 ;;
823 */vim-*-lang* )
824 [[ "$VIMLANG" = "0" ]] && continue
825 ;;
[0c3f2f9]826 *linux/linux-* )
[294c937]827 [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
[401f81e]828 [[ "$GETKERNEL" = "n" ]] && continue
[0c3f2f9]829 ;;
[93135fd]830 esac
831
832 # Locations
[296ae69]833 URL1=`echo $line | cut -d" " -f2` # Preferred URL
834 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
[26053c4]835 FILE=`basename $URL1` # File name
836 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
837
[8a43b5b]838 # Validation pair
839 MD5="$BOOKMD5 $FILE"
840 HAVEMD5=1
[93135fd]841
842 set -e
[c7dbe78]843 # If the file exists in the archive copy it to the
[93135fd]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
[8a43b5b]854 # If the file does not exist yet in /sources download a fresh one
[93135fd]855 if [ ! -f $FILE ] ; then
856 if ! wget $URL1 && ! wget $URL2 ; then
[c7dbe78]857 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
858 continue
[93135fd]859 fi
860 fi
861 fi
862
[8a43b5b]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
[93135fd]875 fi
876 fi
877
878 # Validate the MD5SUM one last time
[8a43b5b]879 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
[93135fd]880 gs_wrt_message "$FILE does not match MD5SUMS value"
[0910f55]881 # Force generation of MD5SUM
882 HAVEMD5=0
[93135fd]883 fi
884
885 # Generate a fresh MD5SUM for this file
886 if [[ "$HAVEMD5" = "0" ]] ; then
887 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
[8a43b5b]888 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
[93135fd]889 fi
890
891 # Good or bad we write the original md5sum to a file
[8a43b5b]892 echo "$MD5" >> MD5SUMS
[93135fd]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
[d385453]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.
[261eea6]909 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
[401f81e]910 RUNMAKE="n"
[93135fd]911 fi
912}
913
[877cc6a]914#----------------------------#
[15cad16]915create_urls() { #
[877cc6a]916#----------------------------#
[15cad16]917 cd $JHALFSDIR
[877cc6a]918
[15cad16]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 ;;
[7432834]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 ;;
[15cad16]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
[877cc6a]954
[15cad16]955 cd $BUILDDIR/sources
[877cc6a]956}
Note: See TracBrowser for help on using the repository browser.