Skip to content

Commit 28a8168

Browse files
authored
Merge pull request #40 from nathfavour/master
Bypass API rate limits in installer
2 parents 4f7e2d2 + 1aa70aa commit 28a8168

1 file changed

Lines changed: 36 additions & 25 deletions

File tree

install.sh

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,40 +40,51 @@ fi
4040
echo "Detected Platform: $OS/$ARCH"
4141

4242
# Get latest release tag
43-
# GitHub's /releases/latest endpoint only returns non-prereleases.
44-
# We fetch the release list and use a robust way to extract the tag name,
45-
# handling both pretty-printed and minified JSON.
43+
# We prefer git ls-remote to avoid GitHub API rate limits (403 errors).
44+
# If git is not available, we fallback to the API.
4645
echo "Fetching release metadata..."
4746

48-
# Use a portable temporary file (Termux doesn't have /tmp)
49-
TMP_ERR=$(mktemp)
50-
TAG_DATA=$(curl -fsSL -H "User-Agent: vibeauracle-installer" "https://api.github.com/repos/$REPO/releases" 2>"$TMP_ERR" || true)
51-
52-
if [ -z "$TAG_DATA" ]; then
53-
echo "Error: Failed to fetch releases from GitHub API."
54-
if [ -f "$TMP_ERR" ]; then
55-
cat "$TMP_ERR"
56-
rm "$TMP_ERR"
47+
LATEST_TAG=""
48+
if command -v git >/dev/null 2>&1; then
49+
# Try to get the latest tag (preferring 'latest' rolling tag or newest semver)
50+
ALL_TAGS=$(git ls-remote --tags "https://github.com/$REPO.git" | cut -d/ -f3)
51+
if echo "$ALL_TAGS" | grep -q "^latest$"; then
52+
LATEST_TAG="latest"
53+
else
54+
LATEST_TAG=$(echo "$ALL_TAGS" | grep -E "^v[0-9]" | sort -V | tail -n 1)
5755
fi
58-
exit 1
5956
fi
60-
rm "$TMP_ERR"
6157

62-
LATEST_TAG=$(echo "$TAG_DATA" | grep -oE '"tag_name": *"[^"]+"' | head -n 1 | cut -d'"' -f4)
58+
if [ -z "$LATEST_TAG" ]; then
59+
# Fallback to API if git failed or wasn't found
60+
TMP_ERR=$(mktemp)
61+
TAG_DATA=$(curl -fsSL -H "User-Agent: vibeauracle-installer" "https://api.github.com/repos/$REPO/releases" 2>"$TMP_ERR" || true)
62+
63+
if [ -n "$TAG_DATA" ]; then
64+
LATEST_TAG=$(echo "$TAG_DATA" | grep -oE '"tag_name": *"[^"]+"' | head -n 1 | cut -d'"' -f4)
65+
66+
# If we found tags but it wasn't the 'latest' tag specifically,
67+
# try to see if 'latest' exists in the list for stability
68+
if [[ "$LATEST_TAG" != "latest" ]]; then
69+
STABLE_TAG=$(echo "$TAG_DATA" | grep -oE '"tag_name": *"latest"' | head -n 1 | cut -d'"' -f4)
70+
if [ -n "$STABLE_TAG" ]; then
71+
LATEST_TAG="$STABLE_TAG"
72+
fi
73+
fi
74+
fi
6375

64-
# If we found tags but it wasn't the 'latest' tag specifically,
65-
# try to see if 'latest' exists in the list for stability
66-
if [[ "$LATEST_TAG" != "latest" ]]; then
67-
STABLE_TAG=$(echo "$TAG_DATA" | grep -oE '"tag_name": *"latest"' | head -n 1 | cut -d'"' -f4)
68-
if [ -n "$STABLE_TAG" ]; then
69-
LATEST_TAG="$STABLE_TAG"
76+
if [ -z "$LATEST_TAG" ]; then
77+
echo "Error: Failed to fetch releases from GitHub."
78+
if [ -f "$TMP_ERR" ] && [ -s "$TMP_ERR" ]; then
79+
cat "$TMP_ERR"
80+
fi
81+
rm -f "$TMP_ERR"
82+
exit 1
7083
fi
84+
rm -f "$TMP_ERR"
7185
fi
7286

73-
if [ -z "$LATEST_TAG" ]; then
74-
echo "Error: Could not determine latest version. Please check $GITHUB_URL/releases"
75-
exit 1
76-
fi
87+
echo "Resolved version: $LATEST_TAG"
7788

7889
DOWNLOAD_URL="$GITHUB_URL/releases/download/$LATEST_TAG/$BINARY_NAME"
7990

0 commit comments

Comments
 (0)