source: common/common-functions@ 6f75d64

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

Applied Dan Nicholson's changes to progress_bar.sh and its support code

  • Property mode set to 100644
File size: 24.5 KB
RevLine 
[877cc6a]1#!/bin/bash
2
3# $Id$
4
[4da2512]5set -e
[877cc6a]6
7
8no_empty_builddir() {
9 'clear'
10cat <<- -EOF-
11${DD_BORDER}
12
13${tab_}${tab_}${BOLD}${RED}W A R N I N G${OFF}
14 Looks like the \$BUILDDIR directory contains subdirectories
15 from a previous HLFS build.
16
17 Please format the partition mounted on \$BUILDDIR or set
[73e5448]18 a different build directory before running jhalfs.
[877cc6a]19${OFF}
20${DD_BORDER}
21-EOF-
22 exit
23}
24
25
[73e5448]26HEADER="# This file is automatically generated by jhalfs
[877cc6a]27# DO NOT EDIT THIS FILE MANUALLY
28#
29# Generated on `date \"+%F %X %Z\"`"
30
31
32
33#----------------------------------#
[3a321ea]34wrt_target() { # Create target and initialize log file
[877cc6a]35#----------------------------------#
36 local i=$1
37 local PREV=$2
[4edf3b7]38 case $i in
39 iteration* ) local LOGFILE=$this_script.log ;;
40 * ) local LOGFILE=$this_script ;;
41 esac
[877cc6a]42(
43cat << EOF
44
45$i: $PREV
46 @\$(call echo_message, Building)
[d44206f]47 @./progress_bar.sh \$@ \$\$PPID &
[1a1f099]48 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >logs/$LOGFILE
[877cc6a]49EOF
50) >> $MKFILE.tmp
51}
52
[7eb9402]53
54#----------------------------------#
55wrt_target_boot() { # Create target and initialize log file
56#----------------------------------#
57 local i=$1
58 local PREV=$2
59 case $i in
60 iteration* ) local LOGFILE=$this_script.log ;;
61 * ) local LOGFILE=$this_script ;;
62 esac
63(
64cat << EOF
65
66$i: $PREV
67 @\$(call echo_message, Building)
[d44206f]68 @./progress_bar.sh \$@ \$\$PPID &
[7eb9402]69 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT}\`\n" >logs/$LOGFILE
70EOF
71) >> $MKFILE.tmp
72}
73
[dd29d02]74#----------------------------#
75get_package_tarball_name() { #
76#----------------------------#
77 local script_name=$1
78
79 # The use of 'head' is necessary to limit the return value to the FIRST match..
80 # hopefully this will not cause problems.
81 #
82 case $script_name in
[6ad5a2f]83 tcl) echo $(grep "^tcl" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
[983db9f]84 linux-headers) echo $(grep "^linux-headers.*.bz2" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
[6ad5a2f]85 *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
[dd29d02]86 esac
87
88}
[877cc6a]89
[401f81e]90
[5842156]91#----------------------------------#
[401f81e]92wrt_test_log() { # Initialize testsuite log file
[5842156]93#----------------------------------#
[401f81e]94 local TESTLOGFILE=$1
[5842156]95(
[401f81e]96cat << EOF
97 @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
98 su - \$(LUSER) -c "echo -e '\n\`date\`\n' >$TESTLOGDIR/$TESTLOGFILE"
[5842156]99EOF
100) >> $MKFILE.tmp
101}
102
103#----------------------------------#
[401f81e]104wrt_test_log2() { #
[5842156]105#----------------------------------#
[401f81e]106 local TESTLOGFILE=$1
[5842156]107(
[401f81e]108cat << EOF
109 @echo "export TEST_LOG=/$SCRIPT_ROOT/test-logs/$TESTLOGFILE" >> envars && \\
110 echo -e "\n\`date\`\n" >test-logs/$TESTLOGFILE
111EOF
112) >> $MKFILE.tmp
113}
114
115#----------------------------------#
116wrt_target_vars() { # Target vars for hlfs (cross-build method)
117#----------------------------------#
118(
119cat << EOF
120 @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
121 echo "export ldso=/lib/${LOADER}" >> envars
122EOF
123) >> $MKFILE.tmp
124
125}
126
127
128#----------------------------------#
129wrt_copy_fstab() { #
130#----------------------------------#
131 local i=$1
132(
133 cat << EOF
134 @cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1
135EOF
136) >> $MKFILE.tmp
137}
138
139
140#----------------------------------#
141wrt_copy_fstab2() { #
142#----------------------------------#
143 local i=$1
144(
145 cat << EOF
146 @cp -v /sources/fstab /etc/fstab >>logs/$i 2>&1
[5842156]147EOF
148) >> $MKFILE.tmp
149}
150
151
[401f81e]152#----------------------------------#
153wrt_report() { #
154#----------------------------------#
155(
156cat << EOF
[5842156]157
[401f81e]158create-sbu_du-report: $PREV
159 @\$(call echo_message, Building)
160 @./create-sbu_du-report.sh logs $VERSION
161 @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
162 @touch \$@
163EOF
164) >> $MKFILE.tmp
165
166chapter789="$chapter789 create-sbu_du-report"
167}
168
169unset wrt_unpack
[877cc6a]170#----------------------------------#
171wrt_unpack() { # Unpack and set 'ROOT' var
172#----------------------------------#
173 local FILE=$1
[5842156]174 local optSAVE_PREVIOUS=$2
[82eb8c1]175
[401f81e]176 if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
177(
178cat << EOF
179 @\$(call remove_existing_dirs,$FILE)
180EOF
181) >> $MKFILE.tmp
[5842156]182 fi
[401f81e]183
[877cc6a]184(
185cat << EOF
186 @\$(call unpack,$FILE)
[401f81e]187 @\$(call get_pkg_root)
[e5f5970]188EOF
189) >> $MKFILE.tmp
190
[401f81e]191}
[e5f5970]192
[401f81e]193unset wrt_unpack2
[877cc6a]194#----------------------------------#
195wrt_unpack2() { #
196#----------------------------------#
197 local FILE=$1
[5842156]198 local optSAVE_PREVIOUS=$2
199
200 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
[401f81e]201(
202cat << EOF
203 @\$(call remove_existing_dirs,$FILE)
204EOF
205) >> $MKFILE.tmp
[5842156]206 fi
[877cc6a]207(
208cat << EOF
209 @\$(call unpack2,$FILE)
[401f81e]210 @\$(call get_pkg_root,nouser)
[877cc6a]211EOF
212) >> $MKFILE.tmp
213}
214
[261eea6]215#----------------------------------#
216wrt_unpack3() { #
217#----------------------------------#
[877cc6a]218 local FILE=$1
[5842156]219 local optSAVE_PREVIOUS=$2
220
221 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
[401f81e]222(
223cat << EOF
224 @\$(call remove_existing_dirs2,$FILE)
225EOF
226) >> $MKFILE.tmp
[5842156]227 fi
[877cc6a]228(
229cat << EOF
230 @\$(call unpack3,$FILE)
[401f81e]231 @\$(call get_pkg_root2)
[877cc6a]232EOF
233) >> $MKFILE.tmp
234}
235
[401f81e]236
237unset wrt_remove_build_dirs
[a229600]238#----------------------------------#
[401f81e]239wrt_remove_build_dirs() { #
[a229600]240#----------------------------------#
[401f81e]241 local name=$1
[a229600]242(
[401f81e]243cat << EOF
244 @\$(call remove_build_dirs,$name)
[a229600]245EOF
246) >> $MKFILE.tmp
247}
248
249#----------------------------------#
[401f81e]250wrt_remove_build_dirs2() { #
[a229600]251#----------------------------------#
[401f81e]252 local name=$1
[a229600]253(
[401f81e]254cat << EOF
255 @\$(call remove_build_dirs2,$name)
[a229600]256EOF
257) >> $MKFILE.tmp
258}
259
[401f81e]260
261
262unset wrt_touch
[877cc6a]263#----------------------------------#
[401f81e]264wrt_touch() { #
[877cc6a]265#----------------------------------#
266(
[401f81e]267cat << EOF
268 @\$(call housekeeping)
[877cc6a]269EOF
270) >> $MKFILE.tmp
271}
272
[401f81e]273unset wrt_RunAsUser
[877cc6a]274#----------------------------------#
[6ad5a2f]275wrt_RunAsUser() { # Execute script inside time { }, footer to log file
[877cc6a]276#----------------------------------#
277 local this_script=$1
278 local file=$2
[401f81e]279
[877cc6a]280(
281cat << EOF
[401f81e]282 @( time { \$(SU_LUSER) "source \$(LUSER_HOME)/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@" >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\
283 \$(PRT_DU) >> logs/\$@
[877cc6a]284EOF
285) >> $MKFILE.tmp
286}
287
288
[e5f5970]289#----------------------------------#
[6ad5a2f]290wrt_RunAsRoot() { # Some scripts must be run as root..
[e5f5970]291#----------------------------------#
[6ad5a2f]292 local ENV_MOUNT
[e5f5970]293 local this_script=$1
294 local file=$2
295
[6ad5a2f]296 case ${PROGNAME} in
297 lfs ) MOUNT_ENV="LFS" ;;
298 blfs ) MOUNT_ENV="BLFS" ;;
299 clfs ) MOUNT_ENV="CLFS" ;;
300 clfs2 ) MOUNT_ENV="CLFS" ;;
301 hlfs ) MOUNT_ENV="HLFS" ;;
302 *) echo "undefined progname $PROGNAME"; exit 1
303 esac
[e5f5970]304
[ac1d897]305(
306cat << EOF
[401f81e]307 @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
308 \$(PRT_DU_CR) >>logs/\$@
[ac1d897]309EOF
310) >> $MKFILE.tmp
311}
312
[261eea6]313#----------------------------------#
314wrt_run_as_root2() { #
315#----------------------------------#
[877cc6a]316 local this_script=$1
317 local file=$2
318(
319cat << EOF
[401f81e]320 @( time { source envars && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
321 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \`\n" >>logs/\$@
[877cc6a]322EOF
323) >> $MKFILE.tmp
324}
325
326
[401f81e]327unset wrt_run_as_chroot1
[877cc6a]328#----------------------------------#
329wrt_run_as_chroot1() { #
330#----------------------------------#
331 local this_script=$1
332 local file=$2
333(
[401f81e]334cat << EOF
[3619bc5]335 @( time { \$(CHROOT1) 'cd \$(SCRIPT_ROOT) && source envars && \$(crCMDSDIR)/$file >>logs/${this_script} 2>&1' ; } ) 2>>logs/${this_script} && \\
336 \$(PRT_DU_CR) >> logs/${this_script}
[877cc6a]337EOF
338) >> $MKFILE.tmp
339}
340
[401f81e]341unset wrt_run_as_chroot2
[877cc6a]342#----------------------------------#
343wrt_run_as_chroot2() { #
344#----------------------------------#
345 local this_script=$1
346 local file=$2
347(
348cat << EOF
[4275c72]349 @( time { \$(CHROOT2) 'cd \$(SCRIPT_ROOT) && source envars && \$(crCMDSDIR)/`dirname $file`/\$@ >>logs/\$@ 2>&1' ; } ) 2>>logs/\$@ && \\
[401f81e]350 \$(PRT_DU_CR) >> logs/\$@
[877cc6a]351EOF
352) >> $MKFILE.tmp
353}
354
[401f81e]355unset wrt_target
[877cc6a]356#----------------------------------#
[401f81e]357wrt_target() { # Create target and initialize log file
[877cc6a]358#----------------------------------#
359 local i=$1
[401f81e]360 local PREV=$2
361 case $i in
362 iteration* ) local LOGFILE="\$@.log" ;;
363 * ) local LOGFILE="\$@" ;;
364 esac
[0bdf6ed]365(
366cat << EOF
[877cc6a]367
[401f81e]368$i: $PREV
369 @\$(call echo_message, Building)
[d44206f]370 @./progress_bar.sh \$@ \$\$PPID &
[401f81e]371 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >logs/$LOGFILE
[e2ef100]372EOF
373) >> $MKFILE.tmp
374}
375
[453bef0]376#----------------------------------#
[401f81e]377wrt_target_boot() { # Create target and initialize log file
[453bef0]378#----------------------------------#
[401f81e]379 local i=$1
380 local PREV=$2
381 case $i in
382 iteration* ) local LOGFILE="\$@.log" ;;
383 * ) local LOGFILE="\$@" ;;
384 esac
[453bef0]385(
386cat << EOF
387
[401f81e]388$i: $PREV
[453bef0]389 @\$(call echo_message, Building)
[d44206f]390 @./progress_bar.sh \$@ \$\$PPID &
[401f81e]391 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT}\`\n" >logs/$LOGFILE
[453bef0]392EOF
393) >> $MKFILE.tmp
394}
395
396
[401f81e]397
[877cc6a]398#----------------------------#
[261eea6]399run_make() { #
[877cc6a]400#----------------------------#
401 # Test if make must be run.
[401f81e]402 if [ "$RUNMAKE" = "y" ] ; then
[877cc6a]403 # Test to make sure we're running the build as root
404 if [ "$UID" != "0" ] ; then
405 echo "You must be logged in as root to successfully build the system."
406 exit 1
407 fi
408 # Build the system
409 if [ -e $MKFILE ] ; then
410 echo -ne "Building the system...\n"
[a167246]411 cd $JHALFSDIR && make
[877cc6a]412 echo -ne "done\n"
413 fi
414 fi
415}
416
417
418#----------------------------#
[261eea6]419clean_builddir() { #
[877cc6a]420#----------------------------#
421 # Test if the clean must be done.
[401f81e]422 if [ "${CLEAN}" = "y" ]; then
[877cc6a]423 # Test to make sure we're running the clean as root
424 if [ "$UID" != "0" ] ; then
425 echo "You must be logged in as root to clean the build directory."
426 exit 1
427 fi
428 # Test to make sure that the build directory was populated by jhalfs
429 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
[73e5448]430 echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
[877cc6a]431 exit 1
432 else
433 # Clean the build directory
434 echo -ne "Cleaning $BUILDDIR...\n"
435 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
436 echo -ne "Cleaning $JHALFSDIR...\n"
[dd29d02]437 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,*logs,Makefile,*.xsl,makefile-functions,pkg_tarball_list,*.config,*.sh}
[877cc6a]438 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
439 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
440 echo -ne "done\n"
441 fi
442 fi
443}
444
445#----------------------------#
[261eea6]446get_book() { #
[877cc6a]447#----------------------------#
448 cd $JHALFSDIR
449
[4da2512]450 if [ -z $WORKING_COPY ] ; then
[877cc6a]451 # Check for Subversion instead of just letting the script hit 'svn' and fail.
452 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
453 exit 1"
454 echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
455
456 case $PROGNAME in
457 lfs) svn_root="LFS" ;;
458 hlfs) svn_root="HLFS" ;;
459 clfs) svn_root="cross-lfs" ;;
[7432834]460 clfs2) svn_root="cross-lfs" ;;
[877cc6a]461 *) echo "BOOK not defined in function <get_book>"
462 exit 1 ;;
463 esac
464 # Grab a fresh book if it's missing, otherwise, update it from the
465 # repo. If we've already extracted the commands, move on to getting the
466 # sources.
467 if [ -d ${PROGNAME}-$LFSVRS ] ; then
468 cd ${PROGNAME}-$LFSVRS
[1ff6768]469 if LC_ALL=C svn up | grep -q At && \
470 test -d $JHALFSDIR/${PROGNAME}-commands && \
471 test -f $JHALFSDIR/pkg_tarball_list ; then
[877cc6a]472 # Set the canonical book version
[a6655ff]473 echo -ne "done\n"
[877cc6a]474 cd $JHALFSDIR
[1ff6768]475 case $PROGNAME in
[7432834]476 clfs | clfs2)
[1ff6768]477 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
478 *)
479 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
480 esac
[877cc6a]481 get_sources
482 else
483 echo -ne "done\n"
484 extract_commands
485 fi
486 else
[cb39f79]487 svn co $SVN/${svn_root}/${TREE} ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1
[877cc6a]488 echo -ne "done\n"
489 extract_commands
490 fi
[1ff6768]491
[877cc6a]492 else
493 echo -ne "Using $BOOK as book's sources ...\n"
494 extract_commands
495 fi
[a6655ff]496 echo -ne " Document version ${L_arrow}${BOLD}${VERSION}${R_arrow}\n"
[877cc6a]497}
498
499#----------------------------#
500extract_commands() { #
501#----------------------------#
502
503 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
504 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
505 exit 1"
506
507 cd $JHALFSDIR
[1ff6768]508 case $PROGNAME in
[7432834]509 clfs | clfs2 )
[1ff6768]510 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
511 *)
512 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
513 esac
[877cc6a]514
515 # Start clean
[bfc07d6]516 if [ -d ${PROGNAME}-commands ]; then
517 rm -rf ${PROGNAME}-commands
518 mkdir -v ${PROGNAME}-commands
[877cc6a]519 fi
520 echo -n "Extracting commands for"
521
522 # Dump the commands in shell script form from the HLFS book.
523 case ${PROGNAME} in
524 clfs)
525 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
526 xsltproc --nonet \
527 --xinclude \
528 --stringparam method $METHOD \
529 --stringparam testsuite $TEST \
[28f4756]530 --stringparam bomb-testsuite $BOMB_TEST \
[877cc6a]531 --stringparam vim-lang $VIMLANG \
532 --stringparam timezone $TIMEZONE \
533 --stringparam page $PAGE \
534 --stringparam lang $LANG \
535 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
536 ;;
[7432834]537
538 clfs2)
539 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
540 xsltproc --nonet \
541 --xinclude \
542 --stringparam vim-lang $VIMLANG \
543 --stringparam timezone $TIMEZONE \
544 --stringparam page $PAGE \
545 --stringparam lang $LANG \
546 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
547 ;;
[877cc6a]548 hlfs)
549 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
550 xsltproc --nonet \
551 --xinclude \
552 --stringparam model $MODEL \
553 --stringparam testsuite $TEST \
[28f4756]554 --stringparam bomb-testsuite $BOMB_TEST \
[877cc6a]555 --stringparam timezone $TIMEZONE \
556 --stringparam page $PAGE \
557 --stringparam lang $LANG \
558 --stringparam lc_all $LC_ALL \
559 --stringparam grsecurity_host $GRSECURITY_HOST \
560 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
561 ;;
562 lfs)
563 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
564 xsltproc --nonet \
565 --xinclude \
566 --stringparam testsuite $TEST \
[28f4756]567 --stringparam bomb-testsuite $BOMB_TEST \
[877cc6a]568 --stringparam vim-lang $VIMLANG \
569 --stringparam timezone $TIMEZONE \
570 --stringparam page $PAGE \
571 --stringparam lang $LANG \
572 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
573 ;;
[15cad16]574 *) exit 1 ;;
[877cc6a]575 esac
576
[4965fa8]577 [[ "${BLFS_TOOL}" = "y" ]] && copy_blfs_deps_scripts
578
[877cc6a]579 echo " ...OK"
580
581 # Make the scripts executable.
582 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
583
[15cad16]584 # Create the packages file. We need it for proper Makefile creation
[dd29d02]585 create_package_list
[877cc6a]586
587 # Done. Moving on...
588 get_sources
589}
590
[dd29d02]591#----------------------------#
592create_package_list() { #
593#----------------------------#
594
595 # Create the packages file. We need it for proper Makefile creation
596 rm -f pkg_tarball_list
597 echo -n "Creating <${PROGNAME}> list of tarball names for $BOOK $ARCH"
598 case ${PROGNAME} in
[7432834]599 clfs | clfs2)
[dd29d02]600 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
601 $BOOK/materials/${ARCH}-chapter.xml >>$LOGDIR/$LOG 2>&1
602 ;;
603 hlfs)
604 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
605 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
606 ;;
607 lfs)
608 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
609 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
610 ;;
611 esac
[4965fa8]612
613 if [[ "${BLFS_TOOL}" = "y" ]] ; then
614(
615cat << EOF
616$LIBXML_PKG
617$LIBXSLT_PKG
618$DBXSL_PKG
619$LINKS_PKG
620$SUDO_PKG
621$WGET_PKG
622$SVN_PKG
623$GPM_PKG
624EOF
625) >> pkg_tarball_list
626 fi
627
[dd29d02]628 echo " ...OK"
629
630}
631
632
[877cc6a]633#----------------------------#
[15cad16]634get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
[93135fd]635#----------------------------#
636 local saveIFS=$IFS
[26053c4]637 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE
[93135fd]638
639 # Test if the packages must be downloaded
[401f81e]640 [ ! "$GETPKG" = "y" ] && return
[93135fd]641
642 gs_wrt_message(){
643 echo "${RED}$1${OFF}"
[c7dbe78]644 echo "$1" >> MISSING_FILES.DMP
645 }
[93135fd]646 # Housekeeping
647 [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
648 cd $BUILDDIR/sources
649 [[ -f MD5SUMS ]] && rm MD5SUMS
650 [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
651 [[ -f urls.lst ]] && rm urls.lst
652
653 # Generate URLs file
654 create_urls
655
656 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
657 for line in `cat urls.lst`; do
658 IFS=$saveIFS # Restore the system defaults
659
660 # Skip some packages if they aren't needed
661 case $line in
662 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
663 [[ "$TEST" = "0" ]] && continue
664 ;;
665 */vim-*-lang* )
666 [[ "$VIMLANG" = "0" ]] && continue
667 ;;
[0c3f2f9]668 *linux/linux-* )
[294c937]669 [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
[401f81e]670 [[ "$GETKERNEL" = "n" ]] && continue
[0c3f2f9]671 ;;
[93135fd]672 esac
673
674 # Locations
[296ae69]675 URL1=`echo $line | cut -d" " -f2` # Preferred URL
676 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
[26053c4]677 FILE=`basename $URL1` # File name
678 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
679
[8a43b5b]680 # Validation pair
681 MD5="$BOOKMD5 $FILE"
682 HAVEMD5=1
[93135fd]683
684 set -e
[c7dbe78]685 # If the file exists in the archive copy it to the
[93135fd]686 # $BUILDDIR/sources dir. MD5SUM will be validated later.
687 if [ ! -z ${SRC_ARCHIVE} ] &&
688 [ -d ${SRC_ARCHIVE} ] &&
689 [ -f ${SRC_ARCHIVE}/$FILE ]; then
690 cp ${SRC_ARCHIVE}/$FILE .
691 echo "$FILE: -- copied from $SRC_ARCHIVE"
692 fromARCHIVE=1
693 else
694 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
695 fromARCHIVE=0
[8a43b5b]696 # If the file does not exist yet in /sources download a fresh one
[93135fd]697 if [ ! -f $FILE ] ; then
698 if ! wget $URL1 && ! wget $URL2 ; then
[c7dbe78]699 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
700 continue
[93135fd]701 fi
702 fi
703 fi
704
[8a43b5b]705 # IF the md5sum does not match the existing files
706 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
707 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
708 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
709 # Remove the old file and download a new one
710 rm -fv $FILE
711 # Force storage in SRC_ARCHIVE
712 fromARCHIVE=0;
713 # Try to retrieve again the file. Servers in reverse order.
714 if ! wget $URL2 && ! wget $URL1 ; then
715 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
716 continue
[93135fd]717 fi
718 fi
719
720 # Validate the MD5SUM one last time
[8a43b5b]721 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
[93135fd]722 gs_wrt_message "$FILE does not match MD5SUMS value"
[0910f55]723 # Force generation of MD5SUM
724 HAVEMD5=0
[93135fd]725 fi
726
727 # Generate a fresh MD5SUM for this file
728 if [[ "$HAVEMD5" = "0" ]] ; then
729 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
[8a43b5b]730 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
[93135fd]731 fi
732
733 # Good or bad we write the original md5sum to a file
[8a43b5b]734 echo "$MD5" >> MD5SUMS
[93135fd]735
736 # Copy the freshly downloaded file
737 # to the source archive.
738 if [ ! -z ${SRC_ARCHIVE} ] &&
739 [ -d ${SRC_ARCHIVE} ] &&
740 [ -w ${SRC_ARCHIVE} ] &&
741 [ "$fromARCHIVE" = "0" ] ; then
742 echo "Storing file:<$FILE> in the package archive"
743 cp -f $FILE ${SRC_ARCHIVE}
744 fi
745
746 done
747
748 if [[ -s MISSING_FILES.DMP ]]; then
[d385453]749 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"
750 # Do not allow the automatic execution of the Makefile.
[261eea6]751 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
[401f81e]752 RUNMAKE="n"
[93135fd]753 fi
754}
755
[877cc6a]756#----------------------------#
[15cad16]757create_urls() { #
[877cc6a]758#----------------------------#
[15cad16]759 cd $JHALFSDIR
[877cc6a]760
[15cad16]761 case ${PROGNAME} in
762 clfs)
763 echo -n "Creating CLFS <${ARCH}> specific URLs file"
764 xsltproc --nonet --xinclude \
765 --stringparam server $SERVER \
766 -o $BUILDDIR/sources/urls.lst urls.xsl \
767 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
768 echo " ...OK"
769 ;;
[7432834]770 clfs2)
771 echo -n "Creating CLFS2 <${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 ;;
[15cad16]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
[4965fa8]798
[05d1b17]799 if [[ "${BLFS_TOOL}" = "y" ]]; then
800 add_blfs_deps_urls
801 fi
[4965fa8]802}
803
804#----------------------------# Hardcoded URLs and MD5.
805add_blfs_deps_urls() { # No easy way to extract it.
806#----------------------------# Some FTP mirrors may not work
807
808 local BLFS_SERVER="${SERVER}/pub/blfs/conglomeration/"
809
810 if [[ "${DEP_LIBXML}" = "y" ]] ; then
811 echo "${LIBXML_URL} ${BLFS_SERVER}libxml2/${LIBXML_PKG} ${LIBXML_MD5}" >> urls.lst
812 fi
813
814 if [[ "${DEP_LIBXSLT}" = "y" ]] ; then
815 echo "${LIBXSLT_URL} ${BLFS_SERVER}libxslt/${LIBXSLT_PKG} ${LIBXSLT_MD5}" >> urls.lst
816 fi
817
818 if [[ "${DEP_DBXSL}" = "y" ]] ; then
819 echo "${DBXSL_URL} ${BLFS_SERVER}docbook-xsl/${DBXSL_PKG} ${DBXSL_MD5}" >> urls.lst
820 fi
821
822 if [[ "${DEP_LINKS}" = "y" ]] ; then
823 echo "${LINKS_URL} ${BLFS_SERVER}links/${LINKS_PKG} ${LINKS_MD5}" >> urls.lst
824 fi
825
826 if [[ "${DEP_SUDO}" = "y" ]] ; then
827 echo "${SUDO_URL} ${BLFS_SERVER}sudo/${SUDO_PKG} ${SUDO_MD5}" >> urls.lst
828 echo "${SUDO_PATCH_URL} ${BLFS_SERVER}sudo/${SUDO_PATCH} ${SUDO_PATCH_MD5}" >> urls.lst
829 fi
830
831 if [[ "${DEP_WGET}" = "y" ]] ; then
832 echo "${WGET_URL} ${BLFS_SERVER}wget/${WGET_PKG} ${WGET_MD5}" >> urls.lst
833 fi
834
835 if [[ "${DEP_SVN}" = "y" ]] ; then
836 echo "${SVN_URL} ${BLFS_SERVER}subversion/${SVN_PKG} ${SVN_MD5}" >> urls.lst
837 fi
838
839 if [[ "${DEP_GPM}" = "y" ]] ; then
840 echo "${GPM_URL} ${BLFS_SERVER}gpm/${GPM_PKG} ${GPM_MD5}" >> urls.lst
841 echo "${GPM_PATCH_1_URL} ${BLFS_SERVER}gpm/${GPM_PATCH_1} ${GPM_PATCH_1_MD5}" >> urls.lst
842 echo "${GPM_PATCH_2_URL} ${BLFS_SERVER}gpm/${GPM_PATCH_2} ${GPM_PATCH_2_MD5}" >> urls.lst
843 fi
844
845}
846
847#----------------------------# Maybe there is a better way to do this, but this
848copy_blfs_deps_scripts() { # method avoid to place the test on all
849#----------------------------# $PROGNAME/master.sh scripts.
850
851 mkdir -p ${PROGNAME}-commands/blfs-tool-deps
852
853 if [[ "${DEP_LIBXML}" = "y" ]] ; then
854 mv blfs-tool-deps/901-libxml2 ${PROGNAME}-commands/blfs-tool-deps
855 fi
856
857 if [[ "${DEP_LIBXSLT}" = "y" ]] ; then
858 mv blfs-tool-deps/902-libxslt ${PROGNAME}-commands/blfs-tool-deps
859 fi
860
861 if [[ "${DEP_DBXSL}" = "y" ]] ; then
862 mv blfs-tool-deps/903-docbook-xsl ${PROGNAME}-commands/blfs-tool-deps
863 fi
864
865 if [[ "${DEP_LINKS}" = "y" ]] ; then
866 mv blfs-tool-deps/905-links ${PROGNAME}-commands/blfs-tool-deps
867 fi
868
869 if [[ "${DEP_SUDO}" = "y" ]] ; then
870 mv blfs-tool-deps/906-sudo ${PROGNAME}-commands/blfs-tool-deps
871 fi
872
873 if [[ "${DEP_WGET}" = "y" ]] ; then
874 mv blfs-tool-deps/907-wget ${PROGNAME}-commands/blfs-tool-deps
875 fi
876
877 if [[ "${DEP_SVN}" = "y" ]] ; then
878 mv blfs-tool-deps/908-subversion ${PROGNAME}-commands/blfs-tool-deps
879 fi
880
881 if [[ "${DEP_GPM}" = "y" ]] ; then
882 mv blfs-tool-deps/904-gpm ${PROGNAME}-commands/blfs-tool-deps
883 fi
884
885 rm -rf blfs-tool-deps
886
[877cc6a]887}
Note: See TracBrowser for help on using the repository browser.