bindown

package module
v2.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2020 License: MIT Imports: 17 Imported by: 0

README

bindown

godoc Go Report Card ci

bindown is a command-line utility to download, verify and install binary files. It is intended to be used in development and ci environments where it is important to guarantee the same version of the same binary is downloaded every time.

Installation

Using bootstrap-bindown.sh

This is the preferred method for ci or development environments. Each release contains a shell script bootstrap-bindown.sh that will download bindown for the current os. Place bootstrap-bindown.sh from the latest release in your project's repository. Don't forget to make it executable first (chmod +x bootstrap-bindown.sh on most systems). Then you can call bootstrap-bindown.sh before bindown in the projects bootstrap script or Makefile.

Usage
./bootstrap-bindown.sh -h
./bootstrap-bindown.sh: download the bindown binary

Usage: ./bootstrap-bindown.sh [-b bindir] [-d]
  -b sets bindir or installation directory, Defaults to ./bin
  -d turns on debug logging
Go get

If you happen to already have go installed on your system, you can install bindown with:

GO111MODULE=on go get -u github.com/willabides/bindown/v2/cmd/bindown 

Note the lowercase willabides. Pro tip: Your life will be easier with a lowercase GitHub username.

Config

bindown is configured with a yaml file. By default it uses a file named bindown.yml in the current directory.

Templates

Some fields below are marked with "allows templates". These fields allow you to use simple go templates that will be evaluated by bindown using the os, arch and vars values.

Downloader values
os

required

The operating system this binary is built for. Common values are windows, darwin and linux. macos and osx are aliases for darwin.

arch

required

The system architecture this binary is build for. Common values are amd64, 386 and arm.

url

required, allows templates

The url to download from. The url can point to either the binary itself or an archive containing the binary.

checksum

required

The sha256 hash of the download. Often projects will publish this in a checksums.txt file along with the downloads. You can get the value from there or run bindown config update-checksums <bin-name> to have bindown populate this automatically.

archive path

allows templates

The path to the binary once the downloaded archive has been extracted. If the download is just the unarchived binary, this should just be the downloaded file name.

default: the binary name

Whether bindown should create a symlink instead of moving the binary to its final destination.

default: false

bin

allows templates

What you want the final binary to be called if different from the downloader name.

default: the downloader name

vars

A map of string values to use in templated values.

Example
Simple config without templates
downloaders:
  golangci-lint:
  - os: darwin
    arch: amd64
    url: https://github.com/golangci/golangci-lint/releases/download/v1.21.0/golangci-lint-1.21.0-darwin-amd64.tar.gz
    checksum: 2b2713ec5007e67883aa501eebb81f22abfab0cf0909134ba90f60a066db3760
    archive_path: golangci-lint-1.21.0-darwin-amd64/golangci-lint
    link: true
  - os: linux
    arch: amd64
    url: https://github.com/golangci/golangci-lint/releases/download/v1.21.0/golangci-lint-1.21.0-linux-amd64.tar.gz
    checksum: 2c861f8dc56b560474aa27cab0c075991628cc01af3451e27ac82f5d10d5106b
    archive_path: golangci-lint-1.21.0-linux-amd64/golangci-lint
    link: true
  - os: windows
    arch: amd64
    url: https://github.com/golangci/golangci-lint/releases/download/v1.21.0/golangci-lint-1.21.0-windows-amd64.zip
    checksum: 2e40ded7adcf11e59013cb15c24438b15a86526ca241edfcfdf1abd73a5280a8
    archive_path: golangci-lint-1.21.0-windows-amd64/golangci-lint.exe
    link: true
With templates
downloaders:  
  golangci-lint:
  - os: darwin
    arch: amd64
    url: https://github.com/golangci/golangci-lint/releases/download/v{{.version}}/golangci-lint-{{.version}}-{{.os}}-{{.arch}}{{.urlsuffix}}
    archive_path: golangci-lint-{{.version}}-{{.os}}-{{.arch}}/golangci-lint{{.archivepathsuffix}}
    link: true
    checksum: 7536c375997cca3d2e1f063958ad0344108ce23aed6bd372b69153bdbda82d13
    vars:
      archivepathsuffix: ""
      urlsuffix: .tar.gz
      version: 1.23.7
  - os: linux
    arch: amd64
    url: https://github.com/golangci/golangci-lint/releases/download/v{{.version}}/golangci-lint-{{.version}}-{{.os}}-{{.arch}}{{.urlsuffix}}
    archive_path: golangci-lint-{{.version}}-{{.os}}-{{.arch}}/golangci-lint{{.archivepathsuffix}}
    link: true
    checksum: 34df1794a2ea8e168b3c98eed3cc0f3e13ed4cba735e4e40ef141df5c41bc086
    vars:
      archivepathsuffix: ""
      urlsuffix: .tar.gz
      version: 1.23.7
  - os: windows
    arch: amd64
    url: https://github.com/golangci/golangci-lint/releases/download/v{{.version}}/golangci-lint-{{.version}}-{{.os}}-{{.arch}}{{.urlsuffix}}
    archive_path: golangci-lint-{{.version}}-{{.os}}-{{.arch}}/golangci-lint{{.archivepathsuffix}}
    link: true
    checksum: 8ccb76466e4cdaebfc1633c137043c0bec23173749a6bca42846c7350402dcfe
    vars:
      archivepathsuffix: .exe
      urlsuffix: .zip
      version: 1.23.7

Usage

Usage: bindown <command>

Flags:
  --help                                     Show context-sensitive help.
  --configfile="bindown.yml|bindown.json"    file with bindown config
  --cellar-dir=STRING                        directory where downloads will be cached

Commands:
  version

  download <target-file>
    download a bin

  config format
    formats the config file

  config update-checksums <target-file>
    name of the binary to update

  config validate <bin>
    validate that downloads work

  config install-completions
    install shell completions

Run "bindown <command> --help" for more information on a command.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Downloaders  map[string][]*Downloader `json:"downloaders,omitempty" yaml:"downloaders"`
	URLChecksums map[string]string        `json:"url_checksums,omitempty" yaml:"url_checksums,omitempty"`
}

Config is downloaders configuration

func (*Config) AddDownloaderChecksums added in v2.7.1

func (c *Config) AddDownloaderChecksums(downloaderName, cellarDir string) error

AddDownloaderChecksums adds checksums to c.URLChecksums

func (*Config) Downloader

func (c *Config) Downloader(binary, os, arch string) *Downloader

Downloader returns a Downloader for the given binary, os and arch.

func (*Config) DownloaderExtractDir added in v2.8.0

func (c *Config) DownloaderExtractDir(downloader *Downloader, binName, cellarDir string) (string, error)

DownloaderExtractDir returns the directory where a downloader's archive will be extracted

func (*Config) Validate added in v2.4.3

func (c *Config) Validate(downloaderName string, cellarDir string) error

Validate installs downloaders to a temp directory and returns an error if it was unsuccessful. If cellarDir is empty, it uses a temp directory. If downloaderName is empty, it validates all downloaders.

type ConfigFile added in v2.2.0

type ConfigFile struct {
	Config
	// contains filtered or unexported fields
}

ConfigFile represents a config file

func LoadConfigFile

func LoadConfigFile(file string) (*ConfigFile, error)

LoadConfigFile loads a config file

func (*ConfigFile) Write added in v2.2.0

func (c *ConfigFile) Write() error

type Downloader

type Downloader struct {
	OS          string            `json:"os"`
	Arch        string            `json:"arch"`
	URL         string            `json:"url"`
	ArchivePath string            `json:"archive_path,omitempty" yaml:"archive_path,omitempty"`
	BinName     string            `json:"bin,omitempty" yaml:"bin,omitempty"`
	Link        bool              `json:"link,omitempty" yaml:",omitempty"`
	Checksum    string            `json:"checksum,omitempty" yaml:",omitempty"`
	Vars        map[string]string `json:"vars,omitempty" yaml:"vars,omitempty"`
	// contains filtered or unexported fields
}

Downloader downloads a binary

func (*Downloader) Install

func (d *Downloader) Install(opts InstallOpts) error

Install downloads and installs a bin

func (*Downloader) UpdateChecksum

func (d *Downloader) UpdateChecksum(opts UpdateChecksumOpts) error

UpdateChecksum updates the checksum based on a fresh download

func (*Downloader) Validate added in v2.1.1

func (d *Downloader) Validate(opts ValidateOpts) error

Validate installs the downloader to a temporary directory and returns an error if it was unsuccessful. If cellarDir is "", it will use a temp directory

type InstallOpts

type InstallOpts struct {
	// DownloaderName is the downloader's key from the config file
	DownloaderName string
	// CellarDir is the directory where downloads and extractions will be placed.  Default is a <TargetDir>/.bindown
	CellarDir string
	// TargetDir is the directory where the executable should end up
	TargetDir string
	// Force - whether to force the install even if it already exists
	Force bool
	// Map of known checksums to validate against
	URLChecksums map[string]string
}

InstallOpts options for Install

type UpdateChecksumOpts

type UpdateChecksumOpts struct {
	// CellarDir is the directory where downloads and extractions will be placed.  Default is a temp directory.
	CellarDir    string
	URLChecksums map[string]string
}

UpdateChecksumOpts options for UpdateChecksum

type ValidateOpts added in v2.4.3

type ValidateOpts struct {
	// DownloaderName is the downloader's key from the config file
	DownloaderName string
	// CellarDir is the directory where downloads and extractions will be placed.  Default is a temp directory.
	CellarDir string
}

ValidateOpts is options for Validate

Directories

Path Synopsis
cmd
internal
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL