@@ -14,10 +14,10 @@ CYAN='\033[0;36m'
1414BOLD=' \033[1m'
1515RESET=' \033[0m'
1616
17- info () { echo -e " ${CYAN} [info]${RESET} $* " ; }
18- success () { echo -e " ${GREEN} [✔]${RESET} $* " ; }
19- warn () { echo -e " ${YELLOW} [warn]${RESET} $* " ; }
20- error () { echo -e " ${RED} [✘]${RESET} $* " ; exit 1; }
17+ info () { echo -e " ${CYAN} [info]${RESET} $* " >&2 ; }
18+ success () { echo -e " ${GREEN} [✔]${RESET} $* " >&2 ; }
19+ warn () { echo -e " ${YELLOW} [warn]${RESET} $* " >&2 ; }
20+ error () { echo -e " ${RED} [✘]${RESET} $* " >&2 ; exit 1; }
2121
2222detect_os () {
2323 local os
@@ -46,8 +46,8 @@ resolve_version() {
4646 if [ " $version " = " latest" ]; then
4747 info " Resolving latest release..."
4848 version=$( curl -fsSL " https://api.github.com/repos/$REPO /releases/latest" \
49- | grep ' "tag_name"' \
50- | sed -E ' s/.*"tag_name":\s*"([^"]+)".*/\1/ ' )
49+ | grep -m 1 ' "tag_name": ' \
50+ | cut -d ' " ' -f 4 )
5151
5252 if [ -z " $version " ]; then
5353 error " Could not determine the latest release. Check https://github.com/$REPO /releases"
@@ -62,9 +62,9 @@ install() {
6262 local arch=" $2 "
6363 local version=" $3 "
6464
65- local ext=" "
65+ local ext=" .tar.gz "
6666 if [ " $os " = " windows" ]; then
67- ext=" .exe "
67+ ext=" .zip "
6868 fi
6969
7070 local asset_name=" ${BINARY_NAME} -${os} -${arch}${ext} "
@@ -74,20 +74,53 @@ install() {
7474 info " Version: ${BOLD}${version}${RESET} "
7575 info " Downloading ${BOLD}${asset_name}${RESET} ..."
7676
77+ local tmp_dir
78+ tmp_dir=" $( mktemp -d) "
79+ local tmp_file=" ${tmp_dir} /${asset_name} "
80+
7781 # Create install directory
7882 mkdir -p " $INSTALL_DIR "
7983
80- local target_path=" ${INSTALL_DIR} /${BINARY_NAME}${ext} "
81-
8284 # Download
8385 local http_code
84- http_code=$( curl -fsSL -w " %{http_code}" -o " $target_path " " $download_url " 2>&1 ) || true
86+ http_code=$( curl -fsSL -w " %{http_code}" -o " $tmp_file " " $download_url " 2>&1 ) || true
8587
86- if [ ! -f " $target_path " ] || [ ! -s " $target_path " ]; then
87- rm -f " $target_path "
88+ if [ ! -f " $tmp_file " ] || [ ! -s " $tmp_file " ]; then
89+ rm -rf " $tmp_dir "
8890 error " Download failed. URL: $download_url \n Make sure release $version exists with asset $asset_name ."
8991 fi
9092
93+ info " Extracting..."
94+ if [ " $os " = " windows" ]; then
95+ unzip -q -o " $tmp_file " -d " $INSTALL_DIR " || {
96+ rm -rf " $tmp_dir "
97+ error " Failed to extract $tmp_file "
98+ }
99+ else
100+ tar -xzf " $tmp_file " -C " $INSTALL_DIR " || {
101+ rm -rf " $tmp_dir "
102+ error " Failed to extract $tmp_file "
103+ }
104+ fi
105+
106+ rm -rf " $tmp_dir "
107+
108+ local extracted_file=" ${INSTALL_DIR} /${BINARY_NAME} -${os} -${arch} "
109+ local target_path=" ${INSTALL_DIR} /${BINARY_NAME} "
110+
111+ if [ " $os " = " windows" ]; then
112+ target_path=" ${target_path} .exe"
113+ if [ -f " ${extracted_file} .exe" ]; then
114+ extracted_file=" ${extracted_file} .exe"
115+ fi
116+ fi
117+
118+ if [ -f " $extracted_file " ]; then
119+ mv " $extracted_file " " $target_path "
120+ else
121+ error " Could not find expected binary '$extracted_file ' after extraction."
122+ fi
123+
91124 # Make executable (skip on Windows)
92125 if [ " $os " != " windows" ]; then
93126 chmod +x " $target_path "
0 commit comments