-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nickg
committed
May 17, 2017
1 parent
1b98b74
commit 4117267
Showing
1 changed file
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
#!/bin/sh | ||
set -e | ||
# Code generated by godownloader. DO NOT EDIT. | ||
# | ||
|
||
usage() { | ||
this=$1 | ||
cat <<EOF | ||
$this: download go binaries for client9/misspell | ||
Usage: $this [version] | ||
where [version] is 'latest' or a version number from | ||
https://github.com/client9/misspell/releases | ||
Generated by godownloader | ||
https://github.com/goreleaser/godownloader | ||
EOF | ||
} | ||
|
||
|
||
cat /dev/null << EOF | ||
------------------------------------------------------------------------ | ||
https://github.com/client9/posixshell - portable posix shell functions | ||
Public domain - http://unlicense.org | ||
https://github.com/client9/posixshell/blob/master/LICENSE.md | ||
but credits (and pull requests) appreciated. | ||
------------------------------------------------------------------------ | ||
EOF | ||
is_command() { | ||
type $1 > /dev/null 2> /dev/null | ||
} | ||
uname_arch() { | ||
arch=$(uname -m) | ||
case $arch in | ||
x86_64) arch="amd64" ;; | ||
x86) arch="386" ;; | ||
i686) arch="386" ;; | ||
i386) arch="386" ;; | ||
esac | ||
echo ${arch} | ||
} | ||
uname_os() { | ||
os=$(uname -s | tr '[:upper:]' '[:lower:]') | ||
echo ${os} | ||
} | ||
untar() { | ||
tarball=$1 | ||
case ${tarball} in | ||
*.tar.gz|*.tgz) tar -xzf ${tarball} ;; | ||
*.tar) tar -xf ${tarball} ;; | ||
*.zip) unzip ${tarball} ;; | ||
*) | ||
echo "Unknown archive format for ${tarball}" | ||
return 1 | ||
esac | ||
} | ||
mktmpdir() { | ||
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)" | ||
mkdir -p ${TMPDIR} | ||
echo ${TMPDIR} | ||
} | ||
http_download() { | ||
DEST=$1 | ||
SOURCE=$2 | ||
HEADER=$3 | ||
if is_command curl; then | ||
WGET="curl --fail -sSL" | ||
test -z "${HEADER}" || WGET="${WGET} -H \"${HEADER}\"" | ||
if [ "${DEST}" != "-" ]; then | ||
WGET="$WGET -o $DEST" | ||
fi | ||
elif is_command wget &> /dev/null; then | ||
WGET="wget -q -O $DEST" | ||
test -z "${HEADER}" || WGET="${WGET} --header \"${HEADER}\"" | ||
else | ||
echo "Unable to find wget or curl. Exit" | ||
exit 1 | ||
fi | ||
if [ "${DEST}" != "-" ]; then | ||
rm -f "${DEST}" | ||
fi | ||
${WGET} ${SOURCE} | ||
} | ||
github_api() { | ||
DEST=$1 | ||
SOURCE=$2 | ||
HEADER="" | ||
case $SOURCE in | ||
https://api.github.com*) | ||
test -z "$GITHUB_TOKEN" || HEADER="Authorization: token $GITHUB_TOKEN" | ||
;; | ||
esac | ||
http_download $DEST $SOURCE $HEADER | ||
} | ||
github_last_release() { | ||
OWNER_REPO=$1 | ||
VERSION=$(github_api - https://api.github.com/repos/${OWNER_REPO}/releases/latest | grep -m 1 "\"name\":" | cut -d ":" -f 2 | tr -d ' ",') | ||
if [ -z "${VERSION}" ]; then | ||
echo "Unable to determine latest release for ${OWNER_REPO}" | ||
return 1 | ||
fi | ||
echo ${VERSION} | ||
} | ||
hash_sha256() { | ||
TARGET=${1:-$(</dev/stdin)}; | ||
if is_command gsha256sum; then | ||
gsha256sum $TARGET | cut -d ' ' -f 1 | ||
elif is_command sha256sum; then | ||
sha256sum $TARGET | cut -d ' ' -f 1 | ||
elif is_command shasum; then | ||
shasum -a 256 $TARGET | cut -d ' ' -f 1 | ||
elif is_command openssl; then | ||
openssl -dst openssl dgst -sha256 $TARGET | cut -d ' ' -f a | ||
else | ||
echo "Unable to compute hash. exiting" | ||
exit 1 | ||
fi | ||
} | ||
hash_sha256_verify() { | ||
TARGET=$1 | ||
SUMS=$2 | ||
BASENAME=${TARGET##*/} | ||
WANT=$(grep ${BASENAME} ${SUMS} | tr '\t' ' ' | cut -d ' ' -f 1) | ||
GOT=$(hash_sha256 $TARGET) | ||
if [ "$GOT" != "$WANT" ]; then | ||
echo "Checksum for $TARGET did not verify" | ||
echo "WANT: ${WANT}" | ||
echo "GOT : ${GOT}" | ||
exit 1 | ||
fi | ||
} | ||
cat /dev/null << EOF | ||
------------------------------------------------------------------------ | ||
End of functions from https://github.com/client9/posixshell | ||
------------------------------------------------------------------------ | ||
EOF | ||
|
||
OWNER=client9 | ||
REPO=misspell | ||
BINARY=misspell | ||
FORMAT=tar.gz | ||
BINDIR=${BINDIR:-./bin} | ||
|
||
VERSION=$1 | ||
if [ -z "${VERSION}" ]; then | ||
usage $0 | ||
exit 1 | ||
fi | ||
|
||
if [ "${VERSION}" = "latest" ]; then | ||
echo "Checking GitHub for latest version of ${OWNER}/${REPO}" | ||
VERSION=$(github_last_release "$OWNER/$REPO") | ||
fi | ||
# if version starts with 'v', remove it | ||
VERSION=${VERSION#v} | ||
|
||
OS=$(uname_os) | ||
ARCH=$(uname_arch) | ||
|
||
# change format (tar.gz or zip) based on ARCH | ||
|
||
# adjust archive name based on OS | ||
case ${OS} in | ||
386) OS=32-bit ;; | ||
amd64) OS=64-bit ;; | ||
darwin) OS=macOS ;; | ||
esac | ||
|
||
# adjust archive name based on ARCH | ||
case ${ARCH} in | ||
386) ARCH=32-bit ;; | ||
amd64) ARCH=64-bit ;; | ||
darwin) ARCH=macOS ;; | ||
esac | ||
|
||
NAME=${BINARY}_${VERSION}_${OS}_${ARCH} | ||
TARBALL=${NAME}.${FORMAT} | ||
TARBALL_URL=https://github.com/${OWNER}/${REPO}/releases/download/v${VERSION}/${TARBALL} | ||
CHECKSUM=${REPO}_checksums.txt | ||
CHECKSUM_URL=https://github.com/${OWNER}/${REPO}/releases/download/v${VERSION}/${CHECKSUM} | ||
|
||
# Destructive operations start here | ||
# | ||
# | ||
TMPDIR=$(mktmpdir) | ||
http_download ${TMPDIR}/${TARBALL} ${TARBALL_URL} | ||
|
||
# checksum goes here | ||
if [ 1 -eq 1 ]; then | ||
http_download ${TMPDIR}/${CHECKSUM} ${CHECKSUM_URL} | ||
hash_sha256_verify ${TMPDIR}/${TARBALL} ${TMPDIR}/${CHECKSUM} | ||
fi | ||
|
||
(cd ${TMPDIR} && untar ${TARBALL}) | ||
install -d ${BINDIR} | ||
install ${TMPDIR}/${BINARY} ${BINDIR}/ | ||
|