Skip to content

Repository files navigation

build

Snap Store

fetch

Downloads an aritfact from a URL and optionally verifies it's SHA256 or MD5 checksum.

Usage

fetch -L $SOME_URL --sha256 $SHA256_HASH

Motivation

A typical use case is to download an artifact from a URL and verify it's checksum afterwards. Unfortunately, there is no commonly used tool which provides this in one step. There are multiple feature requests on commonly used tools such as curl, which were closed due to a lack of interest (see here or here).

On the other hand, popular tools such as rustup and node.js propose dangerous workflows for installations, where a direct download is piped into a shell:

url --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

It would be nice to enhance security of those workflows by verifiing a MD5 oder SHA256 checksum during download.

This can be achieved using the fetch utility.

Command Line Options

fetch [OPTIONS] <URL>

Command line options are strongly inspired by curl. While fetch does not use all options that curl provides, the options fetch provides are named the same as curl's options. Therefore, fetch can be used as drop-in replacement for curl in most use cases.

OptionTypeDescription
-o, --outputPathWrite to file instead of stdout
-X, --requestHTTP MethodSpecify the request method to use
-H, --headerstringPass custom header(s) to server
-A, --user-agentstringSend user agent to server
-d, --datastringPost data
--data-rawstringPost data, '@' allowed
-F, --formstringSpecify multipart form data as name=value pair
-k, --insecureflagAllow insecure server connections
-L, --locationflagFollow redirects
--max-redirsuintMaximum number of redirects
--max-filesizeuintMaximum file size to download
--connection-timeoutuintMaximum time allowed for connection in seconds
-m, --max-timeuintMaximum time allowed for transfer in seconds
-1, --tlsv1, --tlsv1.0flagUse TLSv1.0 or later
--tlsv1.1flagUse TLSv1.1 or later
--tlsv1.2flagUse TLSv1.2 or later
--tlsv1.3flagUse TLSv1.3 or later
--protostringList of enabled protocols (see below)
-s, --silentflagSilent mode
-S, --show-errorflagshow error messages, even in silent mode
-v, --verboseflagshow additional log messages
-i, --includeflaginclude HTTP reponse headers in the output
-f, --failflagFail silently (no output at all) on HTTP errors
--fail-with-bodyflagFail on HTTP errors but save the body
-x, --proxystring
--cacertstringCA certificate to verify peer against
--crlfilestringUse this CRL list
--sha256hex-stringSHA256 checksum of the artifact to download
--md5hex-stringMD5 checksum of the artifact to download
-h, --helpflagPrint help
-V, --versionflagPrint version

Protocols

The argument of the --proto option is a single string that contains an expression that is evaluated from the left to the right. It contains a list of protocols with an optional modifier. The following modifiers are defined:

  • +: adds a protocol; default if no modifier is specified explicitly
  • -: removed a protocol
  • =: sets the specified protocol only

Known protocols:

  • all: placeholder for all known protocols
  • http: HTTP protocol
  • https: HTTPS protocol

Examples:

  • =https: allow HTTPS only
  • -all,https: allow HTTPS only
  • -http: don't allow HTTP

Note that fetch uses this argument only to check, if HTTP-only mode can be activated, fetch does never disable HTTPS. The --proto option was added to maintain compatibility with curl.

Missing Features

Fetch does not aim at full curl compatibility, since fetch focuses on http / https protocol only. We also do not aim to support each http / https related option, since some options are rarely used.

The following options are planned to be added in future:

  • mTLS support
    curl options: -E, --cert, --cert-status, --cert-type
  • .netrc support
    curl options: -n, --netrc, --netrc-file
  • show document information
    curl options: -I, --head
  • dump response headers info file
    curl options: -D, --dump-reader
  • etag support
    curl options: --etag-compare, --etag-save
  • put post data in url for GET request
    curl options: -G, --get
  • convenience helpers for often used headers
    curl options: -u, --user, -r, --range, -e, --referer, -b,
    --cookie, -c, --cookie-jar, -U, --proxy-user
  • redirect stderr
    curl option: --stderr

Run tests

In order to run tests, bats is needed. Please install bats and build fetch before running the tests.

bats test

About

Download artifact and verify it's checksum.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages