LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 3605|回复: 10

献上我的自动安装脚本(第五章)

[复制链接]
发表于 2004-9-24 19:55:12 | 显示全部楼层 |阅读模式
第一次是按教程安装的,结果发现启动后无法使用网络,于是决定再装一次。
可是安装时间实在太长,于是我写了个脚本来做。这次是第五章的安装。从以lfs用户登录后开始。

用法:复制下面的部分到一个文本文件ai.sh,运行
source ai.sh
则开始。注意:脚本中有一些检测的代码,简单判断是否编译成功。若有错,请多按几次Ctrl-C强制退出(按一次说不定还不行,记得多按几次,谁有更好的办法退出脚本执行?谢谢)

# !/bin/sh
# ----------------------------------------------------------
# Arthur Yang, 2004.09.24
# For charpter 5, LFS ver 5.0 (Chinese version)
# After loginned as lfs at the end of "Add a user: lfs", use
# this script to finish the remainder part of chapter 5.
# Especially for those who build LFS for second time. Just
# save some time, Enjoy it.
# -----------------------------------------------------------




# Shell script functions
home()
{
cd $LFS/sources;
}

btar()
{
        bunzip2 -k $1;
        tar xvf ${1%.bz2};
}

check()
{
        if grep -E "Error|No such file or directory"

$LFS/sources/log.file
        then
                echo $LFS/sources/log.file
                rm $LFS/sources/log.file
                stop
        else
                rm $LFS/sources/log.file               
        fi
}
       

stop()
{
        echo There\'s ERROR! Stopped.
        while test 1
        do
        echo Press Ctrl-C to exit the shell script!
        read
        done
}

#export LFS=/mnt/lfs
#
#
#mkdir $LFS/tools
#ln -s $LFS/tools /
#
## Assume user lfs exists.
#chown lfs $LFS/tools
#chown lfs $LFS/sources
#su - lfs
# Begin from here!

export logfile=$LFS/sources/log.file


cat > ~/.bash_profile << "EOF"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
PATH=/tools/binPATH
export LFS LC_ALL PATH
unset CC CXX CPP LD_LIBRARY_PATH LD_PRELOAD
EOF

source ~/.bash_profile

home
btar binutils-2.14.tar.bz2
cd binutils-2.14 2> $logfile
check
mkdir ../binutils-build
cd ../binutils-build
../binutils-2.14/configure \
    --prefix=/tools --disable-nls
make configure-host
make LDFLAGS="-all-static"
make install
make -C ld clean
make -C ld LDFLAGS="-all-static" LIB_PATH=/tools/lib

home
btar gcc-core-3.3.1.tar.bz2
cd gcc-3.3.1 2> $logfile
check
mkdir ../gcc-build
cd ../gcc-build
../gcc-3.3.1/configure --prefix=/tools \
    --with-local-prefix=/tools \
    --disable-nls --enable-shared \
    --enable-languages=c
make BOOT_LDFLAGS="-static" bootstrap 2> $logfile
check  
make install
ln -sf gcc /tools/bin/cc
home
rm -rf gcc-3.3.1 gcc-core-3.3.1.tar gcc-build

btar linux-2.4.22.tar.bz2
cd linux-2.4.22 2> $logfile
check  
make mrproper
make include/linux/version.h
make symlinks
mkdir /tools/include/asm
cp include/asm/* /tools/include/asm
cp -R include/asm-generic /tools/include
cp -R include/linux /tools/include
touch /tools/include/linux/autoconf.h

home
btar  glibc-2.3.2.tar.bz2
cd  glibc-2.3.2 2> $logfile
check  
btar ../glibc-linuxthreads-2.3.2.tar.bz2
mkdir /tools/etc
touch /tools/etc/ld.so.conf
patch -Np1 -i ../glibc-2.3.2-sscanf-1.patch
mkdir ../glibc-build
cd ../glibc-build 2> $logfile
check  
../glibc-2.3.2/configure --prefix=/tools \
    --disable-profile --enable-add-ons \
    --with-headers=/tools/include \
    --with-binutils=/tools/bin \
    --without-gd
make 2> $logfile
check
make -k check
make install
make localedata/install-locales
home
rm -rf glibc-2.3.2.tar glibc-2.3.2 glibc-build


cd binutils-build 2> $logfile
check
make -C ld install
SPECFILE=/tools/lib/gcc-lib/*/*/specs &&
sed -e 's@ /lib/ld-linux.so.2@ /tools/lib/ld-linux.so.2@g' \
    $SPECFILE > tempspecfile
mv tempspecfile $SPECFILE &&
unset SPECFILE
rm -f /tools/lib/gcc-lib/*/*/include/

{pthread.h,bits/sigthread.h}
echo 'main(){}' > dummy.c
gcc dummy.c
#-------------Check--------------
if
  readelf -l a.out | grep ': /tools'
then
  echo Check OK! Finished the installation of compiler series
  rm dummy.c a.out

else
  rm dummy.c a.out
  echo Compiler check failed!
  stop
fi

home
btar tcl8.4.4-src.tar.bz2
cd tcl8.4.4
cd unix 2> $logfile
check
./configure --prefix=/tools
make
TZ=UTC make test
ln -s tclsh8.4 /tools/bin/tclsh
home
rm tcl8.4.4-src.tar


btar expect-5.39.0.tar.bz2
cd expect-5.39 2> $logfile
check
patch -Np1 -i ../expect-5.39.0-spawn.patch
./configure --prefix=/tools --with-tcl=/tools/lib --with-x=no
make
make test
make SCRIPTS="" install
home
rm -rf tcl8.4.4 expect-5.39 expect-5.39.0.tar


btar dejagnu-1.4.3.tar.bz2
cd dejagnu-1.4.3 2> $logfile
check
./configure --prefix=/tools
make install
home
rm -r dejagnu-1.4.3  dejagnu-1.4.3.tar

btar gcc-core-3.3.1.tar.bz2
btar gcc-g++-3.3.1.tar.bz2
btar gcc-testsuite-3.3.1.tar.bz2
cd   gcc-3.3.1 2> $logfile
check
patch -Np1 -i ../gcc-3.3.1-no_fixincludes-2.patch
patch -Np1 -i ../gcc-3.3.1-specs-2.patch
mkdir ../gcc-build
cd ../gcc-build
../gcc-3.3.1/configure --prefix=/tools \
    --with-local-prefix=/tools \
    --enable-clocale=gnu --enable-shared \
    --enable-threads=posix --enable-__cxa_atexit \
    --enable-languages=c,c++
make 2> $logfile
check
make -k check
../gcc-3.3.1/contrib/test_summary >

$LFS/sources/gcc_compile_log
make install
home
rm -rf gcc-3.3.1 gcc-core-3.3.1.tar gcc-build gcc-g++-

3.3.1.tar gcc-testsuite-3.3.1.tar

btar binutils-2.14.tar.bz2
cd binutils-2.14 2> $logfile
check
mkdir ../binutils-build
cd ../binutils-build
../binutils-2.14/configure --prefix=/tools \
    --enable-shared --with-lib-path=/tools/lib
make 2> $logfile
check
make check 2> $logfile
check
make install
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib

home
btar gawk-3.1.3.tar.bz2
cd gawk-3.1.3 2> $logfile
check
./configure --prefix=/tools
make
make check
make install
home
rm -rf gawk-3.1.3 gawk-3.1.3.tar

btar coreutils-5.0.tar.bz2
cd coreutils-5.0 2> $logfile
check
./configure --prefix=/tools
make
make RUN_EXPENSIVE_TESTS=yes check
make install
home
rm -rf coreutils-5.0 coreutils-5.0.tar

btar bzip2-1.0.2.tar.bz2
cd bzip2-1.0.2 2> $logfile
check
make PREFIX=/tools install
home
rm -rf bzip2-1.0.2

btar gzip-1.3.5.tar.bz2
cd gzip-1.3.5 2> $logfile
check
./configure --prefix=/tools
make
make install
home
rm -rf gzip-1.3.5.tar gzip-1.3.5

btar diffutils-2.8.1.tar.bz2
cd diffutils-2.8.1 2> $logfile
check
./configure --prefix=/tools
make
make install
home
rm -rf diffutils-2.8.1 diffutils-2.8.1.tar

btar findutils-4.1.20.tar.bz2
cd findutils-4.1.20 2> $logfile
check
./configure --prefix=/tools
make
make check
make install
home
rm -rf findutils-4.1.20 findutils-4.1.20.tar

btar make-3.80.tar.bz2
cd make-3.80 2> $logfile
check
./configure --prefix=/tools
make
make check
make install
home
rm -rf make-3.80 make-3.80.tar

btar grep-2.5.1.tar.bz2
cd grep-2.5.1 2> $logfile
check
./configure --prefix=/tools \
    --disable-perl-regexp --with-included-regex
make
make check
make install
home
rm -rf grep-2.5.1 grep-2.5.1.tar

btar sed-4.0.7.tar.bz2
cd sed-4.0.7 2> $logfile
check
./configure --prefix=/tools
make
make check
make install
home
rm -rf sed-4.0.7 sed-4.0.7.tar

btar gettext-0.12.1.tar.bz2
cd gettext-0.12.1 2> $logfile
check
./configure --prefix=/tools
make
make check
make install
home
rm -rf gettext-0.12.1 gettext-0.12.1.tar

