source: common/common-functions@ 8ed8336

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

Fixed clean_builddir()

  • Property mode set to 100644
File size: 26.1 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
[045b2dc]32#------------------------------------------------------#
33# NEW Makefile scripting functions #
34#------------------------------------------------------#
[877cc6a]35
[7eb9402]36
[045b2dc]37unset get_package_tarball_name
[7eb9402]38#----------------------------------#
[045b2dc]39get_package_tarball_name() { #
[7eb9402]40#----------------------------------#
[dd29d02]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
[64c9caf]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 ;;
[5468631]58 *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 )
[64c9caf]59 ;;
[dd29d02]60 esac
61
62}
[877cc6a]63
[401f81e]64
[045b2dc]65unset wrt_RunaAsRoot
[5842156]66#----------------------------------#
[045b2dc]67wrt_RunAsRoot() { # Some scripts must be run as root..
[5842156]68#----------------------------------#
[045b2dc]69 local ENV_MOUNT
70 local this_script=$1
71 local file=$2
72
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" ;;
79 *) echo "undefined progname $PROGNAME"; exit 1 ;;
80 esac
81
[5842156]82(
[045b2dc]83cat << EOF
84 @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
85 \$(PRT_DU_CR) >>logs/\$@
[5842156]86EOF
87) >> $MKFILE.tmp
88}
89
[045b2dc]90
91#------------------------------------------------------#
92#------------------------------------------------------#
93
[5842156]94#----------------------------------#
[045b2dc]95ROOT_RunAsRoot() { #
[5842156]96#----------------------------------#
[045b2dc]97 local file=$1
[5842156]98(
[045b2dc]99cat << EOF
100 @( time { source envars && \$(CMDSDIR)/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
101 \$(PRT_DU_CR) >>logs/$this_script
[401f81e]102EOF
103) >> $MKFILE.tmp
104}
105
106#----------------------------------#
[045b2dc]107ROOT_Unpack() { # An alias, for clairity
[401f81e]108#----------------------------------#
[045b2dc]109 local FILE=$1
110 local optSAVE_PREVIOUS=$2
111
112 if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
[401f81e]113(
[045b2dc]114cat << EOF
115 @\$(call remove_existing_dirs,$FILE)
[401f81e]116EOF
117) >> $MKFILE.tmp
[045b2dc]118 fi
[401f81e]119
120(
[045b2dc]121cat << EOF
122 @\$(call unpack,$FILE)
123 @\$(call get_pkg_root_LUSER)
[401f81e]124EOF
125) >> $MKFILE.tmp
126}
127
[045b2dc]128#------------------------------------------------------#
129#------------------------------------------------------#
[401f81e]130
131#----------------------------------#
[045b2dc]132LUSER_wrt_target() { # Create target and initialize log file
[401f81e]133#----------------------------------#
134 local i=$1
[045b2dc]135 local PREV=$2
[401f81e]136(
[045b2dc]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/\$@
[5842156]143EOF
144) >> $MKFILE.tmp
145}
146
147
[401f81e]148#----------------------------------#
[045b2dc]149LUSER_wrt_RunAsUser() { # Execute script inside time { }, footer to log file
[401f81e]150#----------------------------------#
[045b2dc]151 local file=$1
152
[401f81e]153(
154cat << EOF
[045b2dc]155 @( time { source ~/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\
156 \$(PRT_DU) >> logs/\$@
[401f81e]157EOF
158) >> $MKFILE.tmp
159}
160
[045b2dc]161
[877cc6a]162#----------------------------------#
[045b2dc]163LUSER_wrt_unpack() { # Unpack and set 'ROOT' var
[877cc6a]164#----------------------------------#
165 local FILE=$1
[5842156]166 local optSAVE_PREVIOUS=$2
[82eb8c1]167
[401f81e]168 if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
169(
170cat << EOF
171 @\$(call remove_existing_dirs,$FILE)
172EOF
173) >> $MKFILE.tmp
[5842156]174 fi
[401f81e]175
[877cc6a]176(
177cat << EOF
178 @\$(call unpack,$FILE)
[045b2dc]179 @\$(call get_pkg_root_LUSER)
[e5f5970]180EOF
181) >> $MKFILE.tmp
182
[401f81e]183}
[e5f5970]184
[045b2dc]185
[877cc6a]186#----------------------------------#
[045b2dc]187LUSER_wrt_CopyFstab() { #
[877cc6a]188#----------------------------------#
[401f81e]189(
190cat << EOF
[045b2dc]191 @( time { cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@
[877cc6a]192EOF
193) >> $MKFILE.tmp
194}
195
[045b2dc]196
[261eea6]197#----------------------------------#
[045b2dc]198LUSER_wrt_test_log() { # Initialize testsuite log file
[261eea6]199#----------------------------------#
[045b2dc]200 local TESTLOGFILE=$1
[877cc6a]201(
202cat << EOF
[045b2dc]203 @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
204 echo -e '\n\`date\`\n' >$TESTLOGDIR/$TESTLOGFILE
[877cc6a]205EOF
206) >> $MKFILE.tmp
207}
208
[401f81e]209
[a229600]210#----------------------------------#
[045b2dc]211LUSER_RemoveBuildDirs() { #
[a229600]212#----------------------------------#
[401f81e]213 local name=$1
[a229600]214(
[401f81e]215cat << EOF
216 @\$(call remove_build_dirs,$name)
[a229600]217EOF
218) >> $MKFILE.tmp
219}
220
[045b2dc]221#-----------------------------------------------------------------#
222#-----------------------------------------------------------------#
223
[a229600]224#----------------------------------#
[045b2dc]225CHROOT_wrt_target() { # Create target and initialize log file
[a229600]226#----------------------------------#
[045b2dc]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
[a229600]233(
[401f81e]234cat << EOF
[045b2dc]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
[a229600]240EOF
241) >> $MKFILE.tmp
242}
243
[401f81e]244
[877cc6a]245#----------------------------------#
[045b2dc]246CHROOT_Unpack() { #
[877cc6a]247#----------------------------------#
[045b2dc]248 local FILE=$1
249 local optSAVE_PREVIOUS=$2
250
251 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
[877cc6a]252(
[401f81e]253cat << EOF
[045b2dc]254 @\$(call remove_existing_dirs2,$FILE)
[877cc6a]255EOF
256) >> $MKFILE.tmp
[045b2dc]257 fi
[877cc6a]258(
[045b2dc]259cat << EOF
260 @\$(call unpack3,$FILE)
261 @\$(call get_pkg_root2)
[877cc6a]262EOF
263) >> $MKFILE.tmp
264}
265
266
[e5f5970]267#----------------------------------#
[045b2dc]268CHROOT_wrt_test_log() { #
[e5f5970]269#----------------------------------#
[045b2dc]270 local TESTLOGFILE=$1
[ac1d897]271(
[045b2dc]272cat << EOF
273 @echo "export TEST_LOG=/\$(SCRIPT_ROOT)/test-logs/$TESTLOGFILE" >> envars && \\
274 echo -e "\n\`date\`\n" >test-logs/$TESTLOGFILE
[ac1d897]275EOF
276) >> $MKFILE.tmp
277}
278
[045b2dc]279
[261eea6]280#----------------------------------#
[045b2dc]281CHROOT_wrt_RunAsRoot() { #
[261eea6]282#----------------------------------#
[045b2dc]283 local file=$1
[877cc6a]284(
285cat << EOF
[045b2dc]286 @( time { source envars && \$(crCMDSDIR)/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
287 \$(PRT_DU_CR) >>logs/$this_script
[877cc6a]288EOF
289) >> $MKFILE.tmp
[045b2dc]290
[877cc6a]291}
292
293
294#----------------------------------#
[045b2dc]295CHROOT_wrt_CopyFstab() { #
[877cc6a]296#----------------------------------#
297(
[401f81e]298cat << EOF
[045b2dc]299 @( time { cp -v /sources/fstab /etc/fstab >>logs/${this_script} 2>&1 ; } ) 2>>logs/${this_script}
[877cc6a]300EOF
301) >> $MKFILE.tmp
302}
303
[045b2dc]304
[877cc6a]305#----------------------------------#
[045b2dc]306CHROOT_wrt_RemoveBuildDirs() { #
[877cc6a]307#----------------------------------#
[045b2dc]308 local name=$1
[877cc6a]309(
310cat << EOF
[045b2dc]311 @\$(call remove_build_dirs2,$name)
[877cc6a]312EOF
313) >> $MKFILE.tmp
314}
315
[045b2dc]316
317unset wrt_touch
[877cc6a]318#----------------------------------#
[045b2dc]319wrt_touch() { #
[877cc6a]320#----------------------------------#
[0bdf6ed]321(
322cat << EOF
[045b2dc]323 @\$(call housekeeping)
[e2ef100]324EOF
325) >> $MKFILE.tmp
326}
327
[045b2dc]328
[453bef0]329#----------------------------------#
[045b2dc]330wrt_blfs_tool_targets() { #
[453bef0]331#----------------------------------#
332
[045b2dc]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
[453bef0]390}
391
[045b2dc]392#------------------------------------------------------#
393# END Makefile scripting functions #
394#------------------------------------------------------#
395
[453bef0]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
[045b2dc]404 if [ "$UID" = "0" ] ; then
405 echo "You must not be logged in as root to build the system."
[877cc6a]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 that the build directory was populated by jhalfs
424 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
[5468631]425 echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
[877cc6a]426 exit 1
427 else
428 # Clean the build directory
[5468631]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"
[877cc6a]438 fi
439 fi
440}
441
442#----------------------------#
[261eea6]443get_book() { #
[877cc6a]444#----------------------------#
445 cd $JHALFSDIR
446
[4da2512]447 if [ -z $WORKING_COPY ] ; then
[877cc6a]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" ;;
[7432834]457 clfs2) svn_root="cross-lfs" ;;
[877cc6a]458 *) echo "BOOK not defined in function <get_book>"
459 exit 1 ;;
460 esac
461 # Grab a fresh book if it's missing, otherwise, update it from the
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
[1ff6768]466 if LC_ALL=C svn up | grep -q At && \
467 test -d $JHALFSDIR/${PROGNAME}-commands && \
468 test -f $JHALFSDIR/pkg_tarball_list ; then
[877cc6a]469 # Set the canonical book version
[a6655ff]470 echo -ne "done\n"
[877cc6a]471 cd $JHALFSDIR
[1ff6768]472 case $PROGNAME in
[7432834]473 clfs | clfs2)
[1ff6768]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
[877cc6a]478 get_sources
479 else
480 echo -ne "done\n"
481 extract_commands
482 fi
483 else
[cb39f79]484 svn co $SVN/${svn_root}/${TREE} ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1
[877cc6a]485 echo -ne "done\n"
486 extract_commands
487 fi
[1ff6768]488
[877cc6a]489 else
490 echo -ne "Using $BOOK as book's sources ...\n"
491 extract_commands
492 fi
[a6655ff]493 echo -ne " Document version ${L_arrow}${BOLD}${VERSION}${R_arrow}\n"
[877cc6a]494}
495
496#----------------------------#
497extract_commands() { #
498#----------------------------#
499
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
[1ff6768]505 case $PROGNAME in
[7432834]506 clfs | clfs2 )
[1ff6768]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
[877cc6a]511
512 # Start clean
[bfc07d6]513 if [ -d ${PROGNAME}-commands ]; then
514 rm -rf ${PROGNAME}-commands
515 mkdir -v ${PROGNAME}-commands
[877cc6a]516 fi
517 echo -n "Extracting commands for"
518
519 # Dump the commands in shell script form from the HLFS book.
520 case ${PROGNAME} in
521 clfs)
522 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
523 xsltproc --nonet \
524 --xinclude \
525 --stringparam method $METHOD \
526 --stringparam testsuite $TEST \
[28f4756]527 --stringparam bomb-testsuite $BOMB_TEST \
[877cc6a]528 --stringparam vim-lang $VIMLANG \
529 --stringparam timezone $TIMEZONE \
530 --stringparam page $PAGE \
531 --stringparam lang $LANG \
532 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
533 ;;
[7432834]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 ;;
[877cc6a]545 hlfs)
546 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
547 xsltproc --nonet \
548 --xinclude \
549 --stringparam model $MODEL \
550 --stringparam testsuite $TEST \
[28f4756]551 --stringparam bomb-testsuite $BOMB_TEST \
[877cc6a]552 --stringparam timezone $TIMEZONE \
553 --stringparam page $PAGE \
554 --stringparam lang $LANG \
555 --stringparam lc_all $LC_ALL \
556 --stringparam grsecurity_host $GRSECURITY_HOST \
557 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
558 ;;
559 lfs)
560 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
561 xsltproc --nonet \
562 --xinclude \
563 --stringparam testsuite $TEST \
[28f4756]564 --stringparam bomb-testsuite $BOMB_TEST \
[877cc6a]565 --stringparam vim-lang $VIMLANG \
566 --stringparam timezone $TIMEZONE \
567 --stringparam page $PAGE \
568 --stringparam lang $LANG \
569 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
570 ;;
[15cad16]571 *) exit 1 ;;
[877cc6a]572 esac
573
[4965fa8]574 [[ "${BLFS_TOOL}" = "y" ]] && copy_blfs_deps_scripts
575
[877cc6a]576 echo " ...OK"
577
578 # Make the scripts executable.
579 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
580
[15cad16]581 # Create the packages file. We need it for proper Makefile creation
[dd29d02]582 create_package_list
[877cc6a]583
584 # Done. Moving on...
585 get_sources
[045b2dc]586
[877cc6a]587}
588
[dd29d02]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
[7432834]597 clfs | clfs2)
[dd29d02]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
[4965fa8]610
611 if [[ "${BLFS_TOOL}" = "y" ]] ; then
612(
613cat << EOF
614$LIBXML_PKG
615$LIBXSLT_PKG
[045b2dc]616$TIDY_PKG
617$UNZIP_PKG
618$DBXML_PKG
[4965fa8]619$DBXSL_PKG
620$LINKS_PKG
621$SUDO_PKG
622$WGET_PKG
623$SVN_PKG
624$GPM_PKG
625EOF
626) >> pkg_tarball_list
627 fi
628
[dd29d02]629 echo " ...OK"
630
631}
632
633
[877cc6a]634#----------------------------#
[15cad16]635get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
[93135fd]636#----------------------------#
637 local saveIFS=$IFS
[26053c4]638 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE
[93135fd]639
640 # Test if the packages must be downloaded
[401f81e]641 [ ! "$GETPKG" = "y" ] && return
[93135fd]642
643 gs_wrt_message(){
644 echo "${RED}$1${OFF}"
[c7dbe78]645 echo "$1" >> MISSING_FILES.DMP
646 }
[93135fd]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
653
654 # Generate URLs file
655 create_urls
656
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
660
661 # Skip some packages if they aren't needed
662 case $line in
663 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
664 [[ "$TEST" = "0" ]] && continue
665 ;;
666 */vim-*-lang* )
667 [[ "$VIMLANG" = "0" ]] && continue
668 ;;
[0c3f2f9]669 *linux/linux-* )
[294c937]670 [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
[401f81e]671 [[ "$GETKERNEL" = "n" ]] && continue
[0c3f2f9]672 ;;
[93135fd]673 esac
674
675 # Locations
[296ae69]676 URL1=`echo $line | cut -d" " -f2` # Preferred URL
677 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
[26053c4]678 FILE=`basename $URL1` # File name
679 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
680
[8a43b5b]681 # Validation pair
682 MD5="$BOOKMD5 $FILE"
683 HAVEMD5=1
[93135fd]684
685 set -e
[c7dbe78]686 # If the file exists in the archive copy it to the
[93135fd]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
[8a43b5b]697 # If the file does not exist yet in /sources download a fresh one
[93135fd]698 if [ ! -f $FILE ] ; then
699 if ! wget $URL1 && ! wget $URL2 ; then
[c7dbe78]700 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
701 continue
[93135fd]702 fi
703 fi
704 fi
705
[8a43b5b]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
[93135fd]718 fi
719 fi
720
721 # Validate the MD5SUM one last time
[8a43b5b]722 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
[93135fd]723 gs_wrt_message "$FILE does not match MD5SUMS value"
[0910f55]724 # Force generation of MD5SUM
725 HAVEMD5=0
[93135fd]726 fi
727
728 # Generate a fresh MD5SUM for this file
729 if [[ "$HAVEMD5" = "0" ]] ; then
730 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
[8a43b5b]731 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
[93135fd]732 fi
733
734 # Good or bad we write the original md5sum to a file
[8a43b5b]735 echo "$MD5" >> MD5SUMS
[93135fd]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
[d385453]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.
[261eea6]752 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
[401f81e]753 RUNMAKE="n"
[93135fd]754 fi
755}
756
[877cc6a]757#----------------------------#
[15cad16]758create_urls() { #
[877cc6a]759#----------------------------#
[15cad16]760 cd $JHALFSDIR
[877cc6a]761
[15cad16]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 ;;
[7432834]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 ;;
[15cad16]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
[877cc6a]797
[15cad16]798 cd $BUILDDIR/sources
[4965fa8]799
[05d1b17]800 if [[ "${BLFS_TOOL}" = "y" ]]; then
801 add_blfs_deps_urls
802 fi
[045b2dc]803
[4965fa8]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
813 echo "${LIBXML_URL} ${BLFS_SERVER}libxml2/${LIBXML_PKG} ${LIBXML_MD5}" >> urls.lst
814 fi
815
816 if [[ "${DEP_LIBXSLT}" = "y" ]] ; then
817 echo "${LIBXSLT_URL} ${BLFS_SERVER}libxslt/${LIBXSLT_PKG} ${LIBXSLT_MD5}" >> urls.lst
818 fi
819
[045b2dc]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
[cbc8ba2]823 echo "${TIDY_DOCS_URL} ${BLFS_SERVER}tidy/${TIDY_DOCS} ${TIDY_DOCS_MD5}" >> urls.lst
[045b2dc]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
831 echo "${DBXML_URL} ${BLFS_SERVER}docbook-xml/${DBXML_PKG} ${DBXML_MD5}" >> urls.lst
832 fi
833
[4965fa8]834 if [[ "${DEP_DBXSL}" = "y" ]] ; then
835 echo "${DBXSL_URL} ${BLFS_SERVER}docbook-xsl/${DBXSL_PKG} ${DBXSL_MD5}" >> urls.lst
836 fi
837
838 if [[ "${DEP_LINKS}" = "y" ]] ; then
839 echo "${LINKS_URL} ${BLFS_SERVER}links/${LINKS_PKG} ${LINKS_MD5}" >> urls.lst
840 fi
841
842 if [[ "${DEP_SUDO}" = "y" ]] ; then
843 echo "${SUDO_URL} ${BLFS_SERVER}sudo/${SUDO_PKG} ${SUDO_MD5}" >> urls.lst
844 echo "${SUDO_PATCH_URL} ${BLFS_SERVER}sudo/${SUDO_PATCH} ${SUDO_PATCH_MD5}" >> urls.lst
845 fi
846
847 if [[ "${DEP_WGET}" = "y" ]] ; then
848 echo "${WGET_URL} ${BLFS_SERVER}wget/${WGET_PKG} ${WGET_MD5}" >> urls.lst
849 fi
850
851 if [[ "${DEP_SVN}" = "y" ]] ; then
852 echo "${SVN_URL} ${BLFS_SERVER}subversion/${SVN_PKG} ${SVN_MD5}" >> urls.lst
853 fi
854
855 if [[ "${DEP_GPM}" = "y" ]] ; then
856 echo "${GPM_URL} ${BLFS_SERVER}gpm/${GPM_PKG} ${GPM_MD5}" >> urls.lst
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
859 fi
860
861}
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
[045b2dc]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
[4965fa8]889 if [[ "${DEP_DBXSL}" = "y" ]] ; then
[045b2dc]890 mv blfs-tool-deps/906-docbook-xsl ${PROGNAME}-commands/blfs-tool-deps
[4965fa8]891 fi
892
893 if [[ "${DEP_LINKS}" = "y" ]] ; then
[045b2dc]894 mv blfs-tool-deps/908-links ${PROGNAME}-commands/blfs-tool-deps
[4965fa8]895 fi
896
897 if [[ "${DEP_SUDO}" = "y" ]] ; then
[045b2dc]898 mv blfs-tool-deps/909-sudo ${PROGNAME}-commands/blfs-tool-deps
[4965fa8]899 fi
900
901 if [[ "${DEP_WGET}" = "y" ]] ; then
[045b2dc]902 mv blfs-tool-deps/910-wget ${PROGNAME}-commands/blfs-tool-deps
[4965fa8]903 fi
904
905 if [[ "${DEP_SVN}" = "y" ]] ; then
[045b2dc]906 mv blfs-tool-deps/911-subversion ${PROGNAME}-commands/blfs-tool-deps
[4965fa8]907 fi
908
909 if [[ "${DEP_GPM}" = "y" ]] ; then
[045b2dc]910 mv blfs-tool-deps/907-gpm ${PROGNAME}-commands/blfs-tool-deps
[4965fa8]911 fi
912
913 rm -rf blfs-tool-deps
914
[877cc6a]915}
Note: See TracBrowser for help on using the repository browser.