From 0685c708f0325692ee46608d5f405e168fe19e65 Mon Sep 17 00:00:00 2001 From: nickg Date: Tue, 23 May 2017 21:46:45 -0700 Subject: [PATCH] close #10 - allow flag to set installation directory --- samples/godownloader-goreleaser.sh | 38 ++++++++++++++++++------------ samples/godownloader-hugo.sh | 38 ++++++++++++++++++------------ samples/godownloader-minify.sh | 2 +- samples/godownloader-misspell.sh | 38 ++++++++++++++++++------------ shell_godownloader.go | 38 ++++++++++++++++++------------ shellfn.go | 2 +- 6 files changed, 94 insertions(+), 62 deletions(-) diff --git a/samples/godownloader-goreleaser.sh b/samples/godownloader-goreleaser.sh index 17e4901..6af78ca 100644 --- a/samples/godownloader-goreleaser.sh +++ b/samples/godownloader-goreleaser.sh @@ -8,14 +8,17 @@ usage() { cat < /dev/null | tr '\t' ' ' | cut -d ' ' -f 1) + want=$(grep "${BASENAME}" "${checksums}" 2> /dev/null | cut -d ' ' -f 1) if [ -z "$want" ]; then echo "hash_sha256_verify: unable to find checksum for '${TARGET}' in '${checksums}'" return 1 @@ -210,22 +213,27 @@ is_supported_platform() { return $found } +parse_args() { + #BINDIR is ./bin unless set be ENV + # over-ridden by flag below + + BINDIR=${BINDIR:-./bin} + while getopts "b:" arg; do + case "$arg" in + b) BINDIR="$OPTARG";; + \?) usage "$0" ;; + esac + done + shift $((OPTIND - 1)) + VERSION=$1 +} + OWNER=goreleaser REPO=goreleaser BINARY=goreleaser FORMAT=tar.gz -BINDIR=${BINDIR:-./bin} -VERSION=$1 -case "${VERSION}" in - latest) - VERSION="" - ;; - -h|-?|*help*) - usage "$0" - exit 1 - ;; -esac +parse_args "$@" uname_os_check uname_arch_check diff --git a/samples/godownloader-hugo.sh b/samples/godownloader-hugo.sh index 697e184..827f257 100644 --- a/samples/godownloader-hugo.sh +++ b/samples/godownloader-hugo.sh @@ -8,14 +8,17 @@ usage() { cat < /dev/null | tr '\t' ' ' | cut -d ' ' -f 1) + want=$(grep "${BASENAME}" "${checksums}" 2> /dev/null | cut -d ' ' -f 1) if [ -z "$want" ]; then echo "hash_sha256_verify: unable to find checksum for '${TARGET}' in '${checksums}'" return 1 @@ -226,22 +229,27 @@ is_supported_platform() { return $found } +parse_args() { + #BINDIR is ./bin unless set be ENV + # over-ridden by flag below + + BINDIR=${BINDIR:-./bin} + while getopts "b:" arg; do + case "$arg" in + b) BINDIR="$OPTARG";; + \?) usage "$0" ;; + esac + done + shift $((OPTIND - 1)) + VERSION=$1 +} + OWNER=spf13 REPO=hugo BINARY=hugo FORMAT=tar.gz -BINDIR=${BINDIR:-./bin} -VERSION=$1 -case "${VERSION}" in - latest) - VERSION="" - ;; - -h|-?|*help*) - usage "$0" - exit 1 - ;; -esac +parse_args "$@" uname_os_check uname_arch_check diff --git a/samples/godownloader-minify.sh b/samples/godownloader-minify.sh index 531a959..5ec219a 100644 --- a/samples/godownloader-minify.sh +++ b/samples/godownloader-minify.sh @@ -172,7 +172,7 @@ hash_sha256_verify() { return 1 fi BASENAME=${TARGET##*/} - want=$(grep "${BASENAME}" "${checksums}" 2> /dev/null | tr '\t' ' ' | cut -d ' ' -f 1) + want=$(grep "${BASENAME}" "${checksums}" 2> /dev/null | cut -d ' ' -f 1) if [ -z "$want" ]; then echo "hash_sha256_verify: unable to find checksum for '${TARGET}' in '${checksums}'" return 1 diff --git a/samples/godownloader-misspell.sh b/samples/godownloader-misspell.sh index 855cb54..0b5c883 100644 --- a/samples/godownloader-misspell.sh +++ b/samples/godownloader-misspell.sh @@ -8,14 +8,17 @@ usage() { cat < /dev/null | tr '\t' ' ' | cut -d ' ' -f 1) + want=$(grep "${BASENAME}" "${checksums}" 2> /dev/null | cut -d ' ' -f 1) if [ -z "$want" ]; then echo "hash_sha256_verify: unable to find checksum for '${TARGET}' in '${checksums}'" return 1 @@ -202,22 +205,27 @@ is_supported_platform() { return $found } +parse_args() { + #BINDIR is ./bin unless set be ENV + # over-ridden by flag below + + BINDIR=${BINDIR:-./bin} + while getopts "b:" arg; do + case "$arg" in + b) BINDIR="$OPTARG";; + \?) usage "$0" ;; + esac + done + shift $((OPTIND - 1)) + VERSION=$1 +} + OWNER=client9 REPO=misspell BINARY=misspell FORMAT=tar.gz -BINDIR=${BINDIR:-./bin} -VERSION=$1 -case "${VERSION}" in - latest) - VERSION="" - ;; - -h|-?|*help*) - usage "$0" - exit 1 - ;; -esac +parse_args "$@" uname_os_check uname_arch_check diff --git a/shell_godownloader.go b/shell_godownloader.go index b23928e..56d84c2 100644 --- a/shell_godownloader.go +++ b/shell_godownloader.go @@ -10,14 +10,17 @@ usage() { cat < /dev/null | tr '\t' ' ' | cut -d ' ' -f 1) + want=$(grep "${BASENAME}" "${checksums}" 2> /dev/null | cut -d ' ' -f 1) if [ -z "$want" ]; then echo "hash_sha256_verify: unable to find checksum for '${TARGET}' in '${checksums}'" return 1