当前位置:   article > 正文

centos7 yum安装maven_centos7 shell脚本一键安装maven

installmaven.sh

最近装什么都希望自己有个一键脚本来搞定,今天看到以前的maven还没有写一键安装脚本,所以今天把他补起.

系统:centos 7(64位)

cat /root/soft_shell/auto_install_maven.sh

#!/bin/bash

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

export PATH

# Check if user is root

if [ $(id -u) != "0" ]; then

echo "Error: You must be root to run this script, please use root to initialization OS."

exit 1

fi

rpm=`yum list installed |grep -e java -e jdk|wc -l`

if [[ $rpm -eq 0 ]];then

yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel &> /dev/null

b="JDK is not installed. Now the installation"

i=0

while [ $i -le 100 ]

do

printf "[%-50s] %d%% \r" "$b" "$i";

sleep 0.2

((i=i+2))

b+='#'

done

echo

fi

mavenversion="3.6.3"

VERSIONPATTERN="[0-9]{1}.[0-9]{1}.[0-9]{1}"

echo -n "Please input a maven version number (Enter 3.6.3): "

read customVersion

if [ ! -z $customVersion ]

then

macthResult=$(echo $customVersion | grep -E -x $VERSIONPATTERN )

if [ -z $macthResult ]

then

echo "Please input a right version number. eg. 3.0.5 or 3.6.3"

exit 1

fi

mavenversion=$customVersion

fi

number=`echo $mavenversion|awk -F '.' '{print $1}'`

maven_name="apache-maven-$mavenversion"

if [ ! -s $maven_name-bin.tar.gz ];then

wget http://mirror.bit.edu.cn/apache/maven/maven-$number/$mavenversion/binaries/$maven_name-bin.tar.gz

fi

if [ ! -s /usr/local/maven ];then

tar zxf $maven_name-bin.tar.gz

mv $maven_name /usr/local/maven

ln -s /usr/local/maven/bin/mvn /usr/bin/mvn

else

rm -fr /usr/local/maven

rm -f /usr/bin/mvn

tar zxf $maven_name-bin.tar.gz

mv $maven_name /usr/local/maven

ln -s /usr/local/maven/bin/mvn /usr/bin/mvn

fi

echo -e "\nInstalled maven version is ... "

mvn -v

[ $? -eq 0 ] && echo -e "\033[32m \nMaven installation successful! \033[0m"

夜空- 本站版权

1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权

2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意

3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责

4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

5、原文链接:blog.slogra.com/post-769.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/139814
推荐阅读
相关标签
  

闽ICP备14008679号