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

Commit

Permalink
close #49 - update minify to use github releases
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Mar 9, 2018
1 parent 80fdc63 commit 1d8a0ba
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 35 deletions.
2 changes: 1 addition & 1 deletion samples/godownloader-event-gateway.sh
@@ -1,6 +1,6 @@
#!/bin/sh
set -e
# Code generated by godownloader on 2018-03-09T17:26:36Z. DO NOT EDIT.
# Code generated by godownloader on 2018-03-09T17:30:55Z. DO NOT EDIT.
#

usage() {
Expand Down
2 changes: 1 addition & 1 deletion samples/godownloader-goreleaser.sh
@@ -1,6 +1,6 @@
#!/bin/sh
set -e
# Code generated by godownloader on 2018-03-09T17:26:35Z. DO NOT EDIT.
# Code generated by godownloader on 2018-03-09T17:30:53Z. DO NOT EDIT.
#

usage() {
Expand Down
2 changes: 1 addition & 1 deletion samples/godownloader-hugo.sh
@@ -1,6 +1,6 @@
#!/bin/sh
set -e
# Code generated by godownloader on 2018-03-09T17:26:34Z. DO NOT EDIT.
# Code generated by godownloader on 2018-03-09T17:30:53Z. DO NOT EDIT.
#

usage() {
Expand Down
135 changes: 106 additions & 29 deletions samples/godownloader-minify.sh
@@ -1,23 +1,22 @@
#!/bin/sh
set -e
# Code generated by godownloader on 2018-03-09T17:26:35Z. DO NOT EDIT.
# Code generated by godownloader on 2018-03-09T17:30:54Z. DO NOT EDIT.
#

usage() {
this=$1
cat <<EOF
$this: download go binaries for tdewolff/minify
Usage: $this [-b bindir]
-b set the installation or BINDIR, defaults to ./bin
Usage: $this [-b] bindir [-d] [tag]
-b sets bindir or installation directory, Defaults to ./bin
-d turns on debug logging
[tag] is a tag from
https://github.com/tdewolff/minify/releases
If tag is missing, then the latest will be used.
Version is automatically selected from
https://dl.equinox.io/tdewolff/minify/stable
Generated by godownloader
https://github.com/goreleaser/godownloader
Generated by godownloader
https://github.com/goreleaser/godownloader
EOF
exit 2
Expand All @@ -36,25 +35,85 @@ parse_args() {
esac
done
shift $((OPTIND - 1))
# VERSION currently unused
#VERSION=$1
TAG=$1
}
# wrap all destructive operations into a function
# to prevent curl|bash network truncation and disaster
# this function wraps all the destructive operations
# if a curl|bash cuts off the end of the script due to
# network, either nothing will happen or will syntax error
# out preventing half-done work
execute() {
TMPDIR=$(mktmpdir)
http_download "${TMPDIR}/${TARBALL}" "${TARBALL_URL}"
http_download "${TMPDIR}/${CHECKSUM}" "${CHECKSUM_URL}"
hash_sha256_verify "${TMPDIR}/${TARBALL}" "${TMPDIR}/${CHECKSUM}"

log_info "seeking '${CHANNEL}' latest from $TARGET"
TARBALL_URL=$(http_copy "$TARGET" | grep "$TARBALL" | cut -d '"' -f 2)

log_info "downloading from ${TARBALL_URL}"
http_download "${TMPDIR}/${TARBALL}" "$TARBALL_URL"

(cd "$TMPDIR" && untar "$TARBALL")
(cd "${TMPDIR}" && untar "${TARBALL}")
install -d "${BINDIR}"
install "${TMPDIR}/${BINARY}" "${BINDIR}/"
log_info "installed ${BINDIR}/${BINARY}"
log_info "installed as ${BINDIR}/${BINARY}"
}
is_supported_platform() {
platform=$1
found=1
case "$platform" in
windows/amd64) found=0 ;;
windows/386) found=0 ;;

windows/arm64) found=0 ;;
linux/amd64) found=0 ;;
linux/386) found=0 ;;

linux/arm64) found=0 ;;
darwin/amd64) found=0 ;;
darwin/386) found=0 ;;

