source: common/common-functions@ 7fdd8f6

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 7fdd8f6 was a6655ff, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Avoiding hardcoded supported books versions.

  • Property mode set to 100644
File size: 27.8 KB
RevLine 
[877cc6a]1#!/bin/bash
2
3# $Id$
4
5set +e
6
7# VT100 colors
8declare -r BLACK=$'\e[1;30m'
9declare -r DK_GRAY=$'\e[0;30m'
10
11declare -r RED=$'\e[31m'
12declare -r GREEN=$'\e[32m'
13declare -r YELLOW=$'\e[33m'
14declare -r BLUE=$'\e[34m'
15declare -r MAGENTA=$'\e[35m'
16declare -r CYAN=$'\e[36m'
17declare -r WHITE=$'\e[37m'
18
19declare -r OFF=$'\e[0m'
20declare -r BOLD=$'\e[1m'
21declare -r REVERSE=$'\e[7m'
22declare -r HIDDEN=$'\e[8m'
23
24declare -r tab_=$'\t'
25declare -r nl_=$'\n'
26
[47e524f]27declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
28declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
29declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
[877cc6a]30
31# bold yellow > < pair
32declare -r R_arrow=$'\e[1;33m>\e[0m'
33declare -r L_arrow=$'\e[1;33m<\e[0m'
34
35
36usage() {
37cat <<- -EOF-
38${DD_BORDER}
39${BOLD}
40 Usage: $0 ${BOLD}[OPTION]
41
[efc0d1e]42${RED}IMPORTANT:${OFF} Only supported command line switches are listed here.
[4dd25a1]43 For more fine-grained setups you must edit the relevant
[efc0d1e]44 configuration files placed under ${BOLD}common/${OFF} and ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])/${OFF}
45
[877cc6a]46Options:
47${BOLD} -h, --help${OFF}
48 print this help, then exit
49
50${BOLD} -V, --version${OFF}
51 print version information, then exit
52
53${BOLD} -B, --book VER${OFF}
[e2fa2bd]54 use VER version of the book as the system to build.
[a6655ff]55 Supported VER values are:
56 dev*, trunk, SVN = aliases for the Development version of {C,H}LFS
57 branch-NAME = a branch of name NAME
58 VERSION = the version of a stable released book
59 To know what branches and stable books works with this version of jhalfs
60 please see http://wiki.linuxfromscratch.org/alfs/wiki/SupportedBooks
[877cc6a]61
62${BOLD} -D --directory DIR${OFF}
[73e5448]63 use DIR directory for building ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF}; all files jhalfs produces
[1a1f099]64 will be in the directory DIR/${SCRIPT_ROOT}.
[511923a]65 The current setting for BUILDDIR is "$BUILDDIR"
[877cc6a]66
67${BOLD} -G, --get-packages${OFF}
68 download the packages and patches. This assumes that the server declared
69 in the configuration file has the proper packages and patches for the
70 book version being processed.
71
[1b65a84]72${BOLD} -O, --optimize${OFF}
73 Optimize [0-2]
74 0 = no optimization
[1ec8fce]75 1 = optimize final system only
76 2 = optimize both temporary tools and final system
[1b65a84]77 Edit common/opt_config{,.d/*} and common/opt_override as desired.
78
[877cc6a]79${BOLD} -T, --testsuites N ${OFF}
80 Run test suites [0-3]
81 0 = none
[0755d1a]82 1 = only final system Glibc, GCC and Binutils testsuites
83 2 = all final system testsuites
[b240ee6]84 3 = all temporary tools and final system testsuites
[877cc6a]85 In CLFS, 3 is an alias to 2
86
87${BOLD} -W, --working-copy DIR${OFF}
88 use the local working copy placed in DIR as the $(echo $PROGNAME | tr [a-z] [A-Z]) book
89
[45f82718]90${BOLD} -C, --comparasion TYPE${OFF}
[e2fa2bd]91 do iterative comparison analysis. This extends the total build time
92 considerably because the entire final system will rebuild itself
93 the number of times specified by ITERATIONS in common/config.
[6dcfd53]94 Types allowed are:
[e2fa2bd]95 ICA = do ICA as designed by Greg Schafer
[0ad851d]96 farce = do the farce analysis designed by Ken Moffat
97 both = perfom both ICA and farce analysis
[45f82718]98
[877cc6a]99${BOLD} -F, --fstab FILE${OFF}
100 use FILE as the /etc/fstab file for the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} system. If not specified,
101 a default /etc/fstab file with dummy values is created.
102
103${BOLD} -K, --kernel-config FILE${OFF}
104 use the kernel configuration file specified in FILE to build the kernel.
105 if the file is not found, or if not specified, the kernel build is skipped.
106
107${BOLD} -M, --run-make${OFF}
108 run make on the generated Makefile
109
110${BOLD} -R --rebuild${OFF}
[e2fa2bd]111 clean the build directory before perfoming any other task. The directory
[73e5448]112 is cleaned only if it was populated by a previous jhalfs run.
[877cc6a]113-EOF-
114
115[[ ${PROGNAME} = "clfs" ]] &&
116cat <<- -EOF-
117
118${BOLD} -A, --arch ARCH ${OFF}
119 Select the TARGET architecture, valid selections are:
120 32bit builds
[b0dd4bd]121 x86, i486, i586, ppc, mips, mipsel, sparc
[877cc6a]122 64bit builds
123 x86_64-64, mips64-64, mipsel64-64, sparc64-64, alpha
124 64bit multi-lib
125 x86_64, mips64, mipsel64, sparc64, ppc64
126
[c7c5a53]127${BOLD} --boot-config FILE ${OFF}
[877cc6a]128 The configuration file for the bootstrap kernel if method=boot
129
130${BOLD} --method BUILDMETHOD ${OFF}
131 Select the build method, chroot or boot
132-EOF-
133
134[[ ${PROGNAME} = "hlfs" ]] &&
135cat <<- -EOF-
136
137${BOLD} --model STYLE ${OFF}
138 Select the library model for the HLFS system
139 Valid choices are: glibc or uclibc
140-EOF-
141
142cat <<- -EOF-
143${DD_BORDER}
144-EOF-
145 exit
146}
147
148version="
[73e5448]149${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
[877cc6a]150\$Date$
151
152${BOLD} \"${PROGNAME}\"${OFF} script module
153
154Written by George Boudreau,
155 Manuel Canales Esparcia,
156 Jeremy Huntwork
157
158This program is published under the ${BOLD}Gnu General Public License, Version 2.${OFF}
159"
160
161
162no_empty_builddir() {
163 'clear'
164cat <<- -EOF-
165${DD_BORDER}
166
167${tab_}${tab_}${BOLD}${RED}W A R N I N G${OFF}
168 Looks like the \$BUILDDIR directory contains subdirectories
169 from a previous HLFS build.
170
171 Please format the partition mounted on \$BUILDDIR or set
[73e5448]172 a different build directory before running jhalfs.
[877cc6a]173${OFF}
174${DD_BORDER}
175-EOF-
176 exit
177}
178
179
180help="${nl_}Try '$0 --help' for more information."
181
182exit_missing_arg="\
183echo \"Option '\$1' requires an argument\" >&2
184echo \"\$help\" >&2
185exit 1"
186
[73e5448]187HEADER="# This file is automatically generated by jhalfs
[877cc6a]188# DO NOT EDIT THIS FILE MANUALLY
189#
190# Generated on `date \"+%F %X %Z\"`"
191
192
193
194#----------------------------------#
[3a321ea]195wrt_target() { # Create target and initialize log file
[877cc6a]196#----------------------------------#
197 local i=$1
198 local PREV=$2
[4edf3b7]199 case $i in
200 iteration* ) local LOGFILE=$this_script.log ;;
201 * ) local LOGFILE=$this_script ;;
202 esac
[877cc6a]203(
204cat << EOF
205
206$i: $PREV
207 @\$(call echo_message, Building)
[46758a2]208 @./progress_bar.sh \$@ &
[1a1f099]209 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >logs/$LOGFILE
[877cc6a]210EOF
211) >> $MKFILE.tmp
212}
213
[7eb9402]214
215#----------------------------------#
216wrt_target_boot() { # Create target and initialize log file
217#----------------------------------#
218 local i=$1
219 local PREV=$2
220 case $i in
221 iteration* ) local LOGFILE=$this_script.log ;;
222 * ) local LOGFILE=$this_script ;;
223 esac
224(
225cat << EOF
226
227$i: $PREV
228 @\$(call echo_message, Building)
229 @./progress_bar.sh \$@ &
230 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT}\`\n" >logs/$LOGFILE
231EOF
232) >> $MKFILE.tmp
233}
234
[dd29d02]235#----------------------------#
236get_package_tarball_name() { #
237#----------------------------#
238 local script_name=$1
239
240 # The use of 'head' is necessary to limit the return value to the FIRST match..
241 # hopefully this will not cause problems.
242 #
243 case $script_name in
244 tcl) echo $(grep "^tcl" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
245 *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
246 esac
247
248}
[877cc6a]249
[5842156]250#----------------------------------#
251wrt_remove_existing_dirs() { #
252#----------------------------------#
253 local PKG_NAME=$1
254(
255cat << EOF
[3b3251a]256 @PKG_PATH=\`ls -t \$(MOUNT_PT)\$(SRC)/${PKG_NAME} | head -n1\` && \\
257 ROOT=\`tar -tf \$\$PKG_PATH | head -n1 | sed -e 's@^./@@;s@/.*@@'\` && \\
[5842156]258 [[ -n \$\$ROOT ]] && \\
259 rm -rf \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
[15787a3]260 if [ -e \$(MOUNT_PT)\$(SRC)/${PKG_NAME%-*}-build ]; then \\
261 rm -rf \$(MOUNT_PT)\$(SRC)/${PKG_NAME%-*}-build; \\
[5842156]262 fi;
263EOF
264) >> $MKFILE.tmp
265}
266
267#----------------------------------#
268wrt_remove_existing_dirs2() { #
269#----------------------------------#
270 local PKG_NAME=$1
271(
272cat << EOF
[3b3251a]273 @PKG_PATH=\`ls -t \$(SRC)/${PKG_NAME} | head -n1\` && \\
274 ROOT=\`tar -tf \$\$PKG_PATH | head -n1 | sed -e 's@^./@@;s@/.*@@'\` && \\
[5842156]275 [[ -n \$\$ROOT ]] && \\
276 rm -rf \$(SRC)/\$\$ROOT && \\
[15787a3]277 if [ -e \$(SRC)/${PKG_NAME%-*}-build ]; then \\
278 rm -rf \$(SRC)/${PKG_NAME%-*}-build; \\
[5842156]279 fi;
280EOF
281) >> $MKFILE.tmp
282}
283
284
285
[877cc6a]286#----------------------------------#
287wrt_unpack() { # Unpack and set 'ROOT' var
288#----------------------------------#
289 local FILE=$1
[5842156]290 local optSAVE_PREVIOUS=$2
[82eb8c1]291
[5842156]292 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
293 wrt_remove_existing_dirs "$FILE"
294 fi
[877cc6a]295(
296cat << EOF
297 @\$(call unpack,$FILE)
[82eb8c1]298 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
[877cc6a]299 echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
[15537d5]300 chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT
[877cc6a]301EOF
302) >> $MKFILE.tmp
303}
304
305
[e5f5970]306#----------------------------------#
307wrt_unpack_clfs() { # Unpack and set 'ROOT' var
308#----------------------------------#
309 local FILE=$1
310 local optSAVE_PREVIOUS=$2
311
312 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
313 wrt_remove_existing_dirs "$FILE"
314 fi
315(
316cat << EOF
317 @\$(call unpack,$FILE)
318 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
319 echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
320 chown -R clfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT
321EOF
322) >> $MKFILE.tmp
323}
324
325
[877cc6a]326#----------------------------------#
327wrt_unpack2() { #
328#----------------------------------#
329 local FILE=$1
[5842156]330 local optSAVE_PREVIOUS=$2
331
332 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
333 wrt_remove_existing_dirs "$FILE"
334 fi
[877cc6a]335(
336cat << EOF
337 @\$(call unpack2,$FILE)
[a229600]338 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
[877cc6a]339 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
340EOF
341) >> $MKFILE.tmp
342}
343
344
[261eea6]345#----------------------------------#
346wrt_unpack3() { #
347#----------------------------------#
[877cc6a]348 local FILE=$1
[5842156]349 local optSAVE_PREVIOUS=$2
350
351 if [ "${optSAVE_PREVIOUS}" != "1" ]; then
352 wrt_remove_existing_dirs2 "$FILE"
353 fi
[877cc6a]354(
355cat << EOF
356 @\$(call unpack3,$FILE)
[82eb8c1]357 @ROOT=\`head -n1 \$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
[877cc6a]358 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
359EOF
360) >> $MKFILE.tmp
361}
362
[a229600]363#----------------------------------#
364wrt_test_log() { # Initialize testsuite log file
365#----------------------------------#
366 local TESTLOGFILE=$1
367(
368cat << EOF
369 @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
370 su - lfs -c "echo -e '\n\`date\`\n' >$TESTLOGDIR/$TESTLOGFILE"
371EOF
372) >> $MKFILE.tmp
373}
374
375#----------------------------------#
376wrt_test_log2() { #
377#----------------------------------#
378 local TESTLOGFILE=$1
379(
380cat << EOF
381 @echo "export TEST_LOG=/$SCRIPT_ROOT/test-logs/$TESTLOGFILE" >> envars && \\
382 echo -e "\n\`date\`\n" >test-logs/$TESTLOGFILE
383EOF
384) >> $MKFILE.tmp
385}
386
[877cc6a]387#----------------------------------#
388wrt_target_vars() { # Target vars for hlfs (cross-build method)
389#----------------------------------#
390(
391cat << EOF
392 @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
393 echo "export ldso=/lib/${LOADER}" >> envars
394EOF
395) >> $MKFILE.tmp
396
397}
398
399
400#----------------------------------#
[3a321ea]401wrt_run_as_su() { # Execute script inside time { }, footer to log file
[877cc6a]402#----------------------------------#
403 local this_script=$1
404 local file=$2
405(
406cat << EOF
[3a321ea]407 @( time { su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
[1a1f099]408 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
[877cc6a]409EOF
410) >> $MKFILE.tmp
411}
412
413
414#----------------------------------#
[3a321ea]415wrt_run_as_root() { # Some scripts must be run as root..
[877cc6a]416#----------------------------------#
417 local this_script=$1
418 local file=$2
419(
420cat << EOF
[3a321ea]421 @( time { export LFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
[1a1f099]422 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
[877cc6a]423EOF
424) >> $MKFILE.tmp
425}
426
427
[e5f5970]428#----------------------------------#
429wrt_run_as_clfs_su() { # Execute script inside time { }, footer to log file
430#----------------------------------#
431 local this_script=$1
432 local file=$2
433(
434cat << EOF
435 @( time { su - clfs -c "source /home/clfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
436 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
437EOF
438) >> $MKFILE.tmp
439}
440
441
[ac1d897]442#----------------------------------#
443wrt_run_as_clfs_root() { # Some scripts must be run as root..
444#----------------------------------#
445 local this_script=$1
446 local file=$2
447(
448cat << EOF
449 @( time { export CLFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
450 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
451EOF
452) >> $MKFILE.tmp
453}
454
455
[261eea6]456#----------------------------------#
457wrt_run_as_root2() { #
458#----------------------------------#
[877cc6a]459 local this_script=$1
460 local file=$2
461(
462cat << EOF
[3a321ea]463 @( time { source envars && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
[1a1f099]464 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \`\n" >>logs/$this_script
[877cc6a]465EOF
466) >> $MKFILE.tmp
467}
468
469
470
471#----------------------------------#
472wrt_run_as_chroot1() { #
473#----------------------------------#
474 local this_script=$1
475 local file=$2
476(
477 cat << EOF
[1a1f099]478 @( time { \$(CHROOT1) 'cd /${SCRIPT_ROOT} && source envars && /${SCRIPT_ROOT}/${PROGNAME}-commands/$file >>/${SCRIPT_ROOT}/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
479 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/${this_script}
[877cc6a]480EOF
481) >> $MKFILE.tmp
482}
483
484
485#----------------------------------#
486wrt_run_as_chroot2() { #
487#----------------------------------#
488 local this_script=$1
489 local file=$2
490(
491cat << EOF
[1a1f099]492 @( time { \$(CHROOT2) 'cd /${SCRIPT_ROOT} && source envars && /${SCRIPT_ROOT}/${PROGNAME}-commands/$file >>/${SCRIPT_ROOT}/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
493 echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/${this_script}
[877cc6a]494EOF
495) >> $MKFILE.tmp
496}
497
498
499#----------------------------------#
500wrt_copy_fstab() { #
501#----------------------------------#
502 local i=$1
503(
504 cat << EOF
[3a321ea]505 @cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1
[877cc6a]506EOF
507) >> $MKFILE.tmp
508}
509
510#----------------------------------#
[3a321ea]511wrt_copy_fstab2() { #
[877cc6a]512#----------------------------------#
513 local i=$1
514(
515 cat << EOF
[3a321ea]516 @cp -v /sources/fstab /etc/fstab >>logs/$i 2>&1
[877cc6a]517EOF
518) >> $MKFILE.tmp
519}
520
521
522#----------------------------------#
[0bdf6ed]523wrt_remove_build_dirs() { #
[877cc6a]524#----------------------------------#
[0bdf6ed]525 local name=$1
[877cc6a]526(
[0bdf6ed]527cat << EOF
[82eb8c1]528 @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
[b7faa5a]529 rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
530 if [ -e \$(MOUNT_PT)\$(SRC)/$name-build ]; then \\
[0bdf6ed]531 rm -r \$(MOUNT_PT)\$(SRC)/$name-build; \\
532 fi;
533EOF
534) >> $MKFILE.tmp
535}
536
537
538#----------------------------------#
539wrt_remove_build_dirs2() { #
540#----------------------------------#
541 local name=$1
542(
543cat << EOF
[82eb8c1]544 @ROOT=\`head -n1 \$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
[b7faa5a]545 rm -r \$(SRC)/\$\$ROOT && \\
546 if [ -e \$(SRC)/$name-build ]; then \\
[0bdf6ed]547 rm -r \$(SRC)/$name-build; \\
548 fi;
[877cc6a]549EOF
550) >> $MKFILE.tmp
551}
552
553
[e2ef100]554#----------------------------------#
555wrt_touch() { #
556#----------------------------------#
557(
558cat << EOF
559 @touch \$@ && \\
560 sleep .25 && \\
[4a444f1]561 echo -e "\n\n "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
562 echo --------------------------------------------------------------------------------\$(WHITE)
[e2ef100]563EOF
564) >> $MKFILE.tmp
565}
566
567
[453bef0]568#----------------------------------#
[261eea6]569wrt_report() { #
[453bef0]570#----------------------------------#
571(
572cat << EOF
573
574create-sbu_du-report: $PREV
575 @\$(call echo_message, Building)
[a9429d5]576 @./create-sbu_du-report.sh logs $VERSION
[453bef0]577 @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
578 @touch \$@
579EOF
580) >> $MKFILE.tmp
581
582chapter789="$chapter789 create-sbu_du-report"
583}
584
585
[877cc6a]586#----------------------------#
[261eea6]587run_make() { #
[877cc6a]588#----------------------------#
589 # Test if make must be run.
590 if [ "$RUNMAKE" = "1" ] ; then
591 # Test to make sure we're running the build as root
592 if [ "$UID" != "0" ] ; then
593 echo "You must be logged in as root to successfully build the system."
594 exit 1
595 fi
596 # Build the system
597 if [ -e $MKFILE ] ; then
598 echo -ne "Building the system...\n"
[a167246]599 cd $JHALFSDIR && make
[877cc6a]600 echo -ne "done\n"
601 fi
602 fi
603}
604
605
606#----------------------------#
[261eea6]607clean_builddir() { #
[877cc6a]608#----------------------------#
609 # Test if the clean must be done.
610 if [ "$CLEAN" = "1" ] ; then
611 # Test to make sure we're running the clean as root
612 if [ "$UID" != "0" ] ; then
613 echo "You must be logged in as root to clean the build directory."
614 exit 1
615 fi
616 # Test to make sure that the build directory was populated by jhalfs
617 if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
[73e5448]618 echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
[877cc6a]619 exit 1
620 else
621 # Clean the build directory
622 echo -ne "Cleaning $BUILDDIR...\n"
623 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
624 echo -ne "Cleaning $JHALFSDIR...\n"
[dd29d02]625 rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,*logs,Makefile,*.xsl,makefile-functions,pkg_tarball_list,*.config,*.sh}
[877cc6a]626 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
627 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
628 echo -ne "done\n"
629 fi
630 fi
631}
632
633#----------------------------#
[261eea6]634get_book() { #
[877cc6a]635#----------------------------#
636 cd $JHALFSDIR
637
638 if [ -z $WC ] ; then
639 # Check for Subversion instead of just letting the script hit 'svn' and fail.
640 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
641 exit 1"
642 echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
643
644 case $PROGNAME in
645 lfs) svn_root="LFS" ;;
646 hlfs) svn_root="HLFS" ;;
647 clfs) svn_root="cross-lfs" ;;
648 *) echo "BOOK not defined in function <get_book>"
649 exit 1 ;;
650 esac
651 # Grab a fresh book if it's missing, otherwise, update it from the
652 # repo. If we've already extracted the commands, move on to getting the
653 # sources.
654 if [ -d ${PROGNAME}-$LFSVRS ] ; then
655 cd ${PROGNAME}-$LFSVRS
[1ff6768]656 if LC_ALL=C svn up | grep -q At && \
657 test -d $JHALFSDIR/${PROGNAME}-commands && \
658 test -f $JHALFSDIR/pkg_tarball_list ; then
[877cc6a]659 # Set the canonical book version
[a6655ff]660 echo -ne "done\n"
[877cc6a]661 cd $JHALFSDIR
[1ff6768]662 case $PROGNAME in
663 clfs)
664 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
665 *)
666 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
667 esac
[877cc6a]668 get_sources
669 else
670 echo -ne "done\n"
671 extract_commands
672 fi
673 else
[a6655ff]674 svn co $SVN/${svn_root}/${TREE} ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1
[877cc6a]675 echo -ne "done\n"
676 extract_commands
677 fi
[1ff6768]678
[877cc6a]679 else
680 echo -ne "Using $BOOK as book's sources ...\n"
681 extract_commands
682 fi
[a6655ff]683 echo -ne " Document version ${L_arrow}${BOLD}${VERSION}${R_arrow}\n"
[877cc6a]684}
685
686#----------------------------#
687extract_commands() { #
688#----------------------------#
689
690 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
691 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
692 exit 1"
693
694 cd $JHALFSDIR
[1ff6768]695 case $PROGNAME in
[a6655ff]696 clfs)
[1ff6768]697 VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
698 *)
699 VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
700 esac
[877cc6a]701
702 # Start clean
[bfc07d6]703 if [ -d ${PROGNAME}-commands ]; then
704 rm -rf ${PROGNAME}-commands
705 mkdir -v ${PROGNAME}-commands
[877cc6a]706 fi
707 echo -n "Extracting commands for"
708
709 # Dump the commands in shell script form from the HLFS book.
710 case ${PROGNAME} in
711 clfs)
712 echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
713 xsltproc --nonet \
714 --xinclude \
715 --stringparam method $METHOD \
716 --stringparam testsuite $TEST \
717 --stringparam vim-lang $VIMLANG \
718 --stringparam timezone $TIMEZONE \
719 --stringparam page $PAGE \
720 --stringparam lang $LANG \
721 --stringparam keymap $KEYMAP \
722 -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
723 ;;
724 hlfs)
725 echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
726 xsltproc --nonet \
727 --xinclude \
728 --stringparam model $MODEL \
729 --stringparam testsuite $TEST \
730 --stringparam timezone $TIMEZONE \
731 --stringparam page $PAGE \
732 --stringparam lang $LANG \
733 --stringparam lc_all $LC_ALL \
734 --stringparam keymap $KEYMAP \
735 --stringparam grsecurity_host $GRSECURITY_HOST \
736 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
737 ;;
738 lfs)
739 echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
740 xsltproc --nonet \
741 --xinclude \
742 --stringparam testsuite $TEST \
743 --stringparam vim-lang $VIMLANG \
744 --stringparam timezone $TIMEZONE \
745 --stringparam page $PAGE \
746 --stringparam lang $LANG \
747 -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
748 ;;
[15cad16]749 *) exit 1 ;;
[877cc6a]750 esac
751
752 echo " ...OK"
753
754 # Make the scripts executable.
755 chmod -R +x $JHALFSDIR/${PROGNAME}-commands
756
[15cad16]757 # Create the packages file. We need it for proper Makefile creation
[dd29d02]758 create_package_list
[877cc6a]759
760 # Done. Moving on...
761 get_sources
762}
763
[dd29d02]764#----------------------------#
765create_package_list() { #
766#----------------------------#
767
768 # Create the packages file. We need it for proper Makefile creation
769 rm -f pkg_tarball_list
770 echo -n "Creating <${PROGNAME}> list of tarball names for $BOOK $ARCH"
771 case ${PROGNAME} in
772 clfs)
773 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
774 $BOOK/materials/${ARCH}-chapter.xml >>$LOGDIR/$LOG 2>&1
775 ;;
776 hlfs)
777 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
778 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
779 ;;
780 lfs)
781 xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
782 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
783 ;;
784 esac
785 echo " ...OK"
786
787}
788
789
[877cc6a]790#----------------------------#
[15cad16]791get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
[93135fd]792#----------------------------#
793 local saveIFS=$IFS
[26053c4]794 local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE
[93135fd]795
796 # Test if the packages must be downloaded
797 [ ! "$GETPKG" = "1" ] && return
798
799 gs_wrt_message(){
800 echo "${RED}$1${OFF}"
[c7dbe78]801 echo "$1" >> MISSING_FILES.DMP
802 }
[93135fd]803 # Housekeeping
804 [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
805 cd $BUILDDIR/sources
806 [[ -f MD5SUMS ]] && rm MD5SUMS
807 [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
808 [[ -f urls.lst ]] && rm urls.lst
809
810 # Generate URLs file
811 create_urls
812
813 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
814 for line in `cat urls.lst`; do
815 IFS=$saveIFS # Restore the system defaults
816
817 # Skip some packages if they aren't needed
818 case $line in
819 */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
820 [[ "$TEST" = "0" ]] && continue
821 ;;
822 */vim-*-lang* )
823 [[ "$VIMLANG" = "0" ]] && continue
824 ;;
[0c3f2f9]825 *linux/linux-* )
[294c937]826 [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
827 [[ "$GETKERNEL" = "0" ]] && continue
[0c3f2f9]828 ;;
[93135fd]829 esac
830
831 # Locations
[296ae69]832 URL1=`echo $line | cut -d" " -f2` # Preferred URL
833 URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
[26053c4]834 FILE=`basename $URL1` # File name
835 BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
836
[8a43b5b]837 # Validation pair
838 MD5="$BOOKMD5 $FILE"
839 HAVEMD5=1
[93135fd]840
841 set -e
[c7dbe78]842 # If the file exists in the archive copy it to the
[93135fd]843 # $BUILDDIR/sources dir. MD5SUM will be validated later.
844 if [ ! -z ${SRC_ARCHIVE} ] &&
845 [ -d ${SRC_ARCHIVE} ] &&
846 [ -f ${SRC_ARCHIVE}/$FILE ]; then
847 cp ${SRC_ARCHIVE}/$FILE .
848 echo "$FILE: -- copied from $SRC_ARCHIVE"
849 fromARCHIVE=1
850 else
851 echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
852 fromARCHIVE=0
[8a43b5b]853 # If the file does not exist yet in /sources download a fresh one
[93135fd]854 if [ ! -f $FILE ] ; then
855 if ! wget $URL1 && ! wget $URL2 ; then
[c7dbe78]856 gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
857 continue
[93135fd]858 fi
859 fi
860 fi
861
[8a43b5b]862 # IF the md5sum does not match the existing files
863 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
864 [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
865 [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
866 # Remove the old file and download a new one
867 rm -fv $FILE
868 # Force storage in SRC_ARCHIVE
869 fromARCHIVE=0;
870 # Try to retrieve again the file. Servers in reverse order.
871 if ! wget $URL2 && ! wget $URL1 ; then
872 gs_wrt_message "$FILE not found on the servers.. SKIPPING"
873 continue
[93135fd]874 fi
875 fi
876
877 # Validate the MD5SUM one last time
[8a43b5b]878 if ! echo "$MD5" | md5sum -c - >/dev/null ; then
[93135fd]879 gs_wrt_message "$FILE does not match MD5SUMS value"
[0910f55]880 # Force generation of MD5SUM
881 HAVEMD5=0
[93135fd]882 fi
883
884 # Generate a fresh MD5SUM for this file
885 if [[ "$HAVEMD5" = "0" ]] ; then
886 echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
[8a43b5b]887 echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
[93135fd]888 fi
889
890 # Good or bad we write the original md5sum to a file
[8a43b5b]891 echo "$MD5" >> MD5SUMS
[93135fd]892
893 # Copy the freshly downloaded file
894 # to the source archive.
895 if [ ! -z ${SRC_ARCHIVE} ] &&
896 [ -d ${SRC_ARCHIVE} ] &&
897 [ -w ${SRC_ARCHIVE} ] &&
898 [ "$fromARCHIVE" = "0" ] ; then
899 echo "Storing file:<$FILE> in the package archive"
900 cp -f $FILE ${SRC_ARCHIVE}
901 fi
902
903 done
904
905 if [[ -s MISSING_FILES.DMP ]]; then
906 echo -e "\n\n${tab_}${RED} One or more files were not retrieved or have a bad MD5SUMS chechsum.\n${tab_} Check ${L_arrow}$BUILDDIR/sources/MISSING_FILES.DMP${R_arrow} for names ${OFF}\n"
907 # Do not allow the automatic exection of the Makefile.
[261eea6]908 echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
[93135fd]909 RUNMAKE=0
910 fi
911}
912
[877cc6a]913#----------------------------#
[15cad16]914create_urls() { #
[877cc6a]915#----------------------------#
[15cad16]916 cd $JHALFSDIR
[877cc6a]917
[15cad16]918 case ${PROGNAME} in
919 clfs)
920 echo -n "Creating CLFS <${ARCH}> specific URLs file"
921 xsltproc --nonet --xinclude \
922 --stringparam server $SERVER \
923 -o $BUILDDIR/sources/urls.lst urls.xsl \
924 $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
925 echo " ...OK"
926 ;;
927 hlfs)
928 echo -n "Creating HLFS <${MODEL}> specific URLs file"
929 xsltproc --nonet --xinclude \
930 --stringparam server $SERVER \
931 --stringparam model $MODEL \
932 -o $BUILDDIR/sources/urls.lst urls.xsl \
933 $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
934 echo " ...OK"
935 ;;
936 lfs)
937 echo -n "Creating LFS specific URLs file"
938 xsltproc --nonet --xinclude \
939 --stringparam server $SERVER \
940 -o ../sources/urls.lst urls.xsl \
941 $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
942 echo " ...OK"
943 ;;
944 esac
[877cc6a]945
[15cad16]946 cd $BUILDDIR/sources
[877cc6a]947}
Note: See TracBrowser for help on using the repository browser.