Maven二进制安装
tips::: 其中用到了sed多行插入的命令,可以参考 :::
#!/bin/bash
install(){
url="https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz"
filename=`basename $url`
[ -f $filename ] || wget $url
tar xf $filename -C /usr/local
ln -s /usr/local/${filename%-bin.tar.gz} /usr/local/maven
echo 'PATH=/usr/local/maven/bin:$PATH' > /etc/profile.d/maven.sh
cat > /etc/profile.d/maven.sh <<-EOF
PATH=/usr/local/maven/bin:$PATH
export MAVEN_HOME=/usr/local/maven
EOF
. /etc/profile.d/maven.sh
mvn -v && echo 安装成功,请重启shell || echo 安装失败
}
#配置镜像加速
set_mirror(){
# sed 插入多行
sed -ri.bak '/<mirrors>/a \
<!-- 添加阿里云镜像加速 --> \
<mirror> \
<id>aliyunmaven</id> \
<mirrorOf>*</mirrorOf> \
<name>阿里云公共仓库</name> \
<url>http://maven.aliyun.com/nexus/content/groups/public/</url> \
</mirror>' /usr/local/maven/conf/settings.xml
}
install
set_mirror