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

Commit

Permalink
CLose #4 format overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed May 11, 2017
1 parent 4ee7298 commit 2fbb1f7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
7 changes: 3 additions & 4 deletions README.md
Expand Up @@ -55,18 +55,17 @@ Your new `hugo` binary is in `./bin`, so change your Makefie or scripts to use `

## Status

* Only GitHub Releases are supported right now
* Binares are installed using `tar.gz` (`zip` support is coming)
* Only GitHub Releases are supported right now.
* Binares are installed using `tar.gz` or `zip`.
* No support for Windows anything. I just don't know enough about it.
* No OS-specific installs such as homebrew, deb, rpm. Everything is installed locally via .tar.gz. Typically OS installs are done differently anyways.

## TODO

* #3 Zip support
* #4 and format over-rides.
* #5 Checksum support
* #8 Setup travis.ci
* #10 Adjustment of default `TMPDIR` and `BINDIR` (install directory)
* #10 Adjustment of default `BINDIR` (install directory)
* #11 Use goreleaser to release godownloader
* #12 Use godownloader to download godownloader
* Vendor dependencies
Expand Down
29 changes: 26 additions & 3 deletions main.go
Expand Up @@ -24,7 +24,6 @@ FORMAT={{ .Archive.Format }}
OWNER={{ $.Release.GitHub.Owner }}
REPO={{ $.Release.GitHub.Name }}
BINDIR=${BINDIR:-./bin}
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
VERSION=$1
if [ -z "${VERSION}" ]; then
Expand Down Expand Up @@ -81,29 +80,45 @@ if [ "${VERSION}" = "latest" ]; then
fi
fi
# if version starts with 'v', remove it
VERSION=${VERSION#v}
OS=$(uname -s)
ARCH=$(uname -m)
{{ with .Archive.Replacements }}
# change format (tar.gz or zip) based on ARCH
{{- with .Archive.FormatOverrides }}
case ${ARCH} in
{{- range . }}
{{ .Goos }}) FORMAT={{ .Format }} ;;
esac
{{- end }}
{{- end }}
# adjust archive name based on OS
{{- with .Archive.Replacements }}
case ${OS} in
{{- range $k, $v := . }}
{{ $k }}) OS={{ $v }} ;;
{{- end }}
esac
# adjust archive name based on ARCH
case ${ARCH} in
{{- range $k, $v := . }}
{{ $k }}) ARCH={{ $v }} ;;
{{- end }}
esac
{{ end }}
{{- end }}
{{ .Archive.NameTemplate }}
TARBALL=${NAME}.${FORMAT}
URL=https://github.com/${OWNER}/${REPO}/releases/download/v${VERSION}/${TARBALL}
# Destructive operations start here
#
#
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
mkdir -p ${TMPDIR}
rm -f ${TMPDIR}/${TARBALL}
download ${TMPDIR}/${TARBALL} ${URL}
Expand Down Expand Up @@ -250,6 +265,14 @@ func Load(repo string, file string) (*config.Project, error) {
}
project.Archive.Replacements = rmap

// do something similar for format over-rides
for i := 0; i < len(project.Archive.FormatOverrides); i++ {
goos := project.Archive.FormatOverrides[i].Goos
newos := uname[goos]
if newos != "" {
project.Archive.FormatOverrides[i].Goos = newos
}
}
return project, nil
}

Expand Down
11 changes: 10 additions & 1 deletion samples/godownloader-goreleaser.sh
Expand Up @@ -7,7 +7,6 @@ FORMAT=tar.gz
OWNER=goreleaser
REPO=goreleaser
BINDIR=${BINDIR:-./bin}
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"

VERSION=$1
if [ -z "${VERSION}" ]; then
Expand Down Expand Up @@ -64,18 +63,28 @@ if [ "${VERSION}" = "latest" ]; then
fi
fi

# if version starts with 'v', remove it
VERSION=${VERSION#v}

OS=$(uname -s)
ARCH=$(uname -m)

# change format (tar.gz or zip) based on arch
case ${ARCH} in
Windows) FORMAT=zip ;;
esac

# adjust archive name based on OS

if [ ! -z "${ARM}" ]; then ARM="v$ARM"; fi
NAME=${BINARY}_${OS}_${ARCH}${ARM}
TARBALL=${NAME}.${FORMAT}
URL=https://github.com/${OWNER}/${REPO}/releases/download/v${VERSION}/${TARBALL}

# Destructive operations start here
#
#
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
mkdir -p ${TMPDIR}
rm -f ${TMPDIR}/${TARBALL}
download ${TMPDIR}/${TARBALL} ${URL}
Expand Down
13 changes: 11 additions & 2 deletions samples/godownloader-hugo.sh
Expand Up @@ -7,7 +7,6 @@ FORMAT=tar.gz
OWNER=spf13
REPO=hugo
BINDIR=${BINDIR:-./bin}
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"

VERSION=$1
if [ -z "${VERSION}" ]; then
Expand Down Expand Up @@ -64,12 +63,18 @@ if [ "${VERSION}" = "latest" ]; then
fi
fi

# if version starts with 'v', remove it
VERSION=${VERSION#v}

OS=$(uname -s)
ARCH=$(uname -m)

# change format (tar.gz or zip) based on arch
case ${ARCH} in
Windows) FORMAT=zip ;;
esac

# adjust archive name based on OS
case ${OS} in
Darwin) OS=macOS ;;
arm) OS=ARM ;;
Expand All @@ -79,6 +84,7 @@ i386) OS=32bit ;;
x86_64) OS=64bit ;;
esac

# adjust archive name based on ARCH
case ${ARCH} in
Darwin) ARCH=macOS ;;
arm) ARCH=ARM ;;
Expand All @@ -88,11 +94,14 @@ i386) ARCH=32bit ;;
x86_64) ARCH=64bit ;;
esac


NAME=${BINARY}_${VERSION}_${OS}-${ARCH}
TARBALL=${NAME}.${FORMAT}
URL=https://github.com/${OWNER}/${REPO}/releases/download/v${VERSION}/${TARBALL}

# Destructive operations start here
#
#
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
mkdir -p ${TMPDIR}
rm -f ${TMPDIR}/${TARBALL}
download ${TMPDIR}/${TARBALL} ${URL}
Expand Down

0 comments on commit 2fbb1f7

Please sign in to comment.