source: common/common-functions@ d14903f

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

First commit of CLFS changes to new Makefile scheme.. work still to be done on optimize function and ICA/farce tools

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