source: common/common-functions@ 7d1f862

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 7d1f862 was 7eb9402, checked in by George Boudreau <georgeb@…>, 18 years ago

The never ending story of cleaning up CLFS scripts..

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