Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
resync shell, add shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed May 19, 2017
1 parent 13c8beb commit 96d9438
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 83 deletions.
9 changes: 8 additions & 1 deletion Makefile
Expand Up @@ -12,6 +12,7 @@ setup: ## Install all the build and lint dependencies

test: ## Run all the tests
gotestcover $(TEST_OPTIONS) -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=30s
shellcheck samples/godownloader-goreleaser.sh

cover: test ## Run all the tests and opens the coverage report
go tool cover -html=coverage.txt
Expand All @@ -35,7 +36,13 @@ lint: ## Run all the linters
--deadline=10m \
./...

ci: build lint test samples ## Run all the tests and code checks as travis-ci does
lint_shell: ## shellcheck the shell scripts
shellcheck -s sh samples/godownloader-goreleaser.sh
shellcheck -s bash samples/godownloader-goreleaser.sh
shellcheck -s dash samples/godownloader-goreleaser.sh
shellcheck -s ksh samples/godownloader-goreleaser.sh

ci: build samples lint test lint_shell ## Run all the tests and code checks as travis-ci does

build: ## Build a beta version of goreleaser
go build
Expand Down
12 changes: 6 additions & 6 deletions makeshellfn.sh
Expand Up @@ -2,13 +2,13 @@
set -e

