Created
January 29, 2026 00:37
-
-
Save saper/16407d5ba46b8cbac7c81dd013309b09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/sh | |
| github_auth=${GITHUB_TOKEN:+--header="Authorization: Bearer $GITHUB_TOKEN"} | |
| verbosity="--quiet" | |
| github_releases() { | |
| { | |
| wget "$verbosity" -O - "$github_auth" https://api.github.com/repos/prometheus/node_exporter/releases || { | |
| echo "Cannot download the list of releases from github.com" >&2; exit 2; | |
| } | |
| } | tee .cached | |
| } | |
| fetch_releases() { | |
| cat .cached 2>/dev/null || github_releases | |
| } | |
| assets() { | |
| awk -F'": "' ' | |
| /published_at/ { PUBLISHED_DATE=$2 } | |
| /browser_download_url/ { | |
| print PUBLISHED_DATE, $2 | |
| } | |
| ' | sort -k 1 | sed -e 's/"$//' | |
| } | |
| strip_timestamp() { | |
| sed -e 's/.*, //' | |
| } | |
| list_versions() { | |
| sed -e 's,https://.*/releases/download/v,,;s,/.*,,' | strip_timestamp | uniq | |
| } | |
| checksum_latest() { | |
| grep "sha256sums.txt" | tail -1 | strip_timestamp | |
| } | |
| checksum_version() { | |
| grep "/v${1?need version}/" | grep "sha256sums.txt" | strip_timestamp | |
| } | |
| select_arch_latest() { | |
| grep "linux-${1?need arch}" | tail -1 | strip_timestamp | |
| } | |
| select_arch_version() { | |
| grep "/v${2?need version}/" | grep "linux-${1?need arch}" | strip_timestamp | |
| } | |
| download_url() { | |
| while read URL | |
| do | |
| wget "$verbosity" -O "$(basename "${URL}")" "$github_auth" "${URL}" || { | |
| echo "Cannot download \"${URL}\"" >&2; exit 3; | |
| } | |
| done | |
| } | |
| fetch_releases | assets | list_versions | |
| fetch_releases | assets | select_arch_version amd64 1.10.0 | download_url | |
| fetch_releases | assets | checksum_version notexisting | download_url | |
| fetch_releases | assets | checksum_version 1.10.0 | download_url | |
| sha256sum -c --ignore-missing sha256sums.txt | |
| fetch_releases | assets | select_arch_latest amd64 | |
| fetch_releases | assets | select_arch_latest amd64 | download_url | |
| fetch_releases | assets | checksum_latest | download_url | |
| sha256sum -c --ignore-missing sha256sums.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment