2018-02-01 16:34:02 +08:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2019-07-12 15:53:54 +08:00
|
|
|
|
###################################################################################
|
|
|
|
|
# 控制台颜色
|
|
|
|
|
BLACK="\033[1;30m"
|
|
|
|
|
RED="\033[1;31m"
|
|
|
|
|
GREEN="\033[1;32m"
|
|
|
|
|
YELLOW="\033[1;33m"
|
|
|
|
|
BLUE="\033[1;34m"
|
|
|
|
|
PURPLE="\033[1;35m"
|
|
|
|
|
CYAN="\033[1;36m"
|
|
|
|
|
RESET="$(tput sgr0)"
|
|
|
|
|
###################################################################################
|
|
|
|
|
|
|
|
|
|
printf "${BLUE}"
|
2019-05-07 11:19:36 +08:00
|
|
|
|
cat << EOF
|
2019-07-12 15:53:54 +08:00
|
|
|
|
|
2018-02-23 17:33:12 +08:00
|
|
|
|
###################################################################################
|
2019-05-07 11:19:36 +08:00
|
|
|
|
# 安装 Maven3 脚本
|
2018-09-29 10:16:24 +08:00
|
|
|
|
# Maven 会被安装到 /opt/maven 路径。
|
2019-05-07 14:29:16 +08:00
|
|
|
|
# @system: 适用于所有 linux 发行版本。
|
2018-02-23 17:33:12 +08:00
|
|
|
|
# 注意:Maven 要求必须先安装 JDK
|
2019-05-07 14:29:16 +08:00
|
|
|
|
# @author: Zhang Peng
|
2018-02-23 17:33:12 +08:00
|
|
|
|
###################################################################################
|
2019-07-12 15:53:54 +08:00
|
|
|
|
|
2019-05-07 11:19:36 +08:00
|
|
|
|
EOF
|
2019-07-12 15:53:54 +08:00
|
|
|
|
printf "${RESET}"
|
|
|
|
|
|
|
|
|
|
printf "${GREEN}>>>>>>>> install maven begin.${RESET}\n"
|
2018-02-23 17:33:12 +08:00
|
|
|
|
|
2019-10-29 18:22:19 +08:00
|
|
|
|
command -v java > /dev/null 2>&1 || {
|
|
|
|
|
printf "${RED}Require java but it's not installed.${RESET}\n";
|
|
|
|
|
exit 1;
|
|
|
|
|
}
|
2019-05-09 11:26:06 +08:00
|
|
|
|
|
2019-10-10 08:56:31 +08:00
|
|
|
|
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]]; then
|
2019-10-29 18:22:19 +08:00
|
|
|
|
printf "${PURPLE}[Hint]\n"
|
|
|
|
|
printf "\t sh maven-install.sh [version] [path]\n"
|
|
|
|
|
printf "\t Example: sh maven-install.sh 3.6.0 /opt/maven\n"
|
|
|
|
|
printf "${RESET}\n"
|
2019-05-09 11:26:06 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2019-12-30 16:30:18 +08:00
|
|
|
|
version=3.5.4
|
2019-05-07 11:19:36 +08:00
|
|
|
|
if [[ -n $1 ]]; then
|
2019-10-29 18:22:19 +08:00
|
|
|
|
version=$1
|
2019-05-07 11:19:36 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2019-07-12 15:53:54 +08:00
|
|
|
|
path=/opt/maven
|
2019-05-07 11:19:36 +08:00
|
|
|
|
if [[ -n $2 ]]; then
|
2019-10-29 18:22:19 +08:00
|
|
|
|
path=$2
|
2019-05-07 11:19:36 +08:00
|
|
|
|
fi
|
2018-02-01 16:34:02 +08:00
|
|
|
|
|
2019-07-12 15:53:54 +08:00
|
|
|
|
# install info
|
|
|
|
|
printf "${PURPLE}[Info]\n"
|
|
|
|
|
printf "\t version = ${version}\n"
|
|
|
|
|
printf "\t path = ${path}\n"
|
|
|
|
|
printf "${RESET}\n"
|
2019-05-07 11:19:36 +08:00
|
|
|
|
|
2019-07-12 15:53:54 +08:00
|
|
|
|
# download and decompression
|
|
|
|
|
mkdir -p ${path}
|
2019-12-30 16:30:18 +08:00
|
|
|
|
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" -O ${path}/apache-maven-${version}-bin.tar.gz http://apache.01link.hk/maven/maven-3/${version}/binaries/apache-maven-${version}-bin.tar.gz
|
2019-07-12 15:53:54 +08:00
|
|
|
|
tar -zxvf ${path}/apache-maven-${version}-bin.tar.gz -C ${path}
|
2018-02-02 17:53:50 +08:00
|
|
|
|
|
2019-07-12 15:53:54 +08:00
|
|
|
|
# setting env
|
|
|
|
|
path=${path}/apache-maven-${version}
|
2018-02-02 17:53:50 +08:00
|
|
|
|
cat >> /etc/profile << EOF
|
2019-05-07 11:39:42 +08:00
|
|
|
|
export MAVEN_HOME=${path}
|
2018-02-23 17:33:12 +08:00
|
|
|
|
export PATH=\$MAVEN_HOME/bin:\$PATH
|
2018-02-02 17:53:50 +08:00
|
|
|
|
EOF
|
|
|
|
|
source /etc/profile
|
2019-02-22 17:09:40 +08:00
|
|
|
|
|
2019-07-12 15:53:54 +08:00
|
|
|
|
# replace mirrors in settings.xml
|
2019-05-07 11:39:42 +08:00
|
|
|
|
echo -e "\n>>>>>>>>> replace ${path}/conf/settings.xml"
|
|
|
|
|
cp ${path}/conf/settings.xml ${path}/conf/settings.xml.bak
|
2019-05-16 11:49:19 +08:00
|
|
|
|
wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/settings-aliyun.xml -O ${path}/conf/settings.xml
|
2019-05-07 12:07:59 +08:00
|
|
|
|
|
2019-07-12 15:53:54 +08:00
|
|
|
|
printf "${GREEN}<<<<<<<< install maven end.${RESET}\n"
|
2019-05-07 12:07:59 +08:00
|
|
|
|
mvn -v
|