source: common/common-functions@ 4fb2c33

experimental
Last change on this file since 4fb2c33 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
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 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 ) ;;
50 esac
51
52}
53
54
55unset wrt_RunaAsRoot
56#----------------------------------#
57wrt_RunAsRoot() { # Some scripts must be run as root..
58#----------------------------------#
59 local ENV_MOUNT
60 local this_script=$1
61 local file=$2
62
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" ;;
69 *) echo "undefined progname $PROGNAME"; exit 1 ;;
70 esac
71
72(
73cat << EOF
74 @( time { export ${MOUNT_ENV}=\$(MOUNT_PT) && ${PROGNAME}-commands/`dirname $file`/\$@ >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@ && \\
75 \$(PRT_DU_CR) >>logs/\$@
76EOF
77) >> $MKFILE.tmp
78}
79
80
81#------------------------------------------------------#
82#------------------------------------------------------#
83
84#----------------------------------#
85ROOT_RunAsRoot() { #
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#------------------------------------------------------#
120
121#----------------------------------#
122LUSER_wrt_target() { # Create target and initialize log file
123#----------------------------------#
124 local i=$1
125 local PREV=$2
126(
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/\$@
133EOF
134) >> $MKFILE.tmp
135}
136
137
138#----------------------------------#
139LUSER_wrt_RunAsUser() { # Execute script inside time { }, footer to log file
140#----------------------------------#
141 local file=$1
142
143(
144cat << EOF
145 @( time { source ~/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@ >> logs/\$@ 2>&1; } ) 2>> logs/\$@ && \\
146 \$(PRT_DU) >> logs/\$@
147EOF
148) >> $MKFILE.tmp
149}
150
151
152#----------------------------------#
153LUSER_wrt_unpack() { # Unpack and set 'ROOT' var
154#----------------------------------#
155 local FILE=$1
156 local optSAVE_PREVIOUS=$2
157
158 if [[ "${optSAVE_PREVIOUS}" != "1" ]]; then
159(
160cat << EOF
161 @\$(call remove_existing_dirs,$FILE)
162EOF
163) >> $MKFILE.tmp
164 fi
165
166(
167cat << EOF
168 @\$(call unpack,$FILE)
169 @\$(call get_pkg_root_LUSER)
170EOF
171) >> $MKFILE.tmp
172
173}
174
175
176#----------------------------------#
177LUSER_wrt_CopyFstab() { #
178#----------------------------------#
179(
180cat << EOF
181 @( time { cp -v \$(MOUNT_PT)/sources/fstab \$(MOUNT_PT)/etc/fstab >>logs/\$@ 2>&1 ; } ) 2>>logs/\$@
182EOF
183) >> $MKFILE.tmp
184}
185
186
187#----------------------------------#
188LUSER_wrt_test_log() { # Initialize testsuite log file
189#----------------------------------#
190 local TESTLOGFILE=$1
191(
192cat << EOF
193 @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
194 echo -e '\n\`date\`\n' >$TESTLOGDIR/$TESTLOGFILE
195EOF
196) >> $MKFILE.tmp
197}
198
199
200#----------------------------------#
201LUSER_RemoveBuildDirs() { #
202#----------------------------------#
203 local name=$1
204(
205cat << EOF
206 @\$(call remove_build_dirs,$name)
207EOF
208) >> $MKFILE.tmp
209}
210
211#-----------------------------------------------------------------#
212#-----------------------------------------------------------------#
213
214#----------------------------------#
215CHROOT_wrt_target() { # Create target and initialize log file
216#----------------------------------#
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
223(
224cat << EOF
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
230EOF
231) >> $MKFILE.tmp
232}
233
234
235#----------------------------------#
236CHROOT_Unpack() { #
237#----------------------------------#
238 local FILE=$1
239 local optSAVE_PREVIOUS=$2
240
241 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
242(
243cat << EOF
244 @\$(call remove_existing_dirs2,$FILE)
245EOF
246) >> $MKFILE.tmp
247 fi
248(
249cat << EOF
250 @\$(call unpack3,$FILE)
251 @\$(call get_pkg_root2)
252EOF
253) >> $MKFILE.tmp
254}
255
256
257#----------------------------------#
258CHROOT_wrt_test_log() { #
259#----------------------------------#
260 local TESTLOGFILE=$1
261(
262cat << EOF
263 @echo "export TEST_LOG=/\$(SCRIPT_ROOT)/test-logs/$TESTLOGFILE" >> envars && \\
264 echo -e "\n\`date\`\n" >test-logs/$TESTLOGFILE
265EOF
266) >> $MKFILE.tmp
267}
268
269
270#----------------------------------#
271CHROOT_wrt_RunAsRoot() { #
272#----------------------------------#
273 local file=$1
274(
275cat << EOF
276 @( time { source envars && \$(crCMDSDIR)/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
277 \$(PRT_DU_CR) >>logs/$this_script
278EOF
279) >> $MKFILE.tmp
280
281}
282
283
284#----------------------------------#
285CHROOT_wrt_CopyFstab() { #
286#----------------------------------#
287(
288cat << EOF
289 @( time { cp -v /sources/fstab /etc/fstab >>logs/${this_script} 2>&1 ; } ) 2>>logs/${this_script}
290EOF
291) >> $MKFILE.tmp
292}
293
294
295#----------------------------------#
296CHROOT_wrt_RemoveBuildDirs() { #
297#----------------------------------#
298 local name=$1
299(
300cat << EOF
301 @\$(call remove_build_dirs2,$name)
302EOF
303) >> $MKFILE.tmp
304}
305
306
307unset wrt_touch
308#----------------------------------#
309wrt_touch() { #
310#----------------------------------#
311(
312cat << EOF
313 @\$(call housekeeping)
314EOF
315) >> $MKFILE.tmp
316}
317
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
382#------------------------------------------------------#
383# END Makefile scripting functions #
384#------------------------------------------------------#
385
386
387
388#----------------------------#
389run_make() { #
390#----------------------------#
391 # Test if make must be run.
392 if [ "$RUNMAKE" = "y" ] ; then
393 # Test to make sure we're running the build as root
394 if [ "$UID" = "0" ] ; then
395 echo "You must not be logged in as root to build the system."
396 exit 1
397 fi
398 # Build the system
399 if [ -e $MKFILE ] ; then
400 echo -ne "Building the system...\n"
401 cd $JHALFSDIR && make
402 echo -ne "done\n"
403 fi
404 fi
405}
406
407
408#----------------------------#
409clean_builddir() { #
410#----------------------------#
411 # Test if the clean must be done.
412 if [ "${CLEAN}" = "y" ]; then
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
420 echo "Looks like $BUILDDIR was not populated by a previous jhalfs-X run."
421 exit 1
422 else
423 # Clean the build directory
424 echo -ne "Cleaning $BUILDDIR...\n"
425 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
426 echo -ne "Cleaning $JHALFSDIR...\n"
427 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,*logs,Makefile,*.xsl,makefile-functions,pkg_tarball_list,*.config,*.sh}
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#----------------------------#
436get_book() { #
437#----------------------------#
438 cd $JHALFSDIR
439
440 if [ -z $WORKING_COPY ] ; then
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" ;;
450 clfs2) svn_root="cross-lfs" ;;
451 *) echo "BOOK not defined in function <get_book>"
452 exit 1 ;;
453 esac
454 # Grab a fresh book if it's missing, otherwise, update it from the
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
459 if LC_ALL=C svn up | grep -q At && \
460 test -d $JHALFSDIR/${PROGNAME}-commands && \
461 test -f $JHALFSDIR/pkg_tarball_list ; then
462 # Set the canonical book version
463 echo -ne "done\n"
464 cd $JHALFSDIR
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
471 get_sources
472 else
473 echo -ne "done\n"
474 extract_commands
475 fi
476 else
477 svn co $SVN/${svn_root}/${TREE} ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1
478 echo -ne "done\n"
479 extract_commands
480 fi
481
482 else
483 echo -ne "Using $BOOK as book's sources ...\n"
484 extract_commands
485 fi
486 echo -ne " Document version ${L_arrow}${BOLD}${VERSION}${R_arrow}\n"
487}
488
489#----------------------------#
490extract_commands() { #
491#----------------------------#
492
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
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
504
505 # Start clean
506 if [ -d ${PROGNAME}-commands ]; then
507 rm -rf ${PROGNAME}-commands
508 mkdir -v ${PROGNAME}-commands
509 fi
510 echo -n "Extracting commands for"
511
512 # Dump the commands in shell script form from the HLFS book.
513 case ${PROGNAME} in
514 clfs)
515 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
516 xsltproc --nonet \
517 --xinclude \
518 --stringparam method $METHOD \
519 --stringparam testsuite $TEST \
520 --stringparam bomb-testsuite $BOMB_TEST \
521 --stringparam vim-lang $VIMLANG \
522 --stringparam timezone $TIMEZONE \
523 --stringparam page $PAGE \
524 --stringparam lang $LANG \
525 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
526 ;;
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 ;;
538 hlfs)
539 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
540 xsltproc --nonet \
541 --xinclude \
542 --stringparam model $MODEL \
543 --stringparam testsuite $TEST \
544 --stringparam bomb-testsuite $BOMB_TEST \
545 --stringparam timezone $TIMEZONE \
546 --stringparam page $PAGE \
547 --stringparam lang $LANG \
548 --stringparam lc_all $LC_ALL \
549 --stringparam grsecurity_host $GRSECURITY_HOST \
550 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
551 ;;
552 lfs)
553 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
554 xsltproc --nonet \
555 --xinclude \
556 --stringparam testsuite $TEST \
557 --stringparam bomb-testsuite $BOMB_TEST \
558 --stringparam vim-lang $VIMLANG \
559 --stringparam timezone $TIMEZONE \
560 --stringparam page $PAGE \
561 --stringparam lang $LANG \
562 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
563 ;;
564 *) exit 1 ;;
565 esac
566
567 [[ "${BLFS_TOOL}" = "y" ]] && copy_blfs_deps_scripts
568
569 echo " ...OK"
570
571 # Make the scripts executable.
572 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
573
574 # Create the packages file. We need it for proper Makefile creation
575 create_package_list
576
577 # Done. Moving on...
578 get_sources
579
580}
581
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
603
604 if [[ "${BLFS_TOOL}" = "y" ]] ; then
605(
606cat << EOF
607$LIBXML_PKG
608$LIBXSLT_PKG
609$TIDY_PKG
610$UNZIP_PKG
611$DBXML_PKG
612$DBXSL_PKG
613$LINKS_PKG
614$SUDO_PKG
615$WGET_PKG
616$SVN_PKG
617$GPM_PKG
618EOF
619) >> pkg_tarball_list
620 fi
621
622 echo " ...OK"
623
624}
625
626
627#----------------------------#
628get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
629#----------------------------#
630 local saveIFS=$IFS
631 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE
632
633 # Test if the packages must be downloaded
634 [ ! "$GETPKG" = "y" ] && return
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
646
647 # Generate URLs file
648 create_urls
649
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
653
654 # Skip some packages if they aren't needed
655 case $line in
656 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
657 [[ "$TEST" = "0" ]] && continue
658 ;;
659 */vim-*-lang* )
660 [[ "$VIMLANG" = "0" ]] && continue
661 ;;
662 *linux/linux-* )
663 [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
664 [[ "$GETKERNEL" = "n" ]] && continue
665 ;;
666 esac
667
668 # Locations
669 URL1=`echo $line | cut -d" " -f2` # Preferred URL
670 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
671 FILE=`basename $URL1` # File name
672 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
673
674 # Validation pair
675 MD5="$BOOKMD5 $FILE"
676 HAVEMD5=1
677
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
690 # If the file does not exist yet in /sources download a fresh one
691 if [ ! -f $FILE ] ; then
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
696 fi
697 fi
698
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
711 fi
712 fi
713
714 # Validate the MD5SUM one last time
715 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
716 gs_wrt_message "$FILE does not match MD5SUMS value"
717 # Force generation of MD5SUM
718 HAVEMD5=0
719 fi
720
721 # Generate a fresh MD5SUM for this file
722 if [[ "$HAVEMD5" = "0" ]] ; then
723 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
724 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
725 fi
726
727 # Good or bad we write the original md5sum to a file
728 echo "$MD5" >> MD5SUMS
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
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.
745 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
746 RUNMAKE="n"
747 fi
748}
749
750#----------------------------#
751create_urls() { #
752#----------------------------#
753 cd $JHALFSDIR
754
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 ;;
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 ;;
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
790
791 cd $BUILDDIR/sources
792
793 if [[ "${BLFS_TOOL}" = "y" ]]; then
794 add_blfs_deps_urls
795 fi
796
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
806 echo "${LIBXML_URL} ${BLFS_SERVER}libxml2/${LIBXML_PKG} ${LIBXML_MD5}" >> urls.lst
807 fi
808
809 if [[ "${DEP_LIBXSLT}" = "y" ]] ; then
810 echo "${LIBXSLT_URL} ${BLFS_SERVER}libxslt/${LIBXSLT_PKG} ${LIBXSLT_MD5}" >> urls.lst
811 fi
812
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
823 echo "${DBXML_URL} ${BLFS_SERVER}docbook-xml/${DBXML_PKG} ${DBXML_MD5}" >> urls.lst
824 fi
825
826 if [[ "${DEP_DBXSL}" = "y" ]] ; then
827 echo "${DBXSL_URL} ${BLFS_SERVER}docbook-xsl/${DBXSL_PKG} ${DBXSL_MD5}" >> urls.lst
828 fi
829
830 if [[ "${DEP_LINKS}" = "y" ]] ; then
831 echo "${LINKS_URL} ${BLFS_SERVER}links/${LINKS_PKG} ${LINKS_MD5}" >> urls.lst
832 fi
833
834 if [[ "${DEP_SUDO}" = "y" ]] ; then
835 echo "${SUDO_URL} ${BLFS_SERVER}sudo/${SUDO_PKG} ${SUDO_MD5}" >> urls.lst
836 echo "${SUDO_PATCH_URL} ${BLFS_SERVER}sudo/${SUDO_PATCH} ${SUDO_PATCH_MD5}" >> urls.lst
837 fi
838
839 if [[ "${DEP_WGET}" = "y" ]] ; then
840 echo "${WGET_URL} ${BLFS_SERVER}wget/${WGET_PKG} ${WGET_MD5}" >> urls.lst
841 fi
842
843 if [[ "${DEP_SVN}" = "y" ]] ; then
844 echo "${SVN_URL} ${BLFS_SERVER}subversion/${SVN_PKG} ${SVN_MD5}" >> urls.lst
845 fi
846
847 if [[ "${DEP_GPM}" = "y" ]] ; then
848 echo "${GPM_URL} ${BLFS_SERVER}gpm/${GPM_PKG} ${GPM_MD5}" >> urls.lst
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
851 fi
852
853}
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
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
881 if [[ "${DEP_DBXSL}" = "y" ]] ; then
882 mv blfs-tool-deps/906-docbook-xsl ${PROGNAME}-commands/blfs-tool-deps
883 fi
884
885 if [[ "${DEP_LINKS}" = "y" ]] ; then
886 mv blfs-tool-deps/908-links ${PROGNAME}-commands/blfs-tool-deps
887 fi
888
889 if [[ "${DEP_SUDO}" = "y" ]] ; then
890 mv blfs-tool-deps/909-sudo ${PROGNAME}-commands/blfs-tool-deps
891 fi
892
893 if [[ "${DEP_WGET}" = "y" ]] ; then
894 mv blfs-tool-deps/910-wget ${PROGNAME}-commands/blfs-tool-deps
895 fi
896
897 if [[ "${DEP_SVN}" = "y" ]] ; then
898 mv blfs-tool-deps/911-subversion ${PROGNAME}-commands/blfs-tool-deps
899 fi
900
901 if [[ "${DEP_GPM}" = "y" ]] ; then
902 mv blfs-tool-deps/907-gpm ${PROGNAME}-commands/blfs-tool-deps
903 fi
904
905 rm -rf blfs-tool-deps
906
907}
Note: See TracBrowser for help on using the repository browser.