source: common/common-functions@ 82eb8c1

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

Creating "unpacked" inside souces dir instead /tmp and referencing it via envar.

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