shell脚本实现自动编译安装

来源:互联网 发布:淘宝店客服招聘 编辑:程序博客网 时间:2024/06/05 09:11

写了个脚本实现许多安装包的自动配置,编译,安装,脚本很简单,关键是我用的时候有个小问题,所以贴出来。

脚本如下:

 

#!/bin/sh

 

#install need root user.

if [  "whoami" != "root"];then

        echo "Installtion this package needs root user."

        exit 1

fi

 

#file exist problem

if [ ! -a /opt/work/libxml2.tar.gz ];then

        echo "The sources of libxml2 is not exist."

        exit

fi

tar xzvf /opt/work/libxml2.tar.gz

#test tar right or not

if [ ! -d /opt/work/libxml2 ];then

        echo "The tar file is not uncompressed."

        exit

fi

#into the directory

cd /opt/work/libxml2

/opt/work/libxml2/configure --prefix=/usr/local

make&make install

#into the root directory

cd /

 

脚本已经结束,可以执行,但是执行的时候不能以./filename.sh的格式,而是必须以source filename.sh的格式来运行,否则在cd /opt/work/libxml2的时候会进不去,当然接下的脚本执行就会错误了!--这是我犯错的地方。

 

如果你要编译安装很多tar包,在linux下,依赖关系复杂,很常见,你可以用这种方法,自动安装,省去不少麻烦!