From ee515b5f75cdb96f6835bfe50d4283b243efe0ee Mon Sep 17 00:00:00 2001 From: Nedyalko Andreev Date: Tue, 9 Dec 2014 15:59:45 +0200 Subject: [PATCH 1/3] Implemented some bash good practices for failing early when there is an error ( http://kvz.io/blog/2013/11/21/bash-best-practices/ ) --- files/download-artifact-from-nexus.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/download-artifact-from-nexus.sh b/files/download-artifact-from-nexus.sh index 8e30a57..7d81616 100755 --- a/files/download-artifact-from-nexus.sh +++ b/files/download-artifact-from-nexus.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash +set -o errexit -o nounset -o pipefail # Define Nexus Configuration NEXUS_BASE= From b0284ab0d86fccbcd77f8d3d6b3e9b22531e5767 Mon Sep 17 00:00:00 2001 From: Nedyalko Andreev Date: Tue, 9 Dec 2014 16:24:09 +0200 Subject: [PATCH 2/3] Fixed a few unbound variables --- files/download-artifact-from-nexus.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/files/download-artifact-from-nexus.sh b/files/download-artifact-from-nexus.sh index 7d81616..6b39a4d 100755 --- a/files/download-artifact-from-nexus.sh +++ b/files/download-artifact-from-nexus.sh @@ -40,6 +40,7 @@ REPO= USERNAME= PASSWORD= VERBOSE=0 +SNAPSHOT_CHECK= OUTPUT= @@ -104,7 +105,7 @@ fi # Define default values for optional components # If we don't have set a repository and the version requested is a SNAPSHOT use snapshots, otherwise use releases -if [[ "$REPOSITORY" == "" ]] +if [[ "$REPO" == "" ]] then if [[ "$VERSION" =~ ".*SNAPSHOT" ]] then @@ -122,7 +123,7 @@ PARAM_VALUES=( $GROUP_ID $ARTIFACT_ID $VERSION $REPO $PACKAGING $CLASSIFIER ) PARAMS="" for index in ${!PARAM_KEYS[*]} do - if [[ ${PARAM_VALUES[$index]} != "" ]] + if [[ ${PARAM_VALUES[$index]:-} != "" ]] then PARAMS="${PARAMS}${PARAM_KEYS[$index]}=${PARAM_VALUES[$index]}&" fi From 723328c5aabd41cce1e2cdae2e36881befcbe728 Mon Sep 17 00:00:00 2001 From: Nedyalko Andreev Date: Tue, 9 Dec 2014 17:01:26 +0200 Subject: [PATCH 3/3] Fixed error reporting for invalid options --- files/download-artifact-from-nexus.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/download-artifact-from-nexus.sh b/files/download-artifact-from-nexus.sh index 6b39a4d..4a965f7 100755 --- a/files/download-artifact-from-nexus.sh +++ b/files/download-artifact-from-nexus.sh @@ -44,7 +44,7 @@ SNAPSHOT_CHECK= OUTPUT= -while getopts "hvza:c:e:o:r:u:p:n:" OPTION +while getopts ":hvza:c:e:o:r:u:p:n:" OPTION do case $OPTION in h) @@ -88,7 +88,7 @@ do NEXUS_BASE=$OPTARG ;; ?) - echo "Illegal argument $OPTION=$OPTARG" >&2 + echo "Illegal argument: -${OPTARG:-}" >&2 usage exit ;;