btar ncurses-5.3.tar.bz2
cd ncurses-5.3 2> $logfile
check
patch -Np1 -i ../ncurses-5.3-etip-2.patch
patch -Np1 -i ../ncurses-5.3-vsscanf.patch
./configure --prefix=/tools --with-shared \
    --without-debug --without-ada --enable-overwrite
make
make install
home
rm -rf ncurses-5.3 ncurses-5.3.tar

btar patch-2.5.4.tar.bz2
cd patch-2.5.4 2> $logfile
check
CPPFLAGS=-D_GNU_SOURCE ./configure --prefix=/tools
make
make install
home
rm -rf patch-2.5.4.tar patch-2.5.4

btar tar-1.13.25.tar.bz2
cd tar-1.13.25 2> $logfile
check
./configure --prefix=/tools
make
make check
make install
home
rm -rf tar-1.13.25 tar-1.13.25.tar

btar texinfo-4.6.tar.bz2
cd texinfo-4.6 2> $logfile
check
./configure --prefix=/tools
make
make check
make install
home
rm -rf texinfo-4.6 texinfo-4.6.tar

btar bash-2.05b.tar.bz2
cd bash-2.05b 2> $logfile
check
patch -Np1 -i ../bash-2.05b-2.patch
./configure --prefix=/tools
make
make tests
make install
ln -s bash /tools/bin/sh
home
rm -rf bash-2.05b bash-2.05b.tar

btar util-linux-2.12.tar.bz2
cd util-linux-2.12 2> $logfile
check
cp configure configure.backup
sed "s@/usr/include@/tools/include@g" configure.backup >

configure
./configure
make -C lib
make -C mount  mount umount
make -C text-utils  more
cp mount/{,u}mount text-utils/more /tools/bin
home
rm -rf util-linux-2.12.tar util-linux-2.12

btar perl-5.8.0.tar.bz2
cd perl-5.8.0 2> $logfile
check
patch -Np1 -i ../perl-5.8.0-libc-3.patch
chmod u+w hints/linux.sh
echo 'static_ext="IO re Fcntl"' >> hints/linux.sh
./configure.gnu --prefix=/tools
make perl utilities
cp perl pod/pod2man /tools/bin
mkdir -p /tools/lib/perl5/5.8.0
cp -R lib/* /tools/lib/perl5/5.8.0
home
rm -rf perl-5.8.0 perl-5.8.0.tar

strip --strip-unneeded /tools/{,s}bin/*
strip --strip-debug /tools/lib/*
rm -rf /tools/{,share/}{doc,info,man}
 楼主| 发表于 2004-9-24 20:24:13 | 显示全部楼层

不知道怎么修改自己的帖子啊

中间有一句
rm -r dejagun-1.4.3  dejagun-1.4.3.tar
应为
rm -r dejagnu-1.4.3  dejagnu-1.4.3.tar

我把gnu打成了gun,抱歉
发表于 2004-9-24 20:36:36 | 显示全部楼层
我已经帮你改了。

要更改贴子的话,就点击贴子右下方的图标第一个是编辑,第二个是用于回复贴子时引用原贴子内容.

同时也谢谢你的贴子。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2004-9-24 21:00:38 | 显示全部楼层
看到了,非常感谢:)
是我自己没仔细找,真不好意思。

正在写第六章的脚本。
发表于 2004-9-25 18:16:03 | 显示全部楼层
加油,欢迎您继续。
 楼主| 发表于 2004-9-26 01:12:31 | 显示全部楼层
我测试了一下第五章的脚本,发现中途会出错,大概就在gcc和glibc编译的地方。但是我把脚本分段粘贴到终端上执行,又万事ok,真是奇怪啊。所以我还没来得及测试第六章的脚本。写好了,没敢发:)
发表于 2004-10-30 21:18:50 | 显示全部楼层

好贴

好贴,兄弟加油!!
我的lfs在进行中,重启后遇到不能加载sics硬盘的问题,重新编译内核中
发表于 2004-12-23 07:04:57 | 显示全部楼层

这样能退出执行脚本

在.sh文件内写上"set -e"可以退出shell的执行.
#Begin
set -e
我用的check函数大至和你的一样,就是发现错误后用exit退出.
check()
{
..........;
exit 1;
.....;
}
这样不用按C-c键,但一下子就退出了登陆,还得重新进入,且不能发现哪有问题.望指教.为防止对以后的安装产生影响,可以考虑在每次运行完check函数后,用"set +e"恢复至原状.
发表于 2004-12-23 07:12:30 | 显示全部楼层
将其中的cd .. 换成实际的目录即可
发表于 2004-12-24 08:37:29 | 显示全部楼层
我正准备写这样一个脚本,呵呵,你先写了。
不过我还是要写我自己的脚本,自己熟悉一点。
还可以练练SHELL编程。
退出可以用EXIT命令试试。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表