您的位置:首页 > 运维架构 > Shell

shell脚本实现自动编译安装

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

脚本如下:

#!/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下,依赖关系复杂,很常见,你可以用这种方法,自动安装,省去不少麻烦!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: