Skip to content

Commit 530f888

Browse files
committed
Fix POSIX compliance: replace echo -e with printf
1 parent f535de9 commit 530f888

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

install.sh

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ timestamp() {
4747
}
4848

4949
info() {
50-
echo -e "$(timestamp) ${GREEN}INF${NC} $1"
50+
printf "%s %bINF%b %s\n" "$(timestamp)" "${GREEN}" "${NC}" "$1"
5151
}
5252

5353
warn() {
54-
echo -e "$(timestamp) ${YELLOW}WRN${NC} $1"
54+
printf "%s %bWRN%b %s\n" "$(timestamp)" "${YELLOW}" "${NC}" "$1"
5555
}
5656

5757
error() {
58-
echo -e "$(timestamp) ${RED}ERR${NC} $1"
58+
printf "%s %bERR%b %s\n" "$(timestamp)" "${RED}" "${NC}" "$1"
5959
exit 1
6060
}
6161

@@ -91,16 +91,16 @@ fetch_url() {
9191

9292
case "$DOWNLOAD_TOOL" in
9393
curl)
94-
curl -s "$url"
94+
curl -sS -f "$url" 2>&1
9595
;;
9696
wget)
97-
wget -qO- "$url"
97+
wget -qO- "$url" 2>&1
9898
;;
9999
python3)
100-
python3 -c "import urllib.request; import sys; response = urllib.request.urlopen('$url'); sys.stdout.buffer.write(response.read())"
100+
python3 -c "import urllib.request; import sys; response = urllib.request.urlopen('$url'); sys.stdout.buffer.write(response.read())" 2>&1
101101
;;
102102
python)
103-
python -c "import urllib.request; import sys; response = urllib.request.urlopen('$url'); sys.stdout.buffer.write(response.read())"
103+
python -c "import urllib.request; import sys; response = urllib.request.urlopen('$url'); sys.stdout.buffer.write(response.read())" 2>&1
104104
;;
105105
*)
106106
error "No download tool available"
@@ -129,19 +129,29 @@ detect_arch() {
129129
# Get latest release version from GitHub API
130130
get_latest_version() {
131131
local version
132+
local response
132133

133134
# Try /releases/latest first
134-
version=$(fetch_url "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
135+
response=$(fetch_url "https://api.github.com/repos/${REPO}/releases/latest" 2>&1)
136+
if [ $? -ne 0 ]; then
137+
warn "Failed to fetch from /releases/latest endpoint"
138+
warn "Response: $response"
139+
else
140+
version=$(echo "$response" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
141+
fi
135142

136143
# If that fails, get the first non-draft, non-prerelease from /releases
137144
if [ -z "$version" ]; then
138-
version=$(fetch_url "https://api.github.com/repos/${REPO}/releases" | \
139-
grep -m 1 '"tag_name":' | \
140-
sed -E 's/.*"([^"]+)".*/\1/')
145+
response=$(fetch_url "https://api.github.com/repos/${REPO}/releases" 2>&1)
146+
if [ $? -ne 0 ]; then
147+
error "Failed to fetch from /releases endpoint. Response: $response"
148+
else
149+
version=$(echo "$response" | grep -m 1 '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
150+
fi
141151
fi
142152

143153
if [ -z "$version" ]; then
144-
error "Failed to fetch latest version from GitHub"
154+
error "Failed to parse version from GitHub API response"
145155
fi
146156

147157
echo "$version"
@@ -188,7 +198,9 @@ parse_args() {
188198
usage
189199
;;
190200
*)
191-
error "Unknown option: $1\nRun '$0 --help' for usage"
201+
printf "%s\n" "Unknown option: $1"
202+
printf "%s\n" "Run '$0 --help' for usage"
203+
exit 1
192204
;;
193205
esac
194206
done

0 commit comments

Comments
 (0)