source: common/common-functions@ 2ee1d11

experimental
Last change on this file since 2ee1d11 was 2ee1d11, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Merged r3147:3173 from trunk.

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