Skip to content

Instantly share code, notes, and snippets.

@seanorama
Last active July 10, 2023 03:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save seanorama/532caf72797a31f1a856 to your computer and use it in GitHub Desktop.
Save seanorama/532caf72797a31f1a856 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
# script to install maven
# todo: add method for checking if latest or automatically grabbing latest
mvn_version=${mvn_version:-3.5.2}
url="http://www.mirrorservice.org/sites/ftp.apache.org/maven/maven-3/${mvn_version}/binaries/apache-maven-${mvn_version}-bin.tar.gz"
install_dir="/opt/maven"
if [ -d ${install_dir} ]; then
mv ${install_dir} ${install_dir}.$(date +"%Y%m%d")
fi
mkdir ${install_dir}
curl -fsSL ${url} | tar zx --strip-components=1 -C ${install_dir}
cat << EOF > /etc/profile.d/maven.sh
#!/bin/sh
export MAVEN_HOME=${install_dir}
export M2_HOME=${install_dir}
export M2=${install_dir}/bin
export PATH=${install_dir}/bin:$PATH
EOF
source /etc/profile.d/maven.sh
echo maven installed to ${install_dir}
mvn --version
printf "\n\nTo get mvn in your path, open a new shell or execute: source /etc/profile.d/maven.sh\n"
@gabrielbauman
Copy link

mvn_version=$(curl https://maven.apache.org/download.cgi --silent | grep "Downloading Apache Maven " | grep -oP '[0-9].[0-9]+.[0-9]+')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment