source: common/common-functions@ 4abc9ec

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

Fixed create-sbu_du-report target run (I think)

  • Property mode set to 100644
File size: 22.9 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
[50fb011]318#------------------------------------------------------#
319# END Makefile scripting functions #
320#------------------------------------------------------#
321
[9e4b9a1]322
[398a037]323
[0170229]324#----------------------------#
[65d83a6]325run_make() { #
[0170229]326#----------------------------#
327 # Test if make must be run.
[47fddc8]328 if [ "$RUNMAKE" = "y" ] ; then
[0170229]329 # Test to make sure we're running the build as root
[621f01f]330 if [ "$UID" = "0" ] ; then
[7d4cc81]331 echo "You must not be logged in as root to build the system."
[0170229]332 exit 1
333 fi
334 # Build the system
335 if [ -e $MKFILE ] ; then
[60b56fd]336 echo -ne "Building the system...\n"
[54b4b32]337 cd $JHALFSDIR && make
[0170229]338 echo -ne "done\n"
339 fi
340 fi
341}
342
343
344#----------------------------#
[65d83a6]345clean_builddir() { #
[0170229]346#----------------------------#
347 # Test if the clean must be done.
[47fddc8]348 if [ "${CLEAN}" = "y" ]; then
[0170229]349 # Test to make sure we're running the clean as root
350 if [ "$UID" != "0" ] ; then
351 echo "You must be logged in as root to clean the build directory."
352 exit 1
353 fi
354 # Test to make sure that the build directory was populated by jhalfs
355 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
[60b56fd]356 echo "Looks like $BUILDDIR was not populated by a previous jhalfs-X run."
[0170229]357 exit 1
358 else
359 # Clean the build directory
360 echo -ne "Cleaning $BUILDDIR...\n"
[3465451]361 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
[0170229]362 echo -ne "Cleaning $JHALFSDIR...\n"
[3b63c8c]363 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,*logs,Makefile,*.xsl,makefile-functions,pkg_tarball_list,*.config,*.sh}
[0170229]364 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
365 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
366 echo -ne "done\n"
367 fi
368 fi
369}
370
371#----------------------------#
[65d83a6]372get_book() { #
[0170229]373#----------------------------#
374 cd $JHALFSDIR
375
[2b0f8a5]376 if [ -z $WORKING_COPY ] ; then
[0170229]377 # Check for Subversion instead of just letting the script hit 'svn' and fail.
378 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
379 exit 1"
380 echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
381
382 case $PROGNAME in
383 lfs) svn_root="LFS" ;;
384 hlfs) svn_root="HLFS" ;;
385 clfs) svn_root="cross-lfs" ;;
[3b63c8c]386 clfs2) svn_root="cross-lfs" ;;
[0170229]387 *) echo "BOOK not defined in function <get_book>"
388 exit 1 ;;
389 esac
[60b56fd]390 # Grab a fresh book if it's missing, otherwise, update it from the
[0170229]391 # repo. If we've already extracted the commands, move on to getting the
392 # sources.
393 if [ -d ${PROGNAME}-$LFSVRS ] ; then
394 cd ${PROGNAME}-$LFSVRS
[3b63c8c]395 if LC_ALL=C svn up | grep -q At && \
396 test -d $JHALFSDIR/${PROGNAME}-commands && \
397 test -f $JHALFSDIR/pkg_tarball_list ; then
[0170229]398 # Set the canonical book version
[3b63c8c]399 echo -ne "done\n"
[0170229]400 cd $JHALFSDIR
[3b63c8c]401 case $PROGNAME in
402 clfs | clfs2)
403 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
404 *)
405 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
406 esac
[0170229]407 get_sources
408 else
409 echo -ne "done\n"
410 extract_commands
411 fi
412 else
[3b63c8c]413 svn co $SVN/${svn_root}/${TREE} ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1
[0170229]414 echo -ne "done\n"
415 extract_commands
416 fi
[3b63c8c]417
[0170229]418 else
419 echo -ne "Using $BOOK as book's sources ...\n"
420 extract_commands
421 fi
[3b63c8c]422 echo -ne " Document version ${L_arrow}${BOLD}${VERSION}${R_arrow}\n"
[0170229]423}
424
425#----------------------------#
426extract_commands() { #
427#----------------------------#
[9e1915a]428
[0170229]429 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
430 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
431 exit 1"
432
433 cd $JHALFSDIR
[3b63c8c]434 case $PROGNAME in
435 clfs | clfs2 )
436 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
437 *)
438 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
439 esac
[0170229]440
441 # Start clean
[3e3e28b]442 if [ -d ${PROGNAME}-commands ]; then
443 rm -rf ${PROGNAME}-commands
444 mkdir -v ${PROGNAME}-commands
[0170229]445 fi
[bef0a98]446 echo -n "Extracting commands for"
[0170229]447
448 # Dump the commands in shell script form from the HLFS book.
449 case ${PROGNAME} in
450 clfs)
[9c90294]451 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
[e676ffa]452 xsltproc --nonet \
453 --xinclude \
454 --stringparam method $METHOD \
455 --stringparam testsuite $TEST \
[056486c]456 --stringparam bomb-testsuite $BOMB_TEST \
[e676ffa]457 --stringparam vim-lang $VIMLANG \
458 --stringparam timezone $TIMEZONE \
459 --stringparam page $PAGE \
460 --stringparam lang $LANG \
[a9490ab]461 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
[0170229]462 ;;
[3b63c8c]463
464 clfs2)
465 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
466 xsltproc --nonet \
467 --xinclude \
468 --stringparam vim-lang $VIMLANG \
469 --stringparam timezone $TIMEZONE \
470 --stringparam page $PAGE \
471 --stringparam lang $LANG \
472 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
473 ;;
[0170229]474 hlfs)
[60b56fd]475 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
[ad71d98]476 xsltproc --nonet \
477 --xinclude \
478 --stringparam model $MODEL \
479 --stringparam testsuite $TEST \
[056486c]480 --stringparam bomb-testsuite $BOMB_TEST \
[ad71d98]481 --stringparam timezone $TIMEZONE \
482 --stringparam page $PAGE \
[d87b293]483 --stringparam lang $LANG \
484 --stringparam lc_all $LC_ALL \
[ad71d98]485 --stringparam grsecurity_host $GRSECURITY_HOST \
486 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
[0170229]487 ;;
488 lfs)
[9c90294]489 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
[0170229]490 xsltproc --nonet \
491 --xinclude \
492 --stringparam testsuite $TEST \
[056486c]493 --stringparam bomb-testsuite $BOMB_TEST \
[0170229]494 --stringparam vim-lang $VIMLANG \
[ad71d98]495 --stringparam timezone $TIMEZONE \
496 --stringparam page $PAGE \
[d87b293]497 --stringparam lang $LANG \
[0170229]498 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
499 ;;
[3e7af38]500 *) exit 1 ;;
[0170229]501 esac
[dd810ea]502
[3c5ca23]503 [[ "${BLFS_TOOL}" = "y" ]] && copy_blfs_deps_scripts
504
[bef0a98]505 echo " ...OK"
[0170229]506
507 # Make the scripts executable.
508 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
509
[3e7af38]510 # Create the packages file. We need it for proper Makefile creation
[3b63c8c]511 create_package_list
[0170229]512
513 # Done. Moving on...
514 get_sources
[50fb011]515
[0170229]516}
517
[3b63c8c]518#----------------------------#
519create_package_list() { #
520#----------------------------#
521
522 # Create the packages file. We need it for proper Makefile creation
523 rm -f pkg_tarball_list
524 echo -n "Creating <${PROGNAME}> list of tarball names for $BOOK $ARCH"
525 case ${PROGNAME} in
526 clfs | clfs2)
527 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
528 $BOOK/materials/${ARCH}-chapter.xml >>$LOGDIR/$LOG 2>&1
529 ;;
530 hlfs)
531 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
532 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
533 ;;
534 lfs)
535 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
536 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
537 ;;
538 esac
[f67691e]539
540 if [[ "${BLFS_TOOL}" = "y" ]] ; then
541(
542cat << EOF
[c03e5d0]543$LIBXML_PKG
544$LIBXSLT_PKG
545$DBXSL_PKG
546$LINKS_PKG
547$SUDO_PKG
548$WGET_PKG
549$SVN_PKG
550$GPM_PKG
[f67691e]551EOF
552) >> pkg_tarball_list
553 fi
554
[3b63c8c]555 echo " ...OK"
556
557}
558
559
[0170229]560#----------------------------#
[3e7af38]561get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
[0170229]562#----------------------------#
[3e7af38]563 local saveIFS=$IFS
[7a100d96]564 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE
[65d83a6]565
566 # Test if the packages must be downloaded
[47fddc8]567 [ ! "$GETPKG" = "y" ] && return
[65d83a6]568
569 gs_wrt_message(){
570 echo "${RED}$1${OFF}"
571 echo "$1" >> MISSING_FILES.DMP
572 }
573 # Housekeeping
574 [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
575 cd $BUILDDIR/sources
576 [[ -f MD5SUMS ]] && rm MD5SUMS
577 [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
578 [[ -f urls.lst ]] && rm urls.lst
[4aede02]579
[3e7af38]580 # Generate URLs file
[65d83a6]581 create_urls
[3e7af38]582
[65d83a6]583 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
584 for line in `cat urls.lst`; do
585 IFS=$saveIFS # Restore the system defaults
[3e7af38]586
587 # Skip some packages if they aren't needed
[65d83a6]588 case $line in
[3e7af38]589 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
590 [[ "$TEST" = "0" ]] && continue
591 ;;
592 */vim-*-lang* )
593 [[ "$VIMLANG" = "0" ]] && continue
594 ;;
[3a27393]595 *linux/linux-* )
[34933b4]596 [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
[47fddc8]597 [[ "$GETKERNEL" = "n" ]] && continue
[3a27393]598 ;;
[65d83a6]599 esac
[3e7af38]600
[65d83a6]601 # Locations
602 URL1=`echo $line | cut -d" " -f2` # Preferred URL
603 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
[7a100d96]604 FILE=`basename $URL1` # File name
605 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
606
[3a27393]607 # Validation pair
608 MD5="$BOOKMD5 $FILE"
609 HAVEMD5=1
[0170229]610
[65d83a6]611 set -e
612 # If the file exists in the archive copy it to the
613 # $BUILDDIR/sources dir. MD5SUM will be validated later.
614 if [ ! -z ${SRC_ARCHIVE} ] &&
615 [ -d ${SRC_ARCHIVE} ] &&
616 [ -f ${SRC_ARCHIVE}/$FILE ]; then
617 cp ${SRC_ARCHIVE}/$FILE .
618 echo "$FILE: -- copied from $SRC_ARCHIVE"
619 fromARCHIVE=1
620 else
621 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
622 fromARCHIVE=0
[3a27393]623 # If the file does not exist yet in /sources download a fresh one
[3e7af38]624 if [ ! -f $FILE ] ; then
[65d83a6]625 if ! wget $URL1 && ! wget $URL2 ; then
626 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
627 continue
628 fi
[3e7af38]629 fi
[65d83a6]630 fi
[0170229]631
[3a27393]632 # IF the md5sum does not match the existing files
633 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
634 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
635 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
636 # Remove the old file and download a new one
637 rm -fv $FILE
638 # Force storage in SRC_ARCHIVE
639 fromARCHIVE=0;
640 # Try to retrieve again the file. Servers in reverse order.
641 if ! wget $URL2 && ! wget $URL1 ; then
642 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
643 continue
[3e7af38]644 fi
[65d83a6]645 fi
[e1edff3]646
[65d83a6]647 # Validate the MD5SUM one last time
[3a27393]648 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
[65d83a6]649 gs_wrt_message "$FILE does not match MD5SUMS value"
[b61a4a9]650 # Force generation of MD5SUM
651 HAVEMD5=0
[65d83a6]652 fi
[3e7af38]653
[65d83a6]654 # Generate a fresh MD5SUM for this file
655 if [[ "$HAVEMD5" = "0" ]] ; then
656 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
[3a27393]657 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
[3e7af38]658 fi
[e1edff3]659
[65d83a6]660 # Good or bad we write the original md5sum to a file
[3a27393]661 echo "$MD5" >> MD5SUMS
[65d83a6]662
663 # Copy the freshly downloaded file
664 # to the source archive.
665 if [ ! -z ${SRC_ARCHIVE} ] &&
666 [ -d ${SRC_ARCHIVE} ] &&
667 [ -w ${SRC_ARCHIVE} ] &&
668 [ "$fromARCHIVE" = "0" ] ; then
669 echo "Storing file:<$FILE> in the package archive"
670 cp -f $FILE ${SRC_ARCHIVE}
671 fi
672
673 done
674
675 if [[ -s MISSING_FILES.DMP ]]; then
[3b63c8c]676 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"
677 # Do not allow the automatic execution of the Makefile.
[65d83a6]678 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
[47fddc8]679 RUNMAKE="n"
[3e7af38]680 fi
[0170229]681}
682
683#----------------------------#
[3e7af38]684create_urls() { #
[0170229]685#----------------------------#
[3e7af38]686 cd $JHALFSDIR
[0170229]687
[3e7af38]688 case ${PROGNAME} in
689 clfs)
690 echo -n "Creating CLFS <${ARCH}> specific URLs file"
691 xsltproc --nonet --xinclude \
692 --stringparam server $SERVER \
693 -o $BUILDDIR/sources/urls.lst urls.xsl \
694 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
695 echo " ...OK"
696 ;;
[3b63c8c]697 clfs2)
698 echo -n "Creating CLFS2 <${ARCH}> specific URLs file"
699 xsltproc --nonet --xinclude \
700 --stringparam server $SERVER \
701 -o $BUILDDIR/sources/urls.lst urls.xsl \
702 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
703 echo " ...OK"
704 ;;
[3e7af38]705 hlfs)
706 echo -n "Creating HLFS <${MODEL}> specific URLs file"
707 xsltproc --nonet --xinclude \
708 --stringparam server $SERVER \
709 --stringparam model $MODEL \
710 -o $BUILDDIR/sources/urls.lst urls.xsl \
711 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
712 echo " ...OK"
713 ;;
714 lfs)
715 echo -n "Creating LFS specific URLs file"
716 xsltproc --nonet --xinclude \
717 --stringparam server $SERVER \
718 -o ../sources/urls.lst urls.xsl \
719 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
720 echo " ...OK"
721 ;;
722 esac
[0170229]723
[3e7af38]724 cd $BUILDDIR/sources
[865f4f6]725
[01b6d52]726 if [[ "${BLFS_TOOL}" = "y" ]]; then
[d66cbc2]727 add_blfs_deps_urls
[01b6d52]728 fi
[50fb011]729
[865f4f6]730}
731
732#----------------------------# Hardcoded URLs and MD5.
733add_blfs_deps_urls() { # No easy way to extract it.
734#----------------------------# Some FTP mirrors may not work
735
736 local BLFS_SERVER="${SERVER}/pub/blfs/conglomeration/"
737
738 if [[ "${DEP_LIBXML}" = "y" ]] ; then
[c03e5d0]739 echo "${LIBXML_URL} ${BLFS_SERVER}libxml2/${LIBXML_PKG} ${LIBXML_MD5}" >> urls.lst
[865f4f6]740 fi
741
742 if [[ "${DEP_LIBXSLT}" = "y" ]] ; then
[c03e5d0]743 echo "${LIBXSLT_URL} ${BLFS_SERVER}libxslt/${LIBXSLT_PKG} ${LIBXSLT_MD5}" >> urls.lst
[865f4f6]744 fi
745
746 if [[ "${DEP_DBXSL}" = "y" ]] ; then
[c03e5d0]747 echo "${DBXSL_URL} ${BLFS_SERVER}docbook-xsl/${DBXSL_PKG} ${DBXSL_MD5}" >> urls.lst
[865f4f6]748 fi
749
[c03e5d0]750 if [[ "${DEP_LINKS}" = "y" ]] ; then
751 echo "${LINKS_URL} ${BLFS_SERVER}links/${LINKS_PKG} ${LINKS_MD5}" >> urls.lst
[865f4f6]752 fi
753
754 if [[ "${DEP_SUDO}" = "y" ]] ; then
[c03e5d0]755 echo "${SUDO_URL} ${BLFS_SERVER}sudo/${SUDO_PKG} ${SUDO_MD5}" >> urls.lst
[3c5ca23]756 echo "${SUDO_PATCH_URL} ${BLFS_SERVER}sudo/${SUDO_PATCH} ${SUDO_PATCH_MD5}" >> urls.lst
[865f4f6]757 fi
758
759 if [[ "${DEP_WGET}" = "y" ]] ; then
[c03e5d0]760 echo "${WGET_URL} ${BLFS_SERVER}wget/${WGET_PKG} ${WGET_MD5}" >> urls.lst
[865f4f6]761 fi
762
763 if [[ "${DEP_SVN}" = "y" ]] ; then
[c03e5d0]764 echo "${SVN_URL} ${BLFS_SERVER}subversion/${SVN_PKG} ${SVN_MD5}" >> urls.lst
[865f4f6]765 fi
766
767 if [[ "${DEP_GPM}" = "y" ]] ; then
[c03e5d0]768 echo "${GPM_URL} ${BLFS_SERVER}gpm/${GPM_PKG} ${GPM_MD5}" >> urls.lst
[3c5ca23]769 echo "${GPM_PATCH_1_URL} ${BLFS_SERVER}gpm/${GPM_PATCH_1} ${GPM_PATCH_1_MD5}" >> urls.lst
770 echo "${GPM_PATCH_2_URL} ${BLFS_SERVER}gpm/${GPM_PATCH_2} ${GPM_PATCH_2_MD5}" >> urls.lst
[865f4f6]771 fi
772
[0170229]773}
[3c5ca23]774
775#----------------------------# Maybe there is a better way to do this, but this
776copy_blfs_deps_scripts() { # method avoid to place the test on all
777#----------------------------# $PROGNAME/master.sh scripts.
778
779 mkdir -p ${PROGNAME}-commands/blfs-tool-deps
780
781 if [[ "${DEP_LIBXML}" = "y" ]] ; then
782 mv blfs-tool-deps/901-libxml2 ${PROGNAME}-commands/blfs-tool-deps
783 fi
784
785 if [[ "${DEP_LIBXSLT}" = "y" ]] ; then
786 mv blfs-tool-deps/902-libxslt ${PROGNAME}-commands/blfs-tool-deps
787 fi
788
789 if [[ "${DEP_DBXSL}" = "y" ]] ; then
790 mv blfs-tool-deps/903-docbook-xsl ${PROGNAME}-commands/blfs-tool-deps
791 fi
792
793 if [[ "${DEP_LINKS}" = "y" ]] ; then
794 mv blfs-tool-deps/905-links ${PROGNAME}-commands/blfs-tool-deps
795 fi
796
797 if [[ "${DEP_SUDO}" = "y" ]] ; then
798 mv blfs-tool-deps/906-sudo ${PROGNAME}-commands/blfs-tool-deps
799 fi
800
801 if [[ "${DEP_WGET}" = "y" ]] ; then
802 mv blfs-tool-deps/907-wget ${PROGNAME}-commands/blfs-tool-deps
803 fi
804
805 if [[ "${DEP_SVN}" = "y" ]] ; then
806 mv blfs-tool-deps/908-subversion ${PROGNAME}-commands/blfs-tool-deps
807 fi
808
809 if [[ "${DEP_GPM}" = "y" ]] ; then
810 mv blfs-tool-deps/904-gpm ${PROGNAME}-commands/blfs-tool-deps
811 fi
812
813 rm -rf blfs-tool-deps
814
[44994cb]815}
Note: See TracBrowser for help on using the repository browser.