Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed unbound vars and implemented some bash good practices #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions files/download-artifact-from-nexus.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail

# Define Nexus Configuration
NEXUS_BASE=
Expand Down Expand Up @@ -39,10 +40,11 @@ REPO=
USERNAME=
PASSWORD=
VERBOSE=0
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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this change and the one on line 99 is this (from the getopts manpage): If an option character not contained in the optstring operand is found where an option character is expected, the shell variable specified by name shall be set to the ('?') character. In this case, if the first character in optstring is a (':'), the shell variable OPTARG shall be set to the option character found, but no output shall be written to standard error; otherwise, the shell variable OPTARG shall be unset and a diagnostic message shall be written to standard error.

do
case $OPTION in
h)
Expand Down Expand Up @@ -86,7 +88,7 @@ do
NEXUS_BASE=$OPTARG
;;
?)
echo "Illegal argument $OPTION=$OPTARG" >&2
echo "Illegal argument: -${OPTARG:-}" >&2
usage
exit
;;
Expand All @@ -103,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
Expand All @@ -121,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
Expand Down