|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +VERSION=${1:?"Missing version number argument (arg 1)"} |
| 6 | +MAJOR=$(echo "$VERSION" | grep -oE '^[0-9]+') |
| 7 | +NEXUS_USER=${2:?"Missing Nexus username argument (arg 2)"} |
| 8 | + |
| 9 | +read -r -s -p "Nexus Password: " NEXUS_PASSWORD |
| 10 | +echo |
| 11 | + |
| 12 | +# https://stackoverflow.com/questions/4632028/how-to-create-a-temporary-directory |
| 13 | +# Find the directory name of the script |
| 14 | +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 15 | + |
| 16 | +# the temp directory used, within $DIR |
| 17 | +WORK_DIR=$(mktemp -d -p "$DIR") |
| 18 | + |
| 19 | +# check if tmp dir was created |
| 20 | +if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then |
| 21 | + echo "Could not create temp dir" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +# deletes the temp directory |
| 26 | +function cleanup { |
| 27 | + rm -rf "$WORK_DIR" |
| 28 | +} |
| 29 | + |
| 30 | +# register the cleanup function to be called on the EXIT signal |
| 31 | +trap cleanup EXIT |
| 32 | + |
| 33 | +cd "$WORK_DIR" || exit |
| 34 | + |
| 35 | +# Example download URLs found at https://maven.apache.org/download.cgi |
| 36 | +# https://dlcdn.apache.org/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gz |
| 37 | +# https://downloads.apache.org/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gz.sha512 |
| 38 | +# https://downloads.apache.org/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gz.asc |
| 39 | +# https://downloads.apache.org/maven/KEYS |
| 40 | +# Preferring downloads.apache.org over dlcdn.apache.org (for no real reason, but wanted consistency) |
| 41 | + |
| 42 | +BASE_URL="https://downloads.apache.org/maven/maven-$MAJOR/$VERSION/binaries" |
| 43 | +ARCHIVE_FILE="apache-maven-$VERSION-bin.tar.gz" |
| 44 | +SUM_FILE="$ARCHIVE_FILE.sha512" |
| 45 | +SIG_FILE="$ARCHIVE_FILE.asc" |
| 46 | + |
| 47 | +echo "Downloading Maven $VERSION" |
| 48 | +curl --fail -LO --progress-bar "$BASE_URL/$ARCHIVE_FILE" |
| 49 | +curl --fail -LO --progress-bar "$BASE_URL/$SUM_FILE" |
| 50 | +curl --fail -LO --progress-bar "$BASE_URL/$SIG_FILE" |
| 51 | + |
| 52 | +# Maven maintainers produce sum files that are incompatible with sha*sum, so we |
| 53 | +# need to append the archive name to the end to make it work. |
| 54 | +echo -n " $ARCHIVE_FILE" >> "$SUM_FILE" |
| 55 | + |
| 56 | +# Check that sha512 sum matches before uploading |
| 57 | +sha512sum --strict --check --status "$SUM_FILE" # do not put && here |
| 58 | +echo "SHA512 Sum matches" |
| 59 | + |
| 60 | +if ! gpg --verify "$SIG_FILE" "$ARCHIVE_FILE"; then |
| 61 | + echo "You might need to download the public keys and try again:" |
| 62 | + echo "curl https://downloads.apache.org/maven/KEYS | gpg --import" |
| 63 | + exit 1 |
| 64 | +fi |
| 65 | + |
| 66 | +echo "Uploading to Nexus" |
| 67 | + |
| 68 | +curl --fail -o /dev/null --progress-bar -u "$NEXUS_USER:$NEXUS_PASSWORD" --upload-file "$ARCHIVE_FILE" 'https://repo.stackable.tech/repository/packages/maven/' |
| 69 | +curl --fail -o /dev/null --progress-bar -u "$NEXUS_USER:$NEXUS_PASSWORD" --upload-file "$SUM_FILE" 'https://repo.stackable.tech/repository/packages/maven/' |
| 70 | +curl --fail -o /dev/null --progress-bar -u "$NEXUS_USER:$NEXUS_PASSWORD" --upload-file "$SIG_FILE" 'https://repo.stackable.tech/repository/packages/maven/' |
| 71 | + |
| 72 | +echo "Successfully uploaded Maven $VERSION to Nexus" |
| 73 | +echo "https://repo.stackable.tech/service/rest/repository/browse/packages/maven/" |
| 74 | +echo "https://github.com/prometheus/maven/releases/tag/$VERSION" |
0 commit comments