Last active
June 18, 2024 23:35
-
-
Save ctubbsii/65fa93e019530b4be99e2ce7989380d7 to your computer and use it in GitHub Desktop.
A simple tool to download and use the latest Maven version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/bash | |
set -e | |
cd "$(dirname "$0")" | |
# check if running in a color terminal | |
terminalSupportsColor() { | |
local c | |
c=$(tput colors 2>/dev/null) || c=-1 | |
[[ -t 1 ]] && [[ $c -ge 8 ]] | |
} | |
terminalSupportsColor && doColor=1 || doColor=0 | |
color() { | |
local c | |
c=$1 | |
shift | |
[[ $doColor -eq 1 ]] && echo -e "\\e[0;${c}m${*}\\e[0m" || echo "$@" | |
} | |
red() { color 31 "$@"; } | |
green() { color 32 "$@"; } | |
yellow() { color 33 "$@"; } | |
fail() { | |
echo -e ' ' "$@" | |
exit 1 | |
} | |
run() { echo "$(green Running) $(yellow "$@")" && "$@"; } | |
updateMaven() { | |
local ver=$1 | |
local dir="apache-maven-$ver" | |
local file="$dir-bin.tar.gz" | |
local url="https://dlcdn.apache.org/maven/maven-3/$ver/binaries" | |
if [[ -z $ver ]]; then | |
fail "Version is $(red missing)" | |
elif ! [[ $ver =~ ^[34][.][1-9][0-9]*[.][1-9][0-9]*$ ]]; then | |
fail "Version $(red "$ver") is not recognized" | |
fi | |
run wget -c "$url/$file" -O "$file" | |
run wget "$url/$file.sha512" -O "$file.sha512" | |
run wget "$url/$file.asc" -O "$file.asc" | |
echo "$(green Adding) filename $(yellow "$file") to raw hash in $(red "$file.sha512")" | |
echo " $file" >>"$file.sha512" | |
run shasum -c "$file.sha512" | |
run gpg --verify "$file.asc" "$file" | |
run tar xf "$file" | |
run ln -sdfT "$dir" current | |
run ls --color=always --classify=always -ald current | |
} | |
updateMaven "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment