Skip to content

Commit 460f71b

Browse files
committed
Fallback to wget
[GitHub #185]
1 parent 4c6ca7d commit 460f71b

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

tool/installer.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,29 @@ set_install_dir() {
218218
fi
219219
}
220220

221+
#
222+
# @param $1: 下载链接
223+
# @param $2: 保存路径(带文件名)
224+
#
225+
download() {
226+
if command -v curl &>/dev/null; then
227+
curl -sL "$1" -o "$2"
228+
return $? # 只能单独 return
229+
fi
230+
231+
if command -v wget &>/dev/null; then
232+
# follow 是wget默认行为
233+
wget -qO "$2" "$1"
234+
return $?
235+
fi
236+
237+
if [ "$userOpt_lang" = "zh" ]; then
238+
error "缺乏必要的下载工具(curl或wget),无法下载文件"
239+
else
240+
error "Missing necessary download tools (curl or wget) to download the file!"
241+
fi
242+
}
243+
221244

222245
install() {
223246

@@ -239,11 +262,13 @@ install() {
239262
info "Downloading ${binary_name} (arch: ${arch}, platform: ${platform}, version: ${binary_version}) to ${path_to_executable}"
240263
fi
241264

242-
if curl -sL "$url" -o "$path_to_executable"; then
265+
download $url "$path_to_executable"
266+
267+
if $?; then
243268
chmod +x "$path_to_executable"
244269

245270
if [ "$userOpt_lang" = "zh" ]; then
246-
info "🎉 安装完成,a版本: $binary_version路径: $path_to_executable"
271+
info "🎉 安装完成,路径: $path_to_executable"
247272
else
248273
info "🎉 Installation completed, path: $path_to_executable"
249274
fi

0 commit comments

Comments
 (0)