Skip to content

Commit

Permalink
Install script and build version fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Olenik committed Oct 27, 2017
1 parent eaac0d9 commit 5944dc0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 45 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LDFLAGS=$(shell echo -X main.version=$$(git describe --always --dirty))
LDFLAGS=$(shell echo -X main.version=$$(ver=$$(git tag -l --points-at HEAD) && [ -z $$ver ] && ver=$$(git describe --always --dirty); printf $$ver))
default: build

get:
Expand All @@ -10,9 +10,6 @@ build: get
GOOS=linux GOARCH=amd64 go build -i -ldflags="${LDFLAGS}" -o dist/hclq-linux-amd64
GOOS=windows GOARCH=amd64 go build -i -ldflags="${LDFLAGS}" -o dist/hclq-windows-amd64

brew: get
GOOS=darwin GOARCH=amd64 go build -i -ldflags="${LDFLAGS}" -o dist/hclq

install:
go install -ldflags="${LDFLAGS}"

Expand Down
64 changes: 23 additions & 41 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,48 +1,30 @@
#!/usr/bin/env dash
# Installs or upgrades to the latest version of hclq
#!/bin/sh
# Installs or upgrades hclq, by default installing into /usr/local/bin
# This can be overridden by passing a directory as the first parameter.
set -e

main() {
destination=${1:-"/usr/local/bin"}
destination=${1:-"/usr/local/bin"}
[ ! -d "$destination" ] && printf "Install directory '%s' does not exist\n", "$destination" && exit 1

if [ ! -d "$destination" ]; then
echo "Install directory '$destination' does not exist"
printUsage
exit 1
fi
if ! command -v jq > /dev/null 2>&1; then
printf "jq is required for this install script"
[ "$(uname)" = "Darwin" ] && printf ", it can be installed with 'brew install jq\n'"
exit 1
fi

if ! command -v jq > /dev/null 2>&1; then
printf "jq is required for this install script"
[ "$(uname)" = "Darwin" ] && printf ", it can be installed with 'brew install jq'"
echo
exit 1
fi
if command -v hclq > /dev/null 2>&1; then
msg="Upgrading hclq..."
ver="$(hclq --version)"
else
msg="Installing hclq..."
fi

if command -v hclq > /dev/null 2>&1; then
msg="Upgrading hclq..."
ver=$(hclq --version)
else
msg="Installing hclq..."
fi
latest="$(curl -s https://api.github.com/repos/mattolenik/hclq/releases/latest)"
tag="$(printf "$latest" | jq -r '.tag_name')"
[ "$tag" = "$ver" ] && printf "hclq is already at the latest version\n" && exit 0
printf "%s\n" "$msg"

latest=$(curl -s https://api.github.com/repos/mattolenik/hclq/releases/latest)
tag=$(echo $latest | jq -r '.tag_name')
if [ "$tag" = "$ver" ]; then
echo "hclq is already at the latest version"
exit 0
fi
hclq_url=$(curl -s https://api.github.com/repos/mattolenik/hclq/releases/latest | jq -r '.assets[] | .browser_download_url' | grep -i "$(uname)")
curl --progress-var -JLo "$destination/hclq" "$hclq_url" && chmod +x "$destination/hclq"

echo $msg
hclq_url=$(curl -s https://api.github.com/repos/mattolenik/hclq/releases/latest | jq -r '.assets[] | .browser_download_url' | grep -i "$(uname)")
curl -sSJLo "$destination/hclq" "$hclq_url" && chmod +x "$destination/hclq"

echo "hclq now at version $(hclq --version)"
}

printUsage() {
echo "Usage: install.sh [installDir]"
echo
echo "Default installDir is /usr/local/bin"
}

main "$@"
printf "hclq now at version %s\n" "$(hclq --version)"

0 comments on commit 5944dc0

Please sign in to comment.