darwin/arm64) found=0 ;;
windows/armv6) found=0 ;;
linux/armv6) found=0 ;;
darwin/armv6) found=0 ;;
esac
return $found
}
check_platform() {
if is_supported_platform "$PLATFORM"; then
# optional logging goes here
true
else
log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new"
exit 1
fi
}
tag_to_version() {
if [ -z "${TAG}" ]; then
log_info "checking GitHub for latest tag"
else
log_info "checking GitHub for tag '${TAG}'"
fi
REALTAG=$(github_release "$OWNER/$REPO" "${TAG}") && true
if test -z "$REALTAG"; then
log_crit "unable to find '${TAG}' - use 'latest' or see https://github.com/${PREFIX}/releases for details"
exit 1
fi
# if version starts with 'v', remove it
TAG="$REALTAG"
VERSION=${TAG#v}
}
adjust_format() {
# change format (tar.gz or zip) based on ARCH
case ${ARCH} in
windows) FORMAT=zip ;;
esac
true
}
adjust_os() {
# adjust archive name based on OS
true
}
adjust_arch() {
# adjust archive name based on ARCH
true
}

cat /dev/null <<EOF
------------------------------------------------------------------------
https://github.com/client9/shlib - portable posix shell functions
Expand Down Expand Up @@ -287,28 +346,46 @@ cat /dev/null <<EOF
End of functions from https://github.com/client9/shlib
------------------------------------------------------------------------
EOF

OWNER=tdewolff
REPO="minify"
BINARY=minify
FORMAT=tgz
BINDIR=${BINDIR:-./bin}
CHANNEL=stable
FORMAT=tar.gz
OS=$(uname_os)
ARCH=$(uname_arch)
PREFIX="$OWNER/$REPO"

# use in logging routines
log_prefix() {
echo "$PREFIX"
echo "$PREFIX"
}
OS=$(uname_os)
ARCH=$(uname_arch)
PLATFORM="${OS}/${ARCH}"
GITHUB_DOWNLOAD=https://github.com/${OWNER}/${REPO}/releases/download

uname_os_check "$OS"
uname_arch_check "$ARCH"

parse_args "$@"

TARGET=https://dl.equinox.io/${OWNER}/${REPO}/${CHANNEL}
TARBALL="${BINARY}-${CHANNEL}-${OS}-${ARCH}.${FORMAT}"
check_platform

tag_to_version

adjust_format

adjust_os

adjust_arch

log_info "found version: ${VERSION} for ${TAG}/${OS}/${ARCH}"

NAME=${BINARY}_${VERSION}_${OS}_${ARCH}
TARBALL=${NAME}.${FORMAT}
TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL}
CHECKSUM=${BINARY}_${VERSION}_checksums.txt
CHECKSUM_URL=${GITHUB_DOWNLOAD}/${TAG}/${CHECKSUM}

# Adjust binary name if windows
if [ "$OS" = "windows" ]; then
BINARY="${BINARY}.exe"
fi
Expand Down
2 changes: 1 addition & 1 deletion samples/godownloader-misspell.sh
@@ -1,6 +1,6 @@
#!/bin/sh
set -e
# Code generated by godownloader on 2018-03-09T17:26:35Z. DO NOT EDIT.
# Code generated by godownloader on 2018-03-09T17:30:54Z. DO NOT EDIT.
#

usage() {
Expand Down
2 changes: 1 addition & 1 deletion samples/godownloader-shfmt.sh
@@ -1,6 +1,6 @@
#!/bin/sh
set -e
# Code generated by godownloader on 2018-03-09T17:26:35Z. DO NOT EDIT.
# Code generated by godownloader on 2018-03-09T17:30:54Z. DO NOT EDIT.
#

usage() {
Expand Down
6 changes: 5 additions & 1 deletion scripts/build_samples.sh
Expand Up @@ -2,7 +2,11 @@
./godownloader -repo gohugoio/hugo >samples/godownloader-hugo.sh
./godownloader -repo goreleaser/goreleaser >samples/godownloader-goreleaser.sh
./godownloader -repo client9/misspell >samples/godownloader-misspell.sh
./godownloader -source equinoxio -repo tdewolff/minify >samples/godownloader-minify.sh
./godownloader -repo tdewolff/minify >samples/godownloader-minify.sh
./godownloader -source raw -repo mvdan/sh -exe shfmt >samples/godownloader-shfmt.sh
./godownloader -repo serverless/event-gateway >samples/godownloader-event-gateway.sh
chmod a+x samples/*.sh

# https://github.com/goreleaser/godownloader/issues/49
# still available and good to test equinoxio but no longer current
#./godownloader -source equinoxio -repo tdewolff/minify >samples/godownloader-minify.sh

0 comments on commit 1d8a0ba

Please sign in to comment.