source: common/common-functions@ fd7455c

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

Added function to write blfs-tool dependencies targets

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