Skip to content

Commit d3500d4

Browse files
authored
Merge pull request #3 from vsilent/dev
install: fallback when latest release is missing
2 parents 8bf0648 + 2f152b7 commit d3500d4

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

install.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Stackdog Security — install script
33
#
44
# Usage:
5-
# curl -fsSL https://raw.githubusercontent.com/vsilent/stackdog/dev/install.sh | sudo bash
6-
# curl -fsSL https://raw.githubusercontent.com/vsilent/stackdog/dev/install.sh | sudo bash -s -- --version v0.2.0
5+
# curl -fsSL https://raw.githubusercontent.com/vsilent/stackdog/main/install.sh | sudo bash
6+
# curl -fsSL https://raw.githubusercontent.com/vsilent/stackdog/main/install.sh | sudo bash -s -- --version v0.2.0
77
#
88
# Installs the stackdog binary to /usr/local/bin.
99
# Requires: curl, tar, sha256sum (or shasum), Linux x86_64 or aarch64.
@@ -57,11 +57,23 @@ resolve_version() {
5757
fi
5858

5959
info "Fetching latest release..."
60-
TAG="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
61-
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')"
60+
TAG="$(
61+
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" 2>/dev/null \
62+
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/' || true
63+
)"
6264

65+
# GitHub returns 404 for /releases/latest when there are no stable releases
66+
# (for example only pre-releases). Fall back to the most recent release entry.
6367
if [ -z "$TAG" ]; then
64-
error "Could not determine latest release. Specify a version with --version"
68+
warn "No stable 'latest' release found, trying most recent release..."
69+
TAG="$(
70+
curl -fsSL "https://api.github.com/repos/${REPO}/releases?per_page=1" 2>/dev/null \
71+
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/' || true
72+
)"
73+
fi
74+
75+
if [ -z "$TAG" ]; then
76+
error "Could not determine latest release. Create a GitHub release, or specify one with --version (e.g. --version v0.2.0)."
6577
fi
6678

6779
VERSION="$(echo "$TAG" | sed 's/^v//')"

0 commit comments

Comments
 (0)