source: common/common-functions@ 1ba5024

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

Remove unnecessary flow tests. Added missing function, wrt_report. Added restore-luser-env to chroot build

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