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
Line 
1#!/bin/bash
2
3# $Id$
4
5set -e
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
18 a different build directory before running jhalfs-X.
19${OFF}
20${DD_BORDER}
21-EOF-
22 exit
23}
24
25
26HEADER="# This file is automatically generated by jhalfs-X
27# DO NOT EDIT THIS FILE MANUALLY
28#
29# Generated on `date \"+%F %X %Z\"`"
30
31
32#------------------------------------------------------#
33# NEW Makefile scripting functions #
34#------------------------------------------------------#
35
36
37unset get_package_tarball_name
38#----------------------------------#
39get_package_tarball_name() { #
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
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 ;;
60 esac
61
62}
63
64
65unset wrt_RunaAsRoot
66#----------------------------------#
67wrt_RunAsRoot() { # Some scripts must be run as root..
68#----------------------------------#
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
82(
83cat << EOF
84 @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
85 \$(PRT_DU_CR) >>logs/\$@
86EOF
87) >> $MKFILE.tmp
88}
89
90
91#------------------------------------------------------#
92#------------------------------------------------------#
93
94#----------------------------------#
95ROOT_RunAsRoot() { #
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#------------------------------------------------------#
130
131#----------------------------------#
132LUSER_wrt_target() { # Create target and initialize log file
133#----------------------------------#
134 local i=$1
135 local PREV=$2
136(
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/\$@
143EOF
144) >> $MKFILE.tmp
145}
146
147
148#----------------------------------#
149LUSER_wrt_RunAsUser() { # Execute script inside time { }, footer to log file
150#----------------------------------#
151 local file=$1
152
153(
154cat << EOF
155 @( time { source ~/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\
156 \$(PRT_DU) >> logs/\$@
157EOF
158) >> $MKFILE.tmp
159}
160
161
162#----------------------------------#
163LUSER_wrt_unpack() { # Unpack and set 'ROOT' var
164#----------------------------------#
165 local FILE=$1
166 local optSAVE_PREVIOUS=$2
167
168 if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
169(
170cat << EOF
171 @\$(call remove_existing_dirs,$FILE)
172EOF
173) >> $MKFILE.tmp
174 fi
175
176(
177cat << EOF
178 @\$(call unpack,$FILE)
179 @\$(call get_pkg_root_LUSER)
180EOF
181) >> $MKFILE.tmp
182
183}
184
185
186#----------------------------------#
187LUSER_wrt_CopyFstab() { #
188#----------------------------------#
189(
190cat << EOF
191 @( time { cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@
192EOF
193) >> $MKFILE.tmp
194}
195
196
197#----------------------------------#
198LUSER_wrt_test_log() { # Initialize testsuite log file
199#----------------------------------#
200 local TESTLOGFILE=$1
201(
202cat << EOF
203 @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
204 echo -e '\n\`date\`\n' >$TESTLOGDIR/$TESTLOGFILE
205EOF
206) >> $MKFILE.tmp
207}
208
209
210#----------------------------------#
211LUSER_RemoveBuildDirs() { #
212#----------------------------------#
213 local name=$1
214(
215cat << EOF
216 @\$(call remove_build_dirs,$name)
217EOF
218) >> $MKFILE.tmp
219}
220
221#-----------------------------------------------------------------#
222#-----------------------------------------------------------------#
223
224#----------------------------------#
225CHROOT_wrt_target() { # Create target and initialize log file
226#----------------------------------#
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
233(
234cat << EOF
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
240EOF
241) >> $MKFILE.tmp
242}
243
244
245#----------------------------------#
246CHROOT_Unpack() { #
247#----------------------------------#
248 local FILE=$1
249 local optSAVE_PREVIOUS=$2
250
251 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
252(
253cat << EOF
254 @\$(call remove_existing_dirs2,$FILE)
255EOF
256) >> $MKFILE.tmp
257 fi
258(
259cat << EOF
260 @\$(call unpack3,$FILE)
261 @\$(call get_pkg_root2)
262EOF
263) >> $MKFILE.tmp
264}
265
266
267#----------------------------------#
268CHROOT_wrt_test_log() { #
269#----------------------------------#
270 local TESTLOGFILE=$1
271(
272cat << EOF
273 @echo "export TEST_LOG=/\$(SCRIPT_ROOT)/test-logs/$TESTLOGFILE" >> envars && \\
274 echo -e "\n\`date\`\n" >test-logs/$TESTLOGFILE
275EOF
276) >> $MKFILE.tmp
277}
278
279
280#----------------------------------#
281CHROOT_wrt_RunAsRoot() { #
282#----------------------------------#
283 local file=$1
284(
285cat << EOF
286 @( time { source envars && \$(crCMDSDIR)/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
287 \$(PRT_DU_CR) >>logs/$this_script
288EOF
289) >> $MKFILE.tmp
290
291}
292
293
294#----------------------------------#
295CHROOT_wrt_CopyFstab() { #
296#----------------------------------#
297(
298cat << EOF
299 @( time { cp -v /sources/fstab /etc/fstab >>logs/${this_script} 2>&1 ; } ) 2>>logs/${this_script}
300EOF
301) >> $MKFILE.tmp
302}
303
304
305#----------------------------------#
306CHROOT_wrt_RemoveBuildDirs() { #
307#----------------------------------#
308 local name=$1
309(
310cat << EOF
311 @\$(call remove_build_dirs2,$name)
312EOF
313) >> $MKFILE.tmp
314}
315
316
317unset wrt_touch
318#----------------------------------#
319wrt_touch() { #
320#----------------------------------#
321(
322cat << EOF
323 @\$(call housekeeping)
324EOF
325) >> $MKFILE.tmp
326}
327
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
392#------------------------------------------------------#
393# END Makefile scripting functions #
394#------------------------------------------------------#
395
396
397
398#----------------------------#
399run_make() { #
400#----------------------------#
401 # Test if make must be run.
402 if [ "$RUNMAKE" = "y" ] ; then
403 # Test to make sure we're running the build as root
404 if [ "$UID" = "0" ] ; then
405 echo "You must not be logged in as root to build the system."
406 exit 1
407 fi
408 # Build the system
409 if [ -e $MKFILE ] ; then
410 echo -ne "Building the system...\n"
411 cd $JHALFSDIR && make
412 echo -ne "done\n"
413 fi
414 fi
415}
416
417
418#----------------------------#
419clean_builddir() { #
420#----------------------------#
421 # Test if the clean must be done.
422 if [ "${CLEAN}" = "y" ]; then
423 # Test to make sure that the build directory was populated by jhalfs
424 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
425 echo "Looks like $BUILDDIR was not populated by a previous jhalfs-X run."
426 exit 1
427 else
428 # Clean the build directory
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"
438 fi
439 fi
440}
441
442#----------------------------#
443get_book() { #
444#----------------------------#
445 cd $JHALFSDIR
446
447 if [ -z $WORKING_COPY ] ; then
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" ;;
457 clfs2) svn_root="cross-lfs" ;;
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
466 if LC_ALL=C svn up | grep -q At && \
467 test -d $JHALFSDIR/${PROGNAME}-commands && \
468 test -f $JHALFSDIR/pkg_tarball_list ; then
469 # Set the canonical book version
470 echo -ne "done\n"
471 cd $JHALFSDIR
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
478 get_sources
479 else
480 echo -ne "done\n"
481 extract_commands
482 fi
483 else
484 svn co $SVN/${svn_root}/${TREE} ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1
485 echo -ne "done\n"
486 extract_commands
487 fi
488
489 else
490 echo -ne "Using $BOOK as book's sources ...\n"
491 extract_commands
492 fi
493 echo -ne " Document version ${L_arrow}${BOLD}${VERSION}${R_arrow}\n"
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
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
511
512 # Start clean
513 if [ -d ${PROGNAME}-commands ]; then
514 rm -rf ${PROGNAME}-commands
515 mkdir -v ${PROGNAME}-commands
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 \
527 --stringparam bomb-testsuite $BOMB_TEST \
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 ;;
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 ;;
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 \
551 --stringparam bomb-testsuite $BOMB_TEST \
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 \
564 --stringparam bomb-testsuite $BOMB_TEST \
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 ;;
571 *) exit 1 ;;
572 esac
573
574 [[ "${BLFS_TOOL}" = "y" ]] && copy_blfs_deps_scripts
575
576 echo " ...OK"
577
578 # Make the scripts executable.
579 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
580
581 # Create the packages file. We need it for proper Makefile creation
582 create_package_list
583
584 # Done. Moving on...
585 get_sources
586
587}
588
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
610
611 if [[ "${BLFS_TOOL}" = "y" ]] ; then
612(
613cat << EOF
614$LIBXML_PKG
615$LIBXSLT_PKG
616$TIDY_PKG
617$UNZIP_PKG
618$DBXML_PKG
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
629 echo " ...OK"
630
631}
632
633
634#----------------------------#
635get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
636#----------------------------#
637 local saveIFS=$IFS
638 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE
639
640 # Test if the packages must be downloaded
641 [ ! "$GETPKG" = "y" ] && return
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
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 ;;
669 *linux/linux-* )
670 [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
671 [[ "$GETKERNEL" = "n" ]] && continue
672 ;;
673 esac
674
675 # Locations
676 URL1=`echo $line | cut -d" " -f2` # Preferred URL
677 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
678 FILE=`basename $URL1` # File name
679 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
680
681 # Validation pair
682 MD5="$BOOKMD5 $FILE"
683 HAVEMD5=1
684
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
697 # If the file does not exist yet in /sources download a fresh one
698 if [ ! -f $FILE ] ; then
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
703 fi
704 fi
705
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
718 fi
719 fi
720
721 # Validate the MD5SUM one last time
722 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
723 gs_wrt_message "$FILE does not match MD5SUMS value"
724 # Force generation of MD5SUM
725 HAVEMD5=0
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"
731 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
732 fi
733
734 # Good or bad we write the original md5sum to a file
735 echo "$MD5" >> MD5SUMS
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
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.
752 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
753 RUNMAKE="n"
754 fi
755}
756
757#----------------------------#
758create_urls() { #
759#----------------------------#
760 cd $JHALFSDIR
761
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 ;;
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 ;;
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
797
798 cd $BUILDDIR/sources
799
800 if [[ "${BLFS_TOOL}" = "y" ]]; then
801 add_blfs_deps_urls
802 fi
803
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
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
823 echo "${TIDY_DOCS_URL} ${BLFS_SERVER}tidy/${TIDY_DOCS} ${TIDY_DOCS_MD5}" >> urls.lst
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
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
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
889 if [[ "${DEP_DBXSL}" = "y" ]] ; then
890 mv blfs-tool-deps/906-docbook-xsl ${PROGNAME}-commands/blfs-tool-deps
891 fi
892
893 if [[ "${DEP_LINKS}" = "y" ]] ; then
894 mv blfs-tool-deps/908-links ${PROGNAME}-commands/blfs-tool-deps
895 fi
896
897 if [[ "${DEP_SUDO}" = "y" ]] ; then
898 mv blfs-tool-deps/909-sudo ${PROGNAME}-commands/blfs-tool-deps
899 fi
900
901 if [[ "${DEP_WGET}" = "y" ]] ; then
902 mv blfs-tool-deps/910-wget ${PROGNAME}-commands/blfs-tool-deps
903 fi
904
905 if [[ "${DEP_SVN}" = "y" ]] ; then
906 mv blfs-tool-deps/911-subversion ${PROGNAME}-commands/blfs-tool-deps
907 fi
908
909 if [[ "${DEP_GPM}" = "y" ]] ; then
910 mv blfs-tool-deps/907-gpm ${PROGNAME}-commands/blfs-tool-deps
911 fi
912
913 rm -rf blfs-tool-deps
914
915}
Note: See TracBrowser for help on using the repository browser.