Skip to content

Commit c86d373

Browse files
authored
fix: simplify and fix install script (#420)
1 parent 2475456 commit c86d373

1 file changed

Lines changed: 6 additions & 80 deletions

File tree

scripts/install.sh

Lines changed: 6 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ set -o pipefail # Catch errors in piped commands
2121
# - Proper cleanup of temporary files
2222
# - Error handling for failed operations
2323
#
24-
# Usage:
25-
# Beta release: curl -sSfL https://raw.githubusercontent.com/herodevs/cli/refs/heads/main/scripts/install.sh | bash
26-
# Latest release: curl -sSfL https://raw.githubusercontent.com/herodevs/cli/refs/heads/main/scripts/install.sh | bash -s -- --latest
24+
# Usage: curl -sSfL https://raw.githubusercontent.com/herodevs/cli/refs/heads/main/scripts/install.sh | bash
2725
#=============================================================================
2826

2927
# Configuration
@@ -34,8 +32,7 @@ INSTALL_DIR="$HOME/.herodevs"
3432
BIN_DIR="$INSTALL_DIR/bin"
3533
GITHUB_API_URL="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases"
3634
TMP_DIR=""
37-
USE_BETA=true
38-
# LATEST_VERSION="v2.0.0-beta.13"
35+
LATEST_VERSION="v2.0.0-beta.13"
3936
DEBUG=${DEBUG:-}
4037

4138
# Colors for output
@@ -81,26 +78,6 @@ error_exit() {
8178
exit 1
8279
}
8380

84-
# Parse arguments
85-
while [ $# -gt 0 ]; do
86-
case $1 in
87-
-l | --latest)
88-
USE_BETA=false
89-
shift
90-
;;
91-
-h | --help)
92-
# Help text goes to the original stdout
93-
emit "Usage: $0 [-l|--latest]"
94-
emit " -l, --latest Install latest release (default: install beta)"
95-
emit " -h, --help Show this help message"
96-
exit 0
97-
;;
98-
*)
99-
error_exit "Unknown option: $1"
100-
;;
101-
esac
102-
done
103-
10481
# Cleanup on exit/interrupt
10582
cleanup() {
10683
if [ -n "$TMP_DIR" ] && [ -d "$TMP_DIR" ]; then
@@ -113,49 +90,6 @@ trap cleanup EXIT INT TERM
11390

11491
log "INFO" "Installing HeroDevs CLI"
11592

116-
# Get release version (beta or latest)
117-
get_version() {
118-
local use_beta="$1"
119-
local releases_data="$2"
120-
121-
log "INFO" "Extracting release version"
122-
local all_tags
123-
local latest_release
124-
local beta_release
125-
local version_tag
126-
127-
# Split complex command chains for Bash 3 compatibility
128-
all_tags=$(echo "$releases_data" | grep -o '"tag_name": "[^"]*"')
129-
all_tags=$(echo "$all_tags" | cut -d'"' -f4)
130-
131-
# Get latest non-beta release
132-
latest_release=$(echo "$all_tags" | grep -v "beta" | head -n 1)
133-
134-
# Get latest beta release
135-
beta_release=$(echo "$all_tags" | grep "beta" | head -n 1)
136-
137-
log "DEBUG" "All tags: $all_tags"
138-
log "DEBUG" "Latest release: $latest_release"
139-
log "DEBUG" "Beta release: $beta_release"
140-
141-
if [ "$use_beta" = "true" ]; then
142-
version_tag="$beta_release"
143-
if [ -z "$version_tag" ]; then
144-
log "ERROR" "No beta release found. Please try again later or use --latest to install the latest stable release."
145-
exit 1
146-
fi
147-
else
148-
version_tag="$latest_release"
149-
if [ -z "$version_tag" ]; then
150-
error_exit "No latest release found. Please try again later."
151-
fi
152-
fi
153-
154-
log "INFO" "Using version: $version_tag"
155-
# Output actual return value to the original stdout (FD 3)
156-
emit "$version_tag"
157-
}
158-
15993
# Download and install
16094
install() {
16195
# Fetch releases from GitHub
@@ -171,21 +105,13 @@ install() {
171105
error_exit "Empty response from GitHub API. Please try again later."
172106
fi
173107

174-
# Ensure the response contains release data
175-
if ! echo "$releases" | grep -q '"tag_name"'; then
176-
error_exit "Invalid response from GitHub API. Please try again later."
177-
fi
178-
179-
# Determine VERSION_TAG
180-
VERSION_TAG=$(get_version "$USE_BETA" "$releases" 3>&1 1>&2)
181-
182-
local version_tag="$VERSION_TAG"
108+
local version_tag="$LATEST_VERSION"
183109

184110
# Remove 'v' prefix if present
185111
local version
186112
version=${version_tag#v}
187113

188-
log "DEBUG" "Version string: $version"
114+
log "INFO" "Installing version: $version"
189115

190116
# Detect system
191117
local os
@@ -207,7 +133,7 @@ install() {
207133
pattern="${os}-${arch}"
208134

209135
# Extract all browser_download_url values for the matching release
210-
release_block=$(echo "$releases" | awk -v tag="\"$VERSION_TAG\"" '
136+
release_block=$(echo "$releases" | awk -v tag="\"$LATEST_VERSION\"" '
211137
BEGIN {found=0; block=""}
212138
$0 ~ tag {found=1}
213139
found {
@@ -227,7 +153,7 @@ install() {
227153

228154
# Ensure we found a matching asset
229155
if [ -z "$download_url" ]; then
230-
error_exit "No release found system $pattern for release $VERSION_TAG"
156+
error_exit "No release found system $pattern for release $LATEST_VERSION"
231157
fi
232158

233159
log "DEBUG" "Download URL: $download_url"

0 commit comments

Comments
 (0)