source: common/common-functions@ c03e5d0

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

Made envars from blfs-tool dependencies, to can update it more easy.

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