centos7 shell脚本一键安装maven
最近装什么都希望自己有个一键脚本来搞定,今天看到以前的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"
评论: