forked from hugojosefson/ubuntu-install-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-maven
executable file
·30 lines (22 loc) · 1009 Bytes
/
install-maven
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
set -e
ORIGINAL_DIR="$(pwd)"
if [ ! -d /opt/apache-maven/ ]; then
which aptitude || sudo apt-get install -y aptitude
which curl || sudo apt-get install -y curl
which wget || sudo apt-get install -y wget
DOWNLOAD_URL=$(curl --silent http://maven.apache.org/download.cgi | hxpipe | grep ^Ahref | grep binaries/apache-maven | grep tar.gz\$ | head -n 1 | cut -d ' ' -f 3)
FILENAME=$(echo $DOWNLOAD_URL | rev | cut -d '/' -f 1 | rev)
FILE=$(dirname $(mktemp))/$FILENAME
wget --continue ${DOWNLOAD_URL} -O $FILE
DIR=$(tar tf $FILE |head -n 1|cut -d '/' -f 1)
sudo chown $USER:$GROUP /opt
tar xf $FILE -C /opt
cd /opt
rm apache-maven || true
ln -s $DIR apache-maven
cd "$ORIGINAL_DIR"
fi
java -version || ./install-java
grep -x 'export PATH=/opt/apache-maven/bin:$PATH' ~/.bashrc || echo -e '\nexport PATH=/opt/apache-maven/bin:$PATH' >> ~/.bashrc
grep -x 'export M2_HOME=/opt/apache-maven' ~/.bashrc || echo export -e '\nM2_HOME=/opt/apache-maven' >> ~/.bashrc