Reorganized the script.

Added jhalfs.conf to have more control over the configuration.
Many thanks to George B.
This commit is contained in:
Manuel Canales Esparcia 2005-10-24 17:53:50 +00:00
parent 741fbe5641
commit 49aea5ef15
2 changed files with 275 additions and 212 deletions

446
jhalfs
View file

@ -1,5 +1,11 @@
#!/bin/sh #!/bin/sh
#
# Load the configuration file
#
. jhalfs.conf
version=" version="
jhalfs development \$Date$ jhalfs development \$Date$
@ -75,182 +81,21 @@ no_dl_client="\
echo \"Could not find a way to download the LFS sources.\" >&2 echo \"Could not find a way to download the LFS sources.\" >&2
echo \"Attempting to continue.\" >&2" echo \"Attempting to continue.\" >&2"
while test $# -gt 0 ; do
case $1 in
--version | -V )
echo "$version"
exit 0
;;
--help | -h )
echo "$usage"
exit 0
;;
--LFS-version | -L )
test $# = 1 && eval "$exit_missing_arg"
shift
case $1 in
dev* | SVN | trunk )
LFSVRS=development
;;
testing | 6.1.1 )
LFSVRS=6.1.1
;;
* )
echo "$1 is an unsupported version at this time."
exit 1
;;
esac
shift
;;
--directory | -d )
test $# = 1 && eval "$exit_missing_arg"
shift
BUILDDIR=$1
shift
;;
--download-client | -D )
test $# = 1 && eval "$exit_missing_arg"
shift
DL=$1
shift
;;
--working-copy | -W )
test $# = 1 && eval "$exit_missing_arg"
shift
if [ -f $1/patches.ent ] ; then
WC=1
BOOK=$1
else
echo -e "\nLook like $1 isn't a supported working copy."
echo -e "Verify your selection and the command line.\n"
exit 1
fi
shift
;;
--testsuites | -T )
TEST=1
shift
;;
--get-packages | -P )
HPKG=1
shift
;;
--run-make | -M )
RUNMAKE=1
shift
;;
--page_size )
test $# = 1 && eval "$exit_missing_arg"
shift
case $1 in
letter | A4 )
PAGE=$1
;;
* )
echo "$1 isn't a supported page size."
exit 1
;;
esac
shift
;;
--no-toolchain-test )
TOOLCHAINTEST=0
shift
;;
--timezone )
test $# = 1 && eval "$exit_missing_arg"
shift
if [ -f /usr/share/zoneinfo/$1 ] ; then
TIMEZONE=$1
else
echo -e "\nLook like $1 isn't a valid timezone description."
echo -e "Verify your selection and the command line.\n"
exit 1
fi
shift
;;
--fstab )
test $# = 1 && eval "$exit_missing_arg"
shift
if [ -f $1 ] ; then
FSTAB=$1
else
echo -e "\nFile $1 not found. Verify your command line.\n"
exit 1
fi
shift
;;
--kernel-config | -C )
test $# = 1 && eval "$exit_missing_arg"
shift
if [ -f $1 ] ; then
CONFIG=$1
else
echo -e "\nFile $1 not found. Verify your command line.\n"
exit 1
fi
shift
;;
* )
echo "$usage"
exit 1
;;
esac
done
# Test to make sure we're running the build as root
if [ "$UID" != "0" ] ; then
echo "You must be logged in as root to successfully build LFS."
exit 1
fi
# Find the download client to use, if not already specified.
if [ -z $DL ] ; then
if [ `type -p wget` ] ; then
DL=wget
elif [ `type -p curl` ] ; then
DL=curl
else
eval "$no_dl_client"
fi
fi
SVN="svn://svn.linuxfromscratch.org"
HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
JHALFSDIR=$BUILDDIR/jhalfs
LOGDIR=$JHALFSDIR/logs
LOG=000-jhalfs.log
MKFILE=$JHALFSDIR/Makefile
XSL=dump-lfs-scripts.xsl
FNC=functions
if [ -z $TEST ] ; then TEST=0 ; fi
if [ -z $TOOLCHAINTEST ] ; then TOOLCHAINTEST=1 ; fi
if [ -z $PAGE ] ; then PAGE=letter ; fi
if [ -z $TIMEZONE ] ; then TIMEZONE=Europe/London ; fi
HEADER="# This file is automatically generated by jhalfs HEADER="# This file is automatically generated by jhalfs
# DO NOT EDIT THIS FILE MANUALLY # DO NOT EDIT THIS FILE MANUALLY
# #
# Generated on `date \"+%F %X %Z\"`" # Generated on `date \"+%F %X %Z\"`"
###################################
### FUNCTIONS ###
###################################
#----------------------------#
get_book() { get_book() {
#----------------------------#
# Check for Subversion instead of just letting the script hit 'svn' and fail. # Check for Subversion instead of just letting the script hit 'svn' and fail.
test `type -p svn` || eval "echo \"This feature requires Subversion.\" test `type -p svn` || eval "echo \"This feature requires Subversion.\"
exit 1" exit 1"
@ -296,7 +141,9 @@ get_book() {
VERSION=`grep "ENTITY version " $BOOK/general.ent | sed -e 's@<!ENTITY version "@@' -e 's@">@@'` VERSION=`grep "ENTITY version " $BOOK/general.ent | sed -e 's@<!ENTITY version "@@' -e 's@">@@'`
} }
#----------------------------#
extract_commands() { extract_commands() {
#----------------------------#
# Check for libxslt instead of just letting the script hit 'xsltproc' and fail. # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\" test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
exit 1" exit 1"
@ -331,7 +178,9 @@ extract_commands() {
get_sources get_sources
} }
#----------------------------#
download() { download() {
#----------------------------#
cd $BUILDDIR/sources cd $BUILDDIR/sources
# Hackish fix for the bash-doc and glibc-{linuxthreads,libidn} packages that # Hackish fix for the bash-doc and glibc-{linuxthreads,libidn} packages that
@ -371,7 +220,9 @@ download() {
fi fi
} }
#----------------------------#
get_sources() { get_sources() {
#----------------------------#
# Test if the packages must be downloaded # Test if the packages must be downloaded
if [ "$HPKG" = "1" ] ; then if [ "$HPKG" = "1" ] ; then
@ -426,13 +277,44 @@ get_sources() {
fi fi
} }
build_Makefile() { #----------------------------#
echo -n "Creating Makefile... " chapter4_Makefiles() {
cd $JHALFSDIR/commands #----------------------------#
(
cat << EOF
020-creatingtoolsdir:
@\$(call echo_message, Building)
@mkdir -v \$(LFS)/tools && \\
ln -sv \$(LFS)/tools / && \\
touch \$@
# Start with a clean Makefile.tmp file 021-addinguser: 020-creatingtoolsdir
>$MKFILE.tmp @\$(call echo_message, Building)
@groupadd lfs && \\
useradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\
chown lfs \$(LFS)/tools && \\
chown lfs \$(LFS)/sources && \\
touch \$@
022-settingenvironment: 021-addinguser
@\$(call echo_message, Building)
@echo "set +h" > /home/lfs/.bashrc && \\
echo "umask 022" >> /home/lfs/.bashrc && \\
echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
chown lfs:lfs /home/lfs/.bashrc && \\
touch envars && \\
touch \$@
EOF
) >> $MKFILE.tmp
}
#----------------------------#
chapter5_Makefiles() {
#----------------------------#
for file in chapter05/* ; do for file in chapter05/* ; do
# Keep the script file name # Keep the script file name
i=`basename $file` i=`basename $file`
@ -588,8 +470,12 @@ EOF
# Keep the script file name for Makefile dependencies. # Keep the script file name for Makefile dependencies.
PREV=$i PREV=$i
done done # end for file in chapter05/*
}
#----------------------------#
chapter6_Makefiles() {
#----------------------------#
for file in chapter06/* ; do for file in chapter06/* ; do
# Keep the script file name # Keep the script file name
i=`basename $file` i=`basename $file`
@ -722,8 +608,12 @@ EOF
# Keep the script file name for Makefile dependencies. # Keep the script file name for Makefile dependencies.
PREV=$i PREV=$i
done done # end for file in chapter06/*
}
#----------------------------#
chapter789_Makefiles() {
#----------------------------#
for file in chapter0{7,8,9}/* ; do for file in chapter0{7,8,9}/* ; do
# Keep the script file name # Keep the script file name
i=`basename $file` i=`basename $file`
@ -827,7 +717,24 @@ EOF
# Keep the script file name for Makefile dependencies. # Keep the script file name for Makefile dependencies.
PREV=$i PREV=$i
done done # for file in chapter0{7,8,9}/*
}
#----------------------------#
build_Makefile() {
#----------------------------#
echo -n "Creating Makefile... "
cd $JHALFSDIR/commands
# Start with a clean Makefile.tmp file
>$MKFILE.tmp
chapter4_Makefiles
chapter5_Makefiles
chapter6_Makefiles
chapter789_Makefiles
# Add a header, some variables and include the function file # Add a header, some variables and include the function file
# to the top of the real Makefile. # to the top of the real Makefile.
@ -850,7 +757,8 @@ EOF
i=1 i=1
for file in chapter06/*chroot* ; do for file in chapter06/*chroot* ; do
chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \ chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
-e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' -e 's|"$$LFS"|$(LFS)|'` -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
-e 's|"$$LFS"|$(LFS)|' -e 's|set -e||'`
echo -e "CHROOT$i= $chroot\n" >> $MKFILE echo -e "CHROOT$i= $chroot\n" >> $MKFILE
i=`expr $i + 1` i=`expr $i + 1`
done done
@ -888,32 +796,6 @@ clean-chapter5:
rm -f $chapter5 rm -f $chapter5
cd logs && rm -f $chapter5 && cd .. cd logs && rm -f $chapter5 && cd ..
020-creatingtoolsdir:
@\$(call echo_message, Building)
@mkdir -v \$(LFS)/tools && \\
ln -sv \$(LFS)/tools / && \\
touch \$@
021-addinguser: 020-creatingtoolsdir
@\$(call echo_message, Building)
@groupadd lfs && \\
useradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\
chown lfs \$(LFS)/tools && \\
chown lfs \$(LFS)/sources && \\
touch \$@
022-settingenvironment: 021-addinguser
@\$(call echo_message, Building)
@echo "set +h" > /home/lfs/.bashrc && \\
echo "umask 022" >> /home/lfs/.bashrc && \\
echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
chown lfs:lfs /home/lfs/.bashrc && \\
touch envars && \\
touch \$@
EOF EOF
) >> $MKFILE ) >> $MKFILE
@ -923,7 +805,9 @@ EOF
echo -ne "done\n" echo -ne "done\n"
} }
#----------------------------#
run_make() { run_make() {
#----------------------------#
# Test if make must be run. # Test if make must be run.
if [ "$RUNMAKE" = "1" ] ; then if [ "$RUNMAKE" = "1" ] ; then
# Build the system # Build the system
@ -935,20 +819,158 @@ run_make() {
fi fi
} }
if [ ! -d $JHALFSDIR ] ; then
mkdir -pv $JHALFSDIR
###################################
### MAIN ###
###################################
# Test to make sure we're running the build as root
if [ "$UID" != "0" ] ; then
echo "You must be logged in as root to successfully build LFS."
exit 1
fi fi
if [ ! -d $LOGDIR ] ; then # Find the download client to use, if not already specified.
mkdir -v $LOGDIR
if [ -z $DL ] ; then
if [ `type -p wget` ] ; then
DL=wget
elif [ `type -p curl` ] ; then
DL=curl
else
eval "$no_dl_client"
fi
fi fi
# Evaluate any command line switches
while test $# -gt 0 ; do
case $1 in
--version | -V )
echo "$version"
exit 0
;;
--help | -h )
echo "$usage"
exit 0
;;
--LFS-version | -L )
test $# = 1 && eval "$exit_missing_arg"
shift
case $1 in
dev* | SVN | trunk )
LFSVRS=development
;;
testing | 6.1.1 )
LFSVRS=6.1.1
;;
* )
echo "$1 is an unsupported version at this time."
exit 1
;;
esac
;;
--directory | -d )
test $# = 1 && eval "$exit_missing_arg"
shift
BUILDDIR=$1
;;
--download-client | -D )
test $# = 1 && eval "$exit_missing_arg"
shift
DL=$1
;;
--working-copy | -W )
test $# = 1 && eval "$exit_missing_arg"
shift
if [ -f $1/patches.ent ] ; then
WC=1
BOOK=$1
else
echo -e "\nLook like $1 isn't a supported working copy."
echo -e "Verify your selection and the command line.\n"
exit 1
fi
;;
--testsuites | -T ) TEST=1 ;;
--get-packages | -P ) HPKG=1 ;;
--run-make | -M ) RUNMAKE=1 ;;
--no-toolchain-test ) TOOLCHAINTEST=0 ;;
--page_size )
test $# = 1 && eval "$exit_missing_arg"
shift
case $1 in
letter | A4 )
PAGE=$1
;;
* )
echo "$1 isn't a supported page size."
exit 1
;;
esac
;;
--timezone )
test $# = 1 && eval "$exit_missing_arg"
shift
if [ -f /usr/share/zoneinfo/$1 ] ; then
TIMEZONE=$1
else
echo -e "\nLook like $1 isn't a valid timezone description."
echo -e "Verify your selection and the command line.\n"
exit 1
fi
;;
--fstab )
test $# = 1 && eval "$exit_missing_arg"
shift
if [ -f $1 ] ; then
FSTAB=$1
else
echo -e "\nFile $1 not found. Verify your command line.\n"
exit 1
fi
;;
--kernel-config | -C )
test $# = 1 && eval "$exit_missing_arg"
shift
if [ -f $1 ] ; then
CONFIG=$1
else
echo -e "\nFile $1 not found. Verify your command line.\n"
exit 1
fi
;;
* )
echo "$usage"
exit 1
;;
esac
shift
done
[[ ! -d $JHALFSDIR ]] && mkdir -pv $JHALFSDIR
[[ "$PWD" != "$JHALFSDIR" ]] && cp -v $0 $XSL $FILES $JHALFSDIR/
[[ ! -d $LOGDIR ]] && mkdir -v $LOGDIR
>$LOGDIR/$LOG >$LOGDIR/$LOG
if [ "$PWD" != "$JHALFSDIR" ] ; then
cp -v $0 $XSL $FNC $JHALFSDIR/
fi
get_book get_book
build_Makefile build_Makefile
run_make run_make

41
jhalfs.conf Normal file
View file

@ -0,0 +1,41 @@
#####
#
# Configuration file for the jhalfs build script
#
#####
declare -r SVN="svn://svn.linuxfromscratch.org"
declare -r HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
declare -r XSL=dump-lfs-scripts.xsl
declare -r FILES="functions jhalfs.conf"
declare -r LOG=000-jhalfs.log
#--- Mount point for the build
BUILDDIR=/mnt/lfs
#--- Working directories
JHALFSDIR=$BUILDDIR/jhalfs
LOGDIR=$JHALFSDIR/logs
MKFILE=$JHALFSDIR/Makefile
#--- Download the source packages 0(no)/1(yes)
HPKG=0
#--- Run the makefile at the end 0(no)/1(yes)
RUNMAKE=0
#--- Run test suites 0(no)/1(yes)
TEST=0
#--- Run the toolchain tests 0(no)/1(yes)
TOOLCHAINTEST=1
#--- page definition for groff letter/A4
PAGE=letter
#--- set default timezone.
TIMEZONE=Europe/London
#--- Location of kernel config file (if the kernel is to be compiled)
CONFIG=