diff --git a/README.md b/README.md index 1789d54..36f0bcb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/main.go b/main.go index 67469d9..aaeedb1 100644 --- a/main.go +++ b/main.go @@ -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 @@ -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} @@ -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 } diff --git a/samples/godownloader-goreleaser.sh b/samples/godownloader-goreleaser.sh index 1fba52e..48f8435 100644 --- a/samples/godownloader-goreleaser.sh +++ b/samples/godownloader-goreleaser.sh @@ -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 @@ -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} diff --git a/samples/godownloader-hugo.sh b/samples/godownloader-hugo.sh index 3b36fad..17a3175 100644 --- a/samples/godownloader-hugo.sh +++ b/samples/godownloader-hugo.sh @@ -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 @@ -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 ;; @@ -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 ;; @@ -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}