source: common/common-functions@ 983db9f

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

Ported from experimental linux-header package name fix.

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