git_clone_or_update() {
URL=$1
REPO=${URL##*/} # foo.git
REPO=${REPO%.git} # foo
if [ ! -d "$REPO" ]; then
git clone ${URL}
giturl=$1
gitrepo=${giturl##*/} # foo.git
gitrepo=${gitrepo%.git} # foo
if [ ! -d "$gitrepo" ]; then
git clone "$giturl"
else
(cd ${REPO} && git pull > /dev/null)
(cd "$gitrepo" && git pull > /dev/null)
fi
}

Expand Down
39 changes: 20 additions & 19 deletions samples/godownloader-goreleaser.sh
Expand Up @@ -28,11 +28,11 @@ but credits (and pull requests) appreciated.
------------------------------------------------------------------------
EOF
is_command() {
type $1 > /dev/null 2> /dev/null
command -v "$1" > /dev/null
}
uname_os() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
echo ${os}
echo "$os"
}
uname_arch() {
arch=$(uname -m)
Expand Down Expand Up @@ -83,19 +83,19 @@ uname_arch_check() {
}
untar() {
tarball=$1
case ${tarball} in
*.tar.gz|*.tgz) tar -xzf ${tarball} ;;
*.tar) tar -xf ${tarball} ;;
*.zip) unzip ${tarball} ;;
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}
mkdir -p "${TMPDIR}"
echo "${TMPDIR}"
}
http_download() {
local_file=$1
Expand Down Expand Up @@ -134,25 +134,26 @@ github_api() {
}
github_last_release() {
owner_repo=$1
html=$(github_api - https://api.github.com/repos/${owner_repo}/releases/latest)
giturl="https://api.github.com/repos/${owner_repo}/releases/latest"
html=$(github_api - "$giturl")
version=$(echo "$html" | grep -m 1 "\"name\":" | cut -d ":" -f 2 | tr -d ' ",')
test -z "$version" && return 1
echo "$version"
}
hash_sha256() {
TARGET=${1:-/dev/stdin};
if is_command gsha256sum; then
hash=$(gsha256sum $TARGET) || return 1
echo $hash | cut -d ' ' -f 1
hash=$(gsha256sum "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command sha256sum; then
hash=$(sha256sum $TARGET) || return 1
echo $hash | cut -d ' ' -f 1
hash=$(sha256sum "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command shasum; then
hash=$(shasum -a 256 $TARGET 2>/dev/null) || return 1
echo $hash | cut -d ' ' -f 1
hash=$(shasum -a 256 "$TARGET" 2>/dev/null) || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command openssl; then
hash=$(openssl -dst openssl dgst -sha256 $TARGET) || return 1
echo $hash | cut -d ' ' -f a
hash=$(openssl -dst openssl dgst -sha256 "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f a
else
echo "hash_sha256: unable to find command to compute sha-256 hash"
return 1
Expand All @@ -166,12 +167,12 @@ 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 | tr '\t' ' ' | cut -d ' ' -f 1)
if [ -z "$want" ]; then
echo "hash_sha256_verify: unable to find checksum for '${TARGET}' in '${checksums}'"
return 1
fi
got=$(hash_sha256 $TARGET)
got=$(hash_sha256 "$TARGET")
if [ "$want" != "$got" ]; then
echo "hash_sha256_verify: checksum for '$TARGET' did not verify ${want} vs $got"
return 1
Expand Down
39 changes: 20 additions & 19 deletions samples/godownloader-hugo.sh
Expand Up @@ -28,11 +28,11 @@ but credits (and pull requests) appreciated.
------------------------------------------------------------------------
EOF
is_command() {
type $1 > /dev/null 2> /dev/null
command -v "$1" > /dev/null
}
uname_os() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
echo ${os}
echo "$os"
}
uname_arch() {
arch=$(uname -m)
Expand Down Expand Up @@ -83,19 +83,19 @@ uname_arch_check() {
}
untar() {
tarball=$1
case ${tarball} in
*.tar.gz|*.tgz) tar -xzf ${tarball} ;;
*.tar) tar -xf ${tarball} ;;
*.zip) unzip ${tarball} ;;
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}
mkdir -p "${TMPDIR}"
echo "${TMPDIR}"
}
http_download() {
local_file=$1
Expand Down Expand Up @@ -134,25 +134,26 @@ github_api() {
}
github_last_release() {
owner_repo=$1
html=$(github_api - https://api.github.com/repos/${owner_repo}/releases/latest)
giturl="https://api.github.com/repos/${owner_repo}/releases/latest"
html=$(github_api - "$giturl")
version=$(echo "$html" | grep -m 1 "\"name\":" | cut -d ":" -f 2 | tr -d ' ",')
test -z "$version" && return 1
echo "$version"
}
hash_sha256() {
TARGET=${1:-/dev/stdin};
if is_command gsha256sum; then
hash=$(gsha256sum $TARGET) || return 1
echo $hash | cut -d ' ' -f 1
hash=$(gsha256sum "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command sha256sum; then
hash=$(sha256sum $TARGET) || return 1
echo $hash | cut -d ' ' -f 1
hash=$(sha256sum "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command shasum; then
hash=$(shasum -a 256 $TARGET 2>/dev/null) || return 1
echo $hash | cut -d ' ' -f 1
hash=$(shasum -a 256 "$TARGET" 2>/dev/null) || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command openssl; then
hash=$(openssl -dst openssl dgst -sha256 $TARGET) || return 1
echo $hash | cut -d ' ' -f a
hash=$(openssl -dst openssl dgst -sha256 "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f a
else
echo "hash_sha256: unable to find command to compute sha-256 hash"
return 1
Expand All @@ -166,12 +167,12 @@ 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 | tr '\t' ' ' | cut -d ' ' -f 1)
if [ -z "$want" ]; then
echo "hash_sha256_verify: unable to find checksum for '${TARGET}' in '${checksums}'"
return 1
fi
got=$(hash_sha256 $TARGET)
got=$(hash_sha256 "$TARGET")
if [ "$want" != "$got" ]; then
echo "hash_sha256_verify: checksum for '$TARGET' did not verify ${want} vs $got"
return 1
Expand Down
39 changes: 20 additions & 19 deletions samples/godownloader-misspell.sh
Expand Up @@ -28,11 +28,11 @@ but credits (and pull requests) appreciated.
------------------------------------------------------------------------
EOF
is_command() {
type $1 > /dev/null 2> /dev/null
command -v "$1" > /dev/null
}
uname_os() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
echo ${os}
echo "$os"
}
uname_arch() {
arch=$(uname -m)
Expand Down Expand Up @@ -83,19 +83,19 @@ uname_arch_check() {
}
untar() {
tarball=$1
case ${tarball} in
*.tar.gz|*.tgz) tar -xzf ${tarball} ;;
*.tar) tar -xf ${tarball} ;;
*.zip) unzip ${tarball} ;;
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}
mkdir -p "${TMPDIR}"
echo "${TMPDIR}"
}
http_download() {
local_file=$1
Expand Down Expand Up @@ -134,25 +134,26 @@ github_api() {
}
github_last_release() {
owner_repo=$1
html=$(github_api - https://api.github.com/repos/${owner_repo}/releases/latest)
giturl="https://api.github.com/repos/${owner_repo}/releases/latest"
html=$(github_api - "$giturl")
version=$(echo "$html" | grep -m 1 "\"name\":" | cut -d ":" -f 2 | tr -d ' ",')
test -z "$version" && return 1
echo "$version"
}
hash_sha256() {
TARGET=${1:-/dev/stdin};
if is_command gsha256sum; then
hash=$(gsha256sum $TARGET) || return 1
echo $hash | cut -d ' ' -f 1
hash=$(gsha256sum "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command sha256sum; then
hash=$(sha256sum $TARGET) || return 1
echo $hash | cut -d ' ' -f 1
hash=$(sha256sum "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command shasum; then
hash=$(shasum -a 256 $TARGET 2>/dev/null) || return 1
echo $hash | cut -d ' ' -f 1
hash=$(shasum -a 256 "$TARGET" 2>/dev/null) || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command openssl; then
hash=$(openssl -dst openssl dgst -sha256 $TARGET) || return 1
echo $hash | cut -d ' ' -f a
hash=$(openssl -dst openssl dgst -sha256 "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f a
else
echo "hash_sha256: unable to find command to compute sha-256 hash"
return 1
Expand All @@ -166,12 +167,12 @@ 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 | tr '\t' ' ' | cut -d ' ' -f 1)
if [ -z "$want" ]; then
echo "hash_sha256_verify: unable to find checksum for '${TARGET}' in '${checksums}'"
return 1
fi
got=$(hash_sha256 $TARGET)
got=$(hash_sha256 "$TARGET")
if [ "$want" != "$got" ]; then
echo "hash_sha256_verify: checksum for '$TARGET' did not verify ${want} vs $got"
return 1
Expand Down

0 comments on commit 96d9438

Please sign in to comment.