@@ -8,16 +8,45 @@ readonly DOWNLOAD_URL_TEMPLATE="https://github.com/Gallardo994/xx-cli/releases/d
88readonly SUPPORTED_MACOS_ARCHS=(" arm64" )
99readonly SUPPORTED_LINUX_ARCHS=(" x86_64" " arm64" )
1010
11+ has_command () {
12+ command -v " $1 " > /dev/null 2>&1
13+ }
14+
15+ download_file () {
16+ local url=" $1 "
17+ local output=" $2 "
18+
19+ if has_command curl; then
20+ printf " Using curl"
21+ curl -sSL " ${url} " -o " ${output} "
22+ return $?
23+ elif has_command wget; then
24+ printf " Using wget"
25+ wget -q -O " ${output} " " ${url} "
26+ return $?
27+ else
28+ echo " Error: Neither curl nor wget is installed. Please install one of them and try again." >&2
29+ return 1
30+ fi
31+ }
32+
1133get_latest_release () {
12- curl -sSL " ${RELEASES_URL} /latest" | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/'
34+ local curl_or_wget_args
35+
36+ if has_command curl; then
37+ curl -sSL " ${RELEASES_URL} /latest" | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/'
38+ elif has_command wget; then
39+ wget -qO- " ${RELEASES_URL} /latest" | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/'
40+ else
41+ echo " "
42+ fi
1343}
1444
1545install_xx_cli () {
1646 local LATEST_RELEASE
1747 LATEST_RELEASE=$( get_latest_release)
1848
1949 if [ -z " ${LATEST_RELEASE} " ]; then
20- echo " Failed to fetch the latest release version. Cancelling." >&2
2150 exit 1
2251 fi
2352
@@ -54,11 +83,18 @@ install_xx_cli() {
5483 fi
5584 fi
5685
86+ local DOWNLOAD_URL
5787 DOWNLOAD_URL=$( printf " ${DOWNLOAD_URL_TEMPLATE} " " ${LATEST_RELEASE} " " ${PLATFORM} " " ${ARCH} " )
88+ local DOWNLOAD_TEMP_FILE
5889 DOWNLOAD_TEMP_FILE=" $( mktemp) "
5990
6091 printf " Downloading ${PLATFORM} -${ARCH} from %s\n" " ${DOWNLOAD_URL} "
61- curl -L -o " ${DOWNLOAD_TEMP_FILE} " " ${DOWNLOAD_URL} "
92+
93+ if ! download_file " ${DOWNLOAD_URL} " " ${DOWNLOAD_TEMP_FILE} " ; then
94+ rm -f " ${DOWNLOAD_TEMP_FILE} "
95+ exit 1
96+ fi
97+
6298 chmod +x " ${DOWNLOAD_TEMP_FILE} "
6399 printf " File downloaded to %s\n" " ${DOWNLOAD_TEMP_FILE} "
64100
@@ -68,7 +104,6 @@ install_xx_cli() {
68104 if command -v xx > /dev/null 2>&1 ; then
69105 xx version
70106 else
71- echo " Installation failed. xx not found. Is ${INSTALL_DIRECTORY} in your PATH?" >&2
72107 exit 1
73108 fi
74109}
0 commit comments