source: common/common-functions@ ee21f67

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

Small change required by customization support.

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