source: common/common-functions@ e5f5970

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

more corrections to CLFS scripts.

  • Property mode set to 100644
File size: 27.2 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
[dd29d02]210#----------------------------#
211get_package_tarball_name() { #
212#----------------------------#
213 local script_name=$1
214
215 # The use of 'head' is necessary to limit the return value to the FIRST match..
216 # hopefully this will not cause problems.
217 #
218 case $script_name in
219 tcl) echo $(grep "^tcl" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
220 *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
221 esac
222
223}
[877cc6a]224
[5842156]225#----------------------------------#
226wrt_remove_existing_dirs() { #
227#----------------------------------#
228 local PKG_NAME=$1
229(
230cat << EOF
[3b3251a]231 @PKG_PATH=\`ls -t \$(MOUNT_PT)\$(SRC)/${PKG_NAME} | head -n1\` && \\
232 ROOT=\`tar -tf \$\$PKG_PATH | head -n1 | sed -e 's@^./@@;s@/.*@@'\` && \\
[5842156]233 [[ -n \$\$ROOT ]] && \\
234 rm -rf \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
[15787a3]235 if [ -e \$(MOUNT_PT)\$(SRC)/${PKG_NAME%-*}-build ]; then \\
236 rm -rf \$(MOUNT_PT)\$(SRC)/${PKG_NAME%-*}-build; \\
[5842156]237 fi;
238EOF
239) >> $MKFILE.tmp
240}
241
242#----------------------------------#
243wrt_remove_existing_dirs2() { #
244#----------------------------------#
245 local PKG_NAME=$1
246(
247cat << EOF
[3b3251a]248 @PKG_PATH=\`ls -t \$(SRC)/${PKG_NAME} | head -n1\` && \\
249 ROOT=\`tar -tf \$\$PKG_PATH | head -n1 | sed -e 's@^./@@;s@/.*@@'\` && \\
[5842156]250 [[ -n \$\$ROOT ]] && \\
251 rm -rf \$(SRC)/\$\$ROOT && \\
[15787a3]252 if [ -e \$(SRC)/${PKG_NAME%-*}-build ]; then \\
253 rm -rf \$(SRC)/${PKG_NAME%-*}-build; \\
[5842156]254 fi;
255EOF
256) >> $MKFILE.tmp
257}
258
259
260
[877cc6a]261#----------------------------------#
262wrt_unpack() { # Unpack and set 'ROOT' var
263#----------------------------------#
264 local FILE=$1
[5842156]265 local optSAVE_PREVIOUS=$2
[82eb8c1]266
[5842156]267 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
268 wrt_remove_existing_dirs "$FILE"
269 fi
[877cc6a]270(
271cat << EOF
272 @\$(call unpack,$FILE)
[82eb8c1]273 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
[877cc6a]274 echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
[15537d5]275 chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT
[877cc6a]276EOF
277) >> $MKFILE.tmp
278}
279
280
[e5f5970]281#----------------------------------#
282wrt_unpack_clfs() { # Unpack and set 'ROOT' var
283#----------------------------------#
284 local FILE=$1
285 local optSAVE_PREVIOUS=$2
286
287 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
288 wrt_remove_existing_dirs "$FILE"
289 fi
290(
291cat << EOF
292 @\$(call unpack,$FILE)
293 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
294 echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
295 chown -R clfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT
296EOF
297) >> $MKFILE.tmp
298}
299
300
[877cc6a]301#----------------------------------#
302wrt_unpack2() { #
303#----------------------------------#
304 local FILE=$1
[5842156]305 local optSAVE_PREVIOUS=$2
306
307 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
308 wrt_remove_existing_dirs "$FILE"
309 fi
[877cc6a]310(
311cat << EOF
312 @\$(call unpack2,$FILE)
[a229600]313 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
[877cc6a]314 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
315EOF
316) >> $MKFILE.tmp
317}
318
319
[261eea6]320#----------------------------------#
321wrt_unpack3() { #
322#----------------------------------#
[877cc6a]323 local FILE=$1
[5842156]324 local optSAVE_PREVIOUS=$2
325
326 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
327 wrt_remove_existing_dirs2 "$FILE"
328 fi
[877cc6a]329(
330cat << EOF
331 @\$(call unpack3,$FILE)
[82eb8c1]332 @ROOT=\`head -n1 \$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
[877cc6a]333 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
334EOF
335) >> $MKFILE.tmp
336}
337
[a229600]338#----------------------------------#
339wrt_test_log() { # Initialize testsuite log file
340#----------------------------------#
341 local TESTLOGFILE=$1
342(
343cat << EOF
344 @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
345 su - lfs -c "echo -e '\n\`date\`\n' >$TESTLOGDIR/$TESTLOGFILE"
346EOF
347) >> $MKFILE.tmp
348}
349
350#----------------------------------#
351wrt_test_log2() { #
352#----------------------------------#
353 local TESTLOGFILE=$1
354(
355cat << EOF
356 @echo "export TEST_LOG=/$SCRIPT_ROOT/test-logs/$TESTLOGFILE" >> envars && \\
357 echo -e "\n\`date\`\n" >test-logs/$TESTLOGFILE
358EOF
359) >> $MKFILE.tmp
360}
361
[877cc6a]362#----------------------------------#
363wrt_target_vars() { # Target vars for hlfs (cross-build method)
364#----------------------------------#
365(
366cat << EOF
367 @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
368 echo "export ldso=/lib/${LOADER}" >> envars
369EOF
370) >> $MKFILE.tmp
371
372}
373
374
375#----------------------------------#
[3a321ea]376wrt_run_as_su() { # Execute script inside time { }, footer to log file
[877cc6a]377#----------------------------------#
378 local this_script=$1
379 local file=$2
380(
381cat << EOF
[3a321ea]382 @( time { su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
[1a1f099]383 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
[877cc6a]384EOF
385) >> $MKFILE.tmp
386}
387
388
389#----------------------------------#
[3a321ea]390wrt_run_as_root() { # Some scripts must be run as root..
[877cc6a]391#----------------------------------#
392 local this_script=$1
393 local file=$2
394(
395cat << EOF
[3a321ea]396 @( time { export LFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
[1a1f099]397 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
[877cc6a]398EOF
399) >> $MKFILE.tmp
400}
401
402
[e5f5970]403#----------------------------------#
404wrt_run_as_clfs_su() { # Execute script inside time { }, footer to log file
405#----------------------------------#
406 local this_script=$1
407 local file=$2
408(
409cat << EOF
410 @( time { su - clfs -c "source /home/clfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
411 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
412EOF
413) >> $MKFILE.tmp
414}
415
416
[ac1d897]417#----------------------------------#
418wrt_run_as_clfs_root() { # Some scripts must be run as root..
419#----------------------------------#
420 local this_script=$1
421 local file=$2
422(
423cat << EOF
424 @( time { export CLFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
425 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
426EOF
427) >> $MKFILE.tmp
428}
429
430
[261eea6]431#----------------------------------#
432wrt_run_as_root2() { #
433#----------------------------------#
[877cc6a]434 local this_script=$1
435 local file=$2
436(
437cat << EOF
[3a321ea]438 @( time { source envars && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
[1a1f099]439 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \`\n" >>logs/$this_script
[877cc6a]440EOF
441) >> $MKFILE.tmp
442}
443
444
445
446#----------------------------------#
447wrt_run_as_chroot1() { #
448#----------------------------------#
449 local this_script=$1
450 local file=$2
451(
452 cat << EOF
[1a1f099]453 @( time { \$(CHROOT1) 'cd /${SCRIPT_ROOT} && source envars && /${SCRIPT_ROOT}/${PROGNAME}-commands/$file >>/${SCRIPT_ROOT}/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
454 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/${this_script}
[877cc6a]455EOF
456) >> $MKFILE.tmp
457}
458
459
460#----------------------------------#
461wrt_run_as_chroot2() { #
462#----------------------------------#
463 local this_script=$1
464 local file=$2
465(
466cat << EOF
[1a1f099]467 @( time { \$(CHROOT2) 'cd /${SCRIPT_ROOT} && source envars && /${SCRIPT_ROOT}/${PROGNAME}-commands/$file >>/${SCRIPT_ROOT}/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
468 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/${this_script}
[877cc6a]469EOF
470) >> $MKFILE.tmp
471}
472
473
474#----------------------------------#
475wrt_copy_fstab() { #
476#----------------------------------#
477 local i=$1
478(
479 cat << EOF
[3a321ea]480 @cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1
[877cc6a]481EOF
482) >> $MKFILE.tmp
483}
484
485#----------------------------------#
[3a321ea]486wrt_copy_fstab2() { #
[877cc6a]487#----------------------------------#
488 local i=$1
489(
490 cat << EOF
[3a321ea]491 @cp -v /sources/fstab /etc/fstab >>logs/$i 2>&1
[877cc6a]492EOF
493) >> $MKFILE.tmp
494}
495
496
497#----------------------------------#
[0bdf6ed]498wrt_remove_build_dirs() { #
[877cc6a]499#----------------------------------#
[0bdf6ed]500 local name=$1
[877cc6a]501(
[0bdf6ed]502cat << EOF
[82eb8c1]503 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
[b7faa5a]504 rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
505 if [ -e \$(MOUNT_PT)\$(SRC)/$name-build ]; then \\
[0bdf6ed]506 rm -r \$(MOUNT_PT)\$(SRC)/$name-build; \\
507 fi;
508EOF
509) >> $MKFILE.tmp
510}
511
512
513#----------------------------------#
514wrt_remove_build_dirs2() { #
515#----------------------------------#
516 local name=$1
517(
518cat << EOF
[82eb8c1]519 @ROOT=\`head -n1 \$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
[b7faa5a]520 rm -r \$(SRC)/\$\$ROOT && \\
521 if [ -e \$(SRC)/$name-build ]; then \\
[0bdf6ed]522 rm -r \$(SRC)/$name-build; \\
523 fi;
[877cc6a]524EOF
525) >> $MKFILE.tmp
526}
527
528
[e2ef100]529#----------------------------------#
530wrt_touch() { #
531#----------------------------------#
532(
533cat << EOF
534 @touch \$@ && \\
535 sleep .25 && \\
[4a444f1]536 echo -e "\n\n "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
537 echo --------------------------------------------------------------------------------\$(WHITE)
[e2ef100]538EOF
539) >> $MKFILE.tmp
540}
541
542
[453bef0]543#----------------------------------#
[261eea6]544wrt_report() { #
[453bef0]545#----------------------------------#
546(
547cat << EOF
548
549create-sbu_du-report: $PREV
550 @\$(call echo_message, Building)
[a9429d5]551 @./create-sbu_du-report.sh logs $VERSION
[453bef0]552 @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
553 @touch \$@
554EOF
555) >> $MKFILE.tmp
556
557chapter789="$chapter789 create-sbu_du-report"
558}
559
560
[877cc6a]561#----------------------------#
[261eea6]562run_make() { #
[877cc6a]563#----------------------------#
564 # Test if make must be run.
565 if [ "$RUNMAKE" = "1" ] ; then
566 # Test to make sure we're running the build as root
567 if [ "$UID" != "0" ] ; then
568 echo "You must be logged in as root to successfully build the system."
569 exit 1
570 fi
571 # Build the system
572 if [ -e $MKFILE ] ; then
573 echo -ne "Building the system...\n"
[a167246]574 cd $JHALFSDIR && make
[877cc6a]575 echo -ne "done\n"
576 fi
577 fi
578}
579
580
581#----------------------------#
[261eea6]582clean_builddir() { #
[877cc6a]583#----------------------------#
584 # Test if the clean must be done.
585 if [ "$CLEAN" = "1" ] ; then
586 # Test to make sure we're running the clean as root
587 if [ "$UID" != "0" ] ; then
588 echo "You must be logged in as root to clean the build directory."
589 exit 1
590 fi
591 # Test to make sure that the build directory was populated by jhalfs
592 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
[73e5448]593 echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
[877cc6a]594 exit 1
595 else
596 # Clean the build directory
597 echo -ne "Cleaning $BUILDDIR...\n"
598 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
599 echo -ne "Cleaning $JHALFSDIR...\n"
[dd29d02]600 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,*logs,Makefile,*.xsl,makefile-functions,pkg_tarball_list,*.config,*.sh}
[877cc6a]601 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
602 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
603 echo -ne "done\n"
604 fi
605 fi
606}
607
608#----------------------------#
[261eea6]609get_book() { #
[877cc6a]610#----------------------------#
611 cd $JHALFSDIR
612
613 if [ -z $WC ] ; then
614 # Check for Subversion instead of just letting the script hit 'svn' and fail.
615 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
616 exit 1"
617 echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
618
619 case $PROGNAME in
620 lfs) svn_root="LFS" ;;
621 hlfs) svn_root="HLFS" ;;
622 clfs) svn_root="cross-lfs" ;;
623 *) echo "BOOK not defined in function <get_book>"
624 exit 1 ;;
625 esac
626 # Grab a fresh book if it's missing, otherwise, update it from the
627 # repo. If we've already extracted the commands, move on to getting the
628 # sources.
629 if [ -d ${PROGNAME}-$LFSVRS ] ; then
630 cd ${PROGNAME}-$LFSVRS
[1ff6768]631 if LC_ALL=C svn up | grep -q At && \
632 test -d $JHALFSDIR/${PROGNAME}-commands && \
633 test -f $JHALFSDIR/pkg_tarball_list ; then
[877cc6a]634 # Set the canonical book version
[1ff6768]635 echo -ne "done\n"
[877cc6a]636 cd $JHALFSDIR
[1ff6768]637 case $PROGNAME in
638 clfs)
639 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
640 *)
641 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
642 esac
[877cc6a]643 get_sources
644 else
645 echo -ne "done\n"
646 extract_commands
647 fi
648 else
649 case $LFSVRS in
650 development)
651 svn co $SVN/${svn_root}/trunk/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
652 esac
653 echo -ne "done\n"
654 extract_commands
655 fi
[1ff6768]656
[877cc6a]657 else
658 echo -ne "Using $BOOK as book's sources ...\n"
659 extract_commands
660 fi
[1ff6768]661 echo -ne " Document version ${L_arrow}${BOLD}${VERSION}${R_arrow}\n"
[877cc6a]662}
663
664#----------------------------#
665extract_commands() { #
666#----------------------------#
667
668 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
669 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
670 exit 1"
671
672 cd $JHALFSDIR
[1ff6768]673 case $PROGNAME in
674 clfs)
675 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
676 *)
677 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
678 esac
[877cc6a]679
680 # Start clean
[bfc07d6]681 if [ -d ${PROGNAME}-commands ]; then
682 rm -rf ${PROGNAME}-commands
683 mkdir -v ${PROGNAME}-commands
[877cc6a]684 fi
685 echo -n "Extracting commands for"
686
687 # Dump the commands in shell script form from the HLFS book.
688 case ${PROGNAME} in
689 clfs)
690 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
691 xsltproc --nonet \
692 --xinclude \
693 --stringparam method $METHOD \
694 --stringparam testsuite $TEST \
695 --stringparam vim-lang $VIMLANG \
696 --stringparam timezone $TIMEZONE \
697 --stringparam page $PAGE \
698 --stringparam lang $LANG \
699 --stringparam keymap $KEYMAP \
700 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
701 ;;
702 hlfs)
703 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
704 xsltproc --nonet \
705 --xinclude \
706 --stringparam model $MODEL \
707 --stringparam testsuite $TEST \
708 --stringparam timezone $TIMEZONE \
709 --stringparam page $PAGE \
710 --stringparam lang $LANG \
711 --stringparam lc_all $LC_ALL \
712 --stringparam keymap $KEYMAP \
713 --stringparam grsecurity_host $GRSECURITY_HOST \
714 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
715 ;;
716 lfs)
717 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
718 xsltproc --nonet \
719 --xinclude \
720 --stringparam testsuite $TEST \
721 --stringparam vim-lang $VIMLANG \
722 --stringparam timezone $TIMEZONE \
723 --stringparam page $PAGE \
724 --stringparam lang $LANG \
725 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
726 ;;
[15cad16]727 *) exit 1 ;;
[877cc6a]728 esac
729
730 echo " ...OK"
731
732 # Make the scripts executable.
733 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
734
[15cad16]735 # Create the packages file. We need it for proper Makefile creation
[dd29d02]736 create_package_list
[877cc6a]737
738 # Done. Moving on...
739 get_sources
740}
741
[dd29d02]742#----------------------------#
743create_package_list() { #
744#----------------------------#
745
746 # Create the packages file. We need it for proper Makefile creation
747 rm -f pkg_tarball_list
748 echo -n "Creating <${PROGNAME}> list of tarball names for $BOOK $ARCH"
749 case ${PROGNAME} in
750 clfs)
751 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
752 $BOOK/materials/${ARCH}-chapter.xml >>$LOGDIR/$LOG 2>&1
753 ;;
754 hlfs)
755 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
756 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
757 ;;
758 lfs)
759 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
760 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
761 ;;
762 esac
763 echo " ...OK"
764
765}
766
767
[877cc6a]768#----------------------------#
[15cad16]769get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
[93135fd]770#----------------------------#
771 local saveIFS=$IFS
[26053c4]772 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE
[93135fd]773
774 # Test if the packages must be downloaded
775 [ ! "$GETPKG" = "1" ] && return
776
777 gs_wrt_message(){
778 echo "${RED}$1${OFF}"
[c7dbe78]779 echo "$1" >> MISSING_FILES.DMP
780 }
[93135fd]781 # Housekeeping
782 [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
783 cd $BUILDDIR/sources
784 [[ -f MD5SUMS ]] && rm MD5SUMS
785 [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
786 [[ -f urls.lst ]] && rm urls.lst
787
788 # Generate URLs file
789 create_urls
790
791 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
792 for line in `cat urls.lst`; do
793 IFS=$saveIFS # Restore the system defaults
794
795 # Skip some packages if they aren't needed
796 case $line in
797 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
798 [[ "$TEST" = "0" ]] && continue
799 ;;
800 */vim-*-lang* )
801 [[ "$VIMLANG" = "0" ]] && continue
802 ;;
[0c3f2f9]803 *linux/linux-* )
[294c937]804 [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
805 [[ "$GETKERNEL" = "0" ]] && continue
[0c3f2f9]806 ;;
[93135fd]807 esac
808
809 # Locations
[296ae69]810 URL1=`echo $line | cut -d" " -f2` # Preferred URL
811 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
[26053c4]812 FILE=`basename $URL1` # File name
813 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
814
[8a43b5b]815 # Validation pair
816 MD5="$BOOKMD5 $FILE"
817 HAVEMD5=1
[93135fd]818
819 set -e
[c7dbe78]820 # If the file exists in the archive copy it to the
[93135fd]821 # $BUILDDIR/sources dir. MD5SUM will be validated later.
822 if [ ! -z ${SRC_ARCHIVE} ] &&
823 [ -d ${SRC_ARCHIVE} ] &&
824 [ -f ${SRC_ARCHIVE}/$FILE ]; then
825 cp ${SRC_ARCHIVE}/$FILE .
826 echo "$FILE: -- copied from $SRC_ARCHIVE"
827 fromARCHIVE=1
828 else
829 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
830 fromARCHIVE=0
[8a43b5b]831 # If the file does not exist yet in /sources download a fresh one
[93135fd]832 if [ ! -f $FILE ] ; then
833 if ! wget $URL1 && ! wget $URL2 ; then
[c7dbe78]834 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
835 continue
[93135fd]836 fi
837 fi
838 fi
839
[8a43b5b]840 # IF the md5sum does not match the existing files
841 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
842 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
843 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
844 # Remove the old file and download a new one
845 rm -fv $FILE
846 # Force storage in SRC_ARCHIVE
847 fromARCHIVE=0;
848 # Try to retrieve again the file. Servers in reverse order.
849 if ! wget $URL2 && ! wget $URL1 ; then
850 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
851 continue
[93135fd]852 fi
853 fi
854
855 # Validate the MD5SUM one last time
[8a43b5b]856 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
[93135fd]857 gs_wrt_message "$FILE does not match MD5SUMS value"
[0910f55]858 # Force generation of MD5SUM
859 HAVEMD5=0
[93135fd]860 fi
861
862 # Generate a fresh MD5SUM for this file
863 if [[ "$HAVEMD5" = "0" ]] ; then
864 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
[8a43b5b]865 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
[93135fd]866 fi
867
868 # Good or bad we write the original md5sum to a file
[8a43b5b]869 echo "$MD5" >> MD5SUMS
[93135fd]870
871 # Copy the freshly downloaded file
872 # to the source archive.
873 if [ ! -z ${SRC_ARCHIVE} ] &&
874 [ -d ${SRC_ARCHIVE} ] &&
875 [ -w ${SRC_ARCHIVE} ] &&
876 [ "$fromARCHIVE" = "0" ] ; then
877 echo "Storing file:<$FILE> in the package archive"
878 cp -f $FILE ${SRC_ARCHIVE}
879 fi
880
881 done
882
883 if [[ -s MISSING_FILES.DMP ]]; then
884 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"
885 # Do not allow the automatic exection of the Makefile.
[261eea6]886 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
[93135fd]887 RUNMAKE=0
888 fi
889}
890
[877cc6a]891#----------------------------#
[15cad16]892create_urls() { #
[877cc6a]893#----------------------------#
[15cad16]894 cd $JHALFSDIR
[877cc6a]895
[15cad16]896 case ${PROGNAME} in
897 clfs)
898 echo -n "Creating CLFS <${ARCH}> specific URLs file"
899 xsltproc --nonet --xinclude \
900 --stringparam server $SERVER \
901 -o $BUILDDIR/sources/urls.lst urls.xsl \
902 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
903 echo " ...OK"
904 ;;
905 hlfs)
906 echo -n "Creating HLFS <${MODEL}> specific URLs file"
907 xsltproc --nonet --xinclude \
908 --stringparam server $SERVER \
909 --stringparam model $MODEL \
910 -o $BUILDDIR/sources/urls.lst urls.xsl \
911 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
912 echo " ...OK"
913 ;;
914 lfs)
915 echo -n "Creating LFS specific URLs file"
916 xsltproc --nonet --xinclude \
917 --stringparam server $SERVER \
918 -o ../sources/urls.lst urls.xsl \
919 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
920 echo " ...OK"
921 ;;
922 esac
[877cc6a]923
[15cad16]924 cd $BUILDDIR/sources
[877cc6a]925}
Note: See TracBrowser for help on using the repository browser.