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

写个自动下载安装Ant的shell脚本【二】

2013-06-21 07:27 519 查看
#!/bin/bash

######################################################
# file name: install_ant.sh
#
# function:
# To quickly install ant automatically
# in linux system...
#
# author: jeffzhao
# date: 2013.6.19
#
#
#
######################################################
ant_package_path="./"
ant_install_path="/opt/test/ant"
ant_package_name="apache-ant-1.9.1-bin.tar.gz"
ant_download_url="http://www.apache.org/dist/ant/binaries"/${ant_package_name}
antMD5_download_url="http://www.apache.org/dist/ant/binaries"/${ant_package_name}.md5

######################################################
# download from wen ftp
#
######################################################
function download_ant()
{
wget ${ant_download_url} >/dev/null
wget ${antMD5_download_url} >/dev/null
}

######################################################
# check package and package path
#
######################################################
function check_env()
{
# To Make Sure Ant Pakcage Path is Ok
if [ ! -d ${ant_package_path} ]
then
mkdir -p ${ant_package_path}
fi

# To Make Sure Ant Pakcage is OK

ls ${ant_package_path}| grep .tar.gz$ | grep ant >/dev/null

if [ $? == 1 ]
then
download_ant
check_md5
if [ $? != 0 ]
then
check_env
fi
else
ant_package_name= ls ${ant_package_path}| grep .tar.gz$
fi
}

######################################################
# check package md5
#
######################################################
function check_md5()
{
grep `md5sum ${ant_package_name} | cut -c 1-32` ${ant_package_name}.md5 >/dev/null
return $?
}

######################################################
# unzip package and copy files to install path
#
######################################################
function install_ant()
{
if [ ! -d ${ant_install_path} ]
then
mkdir -p ${ant_install_path}
fi

### clear env
rm -rf ${ant_install_path}/*

###
tar -xzvf ${ant_package_name}
mv `ls -l | grep ^d | grep ant | awk '{print$8}'` ${ant_install_path}
}

######################################################
# main
#
######################################################
function main()
{
## check root right
if [ `whoami` != 'root' ]
then
exit
fi

echo "Preinstall Checking start"
check_env
install_ant
}

main
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: