Skip to content

Instantly share code, notes, and snippets.

@ejlp12
Last active December 23, 2022 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ejlp12/c38420520605dd5bb8f1 to your computer and use it in GitHub Desktop.
Save ejlp12/c38420520605dd5bb8f1 to your computer and use it in GitHub Desktop.
Install Maven Script
JAVA_VERSION=1.8
MAVEN_DIR=`pwd`/maven
MAVEN_FILE=apache-maven-3.3.9-bin.tar.gz
MAVEN_URL=http://www.eu.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
printf "Checking JRE..\n"
JRE_VERSION=`java -version 2>&1 >/dev/null |grep "1.8" |grep $JAVA_VERSION`
if [ -n "$JRE_VERSION" ]; then
printf "Installed: $JRE_VERSION\n"
else
printf "JDK $JAVA_VERSION is not installed yet, trying to install using yum\n"
su -c "yum -y install java-1.8.0-openjdk"
fi
printf "Start install Apache Maven..\n"
maven_version=`mvn -version | grep "Apache Maven" | cut -d'(' -f1 `
if [ -n "$maven_version" ]; then
printf "Maven is already installed: $maven_version\n"
else
if [ ! -f ./$MAVEN_FILE ]; then
printf "Download Apache Maven...\n"
curl -O $MAVEN_URL
fi
if [ ! -d $MAVEN_DIR ]; then
mkdir -p $MAVEN_DIR
fi
printf "Extracting Apache Maven package...\n"
tar zxvf $MAVEN_FILE -C $MAVEN_DIR
if [ ! -h $MAVEN_DIR/maven ]; then
ln -s $MAVEN_DIR/apache-maven-3.3.9 $MAVEN_DIR/maven
fi
if [[ ! $(grep maven /etc/profile) ]]; then
printf "Adding Maven to PATH \n"
cat >> /etc/profile << __EOF__
fi
PATH=\$PATH:$MAVEN_DIR/bin
export PATH
__EOF__
source /etc/profile
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment