source: common/common-functions@ 50fb011

experimental
Last change on this file since 50fb011 was 50fb011, checked in by George Boudreau <georgeb@…>, 18 years ago

First commit of changes to makefile generation. Makefile now does recursive calls to itself for the different phases..SETUP,LUSER,CHROOT,ROOT

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