Skip to content

Commit 856cf30

Browse files
committed
fix: install script
1 parent 6c42259 commit 856cf30

File tree

2 files changed

+61
-26
lines changed

2 files changed

+61
-26
lines changed

.goreleaser.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
version: 2
2+
13
env:
24
- GO111MODULE=on
35
- CGO_ENABLED=0
@@ -48,7 +50,8 @@ builds:
4850

4951
archives:
5052
- id: cli
51-
allow_different_binary_count: true
53+
builds:
54+
- cli
5255
format_overrides:
5356
- goos: windows
5457
format: zip

install.sh

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ has() {
3131
command -v "$1" 1>/dev/null 2>&1
3232
}
3333

34-
SUPPORTED_TARGETS="linux_amd64 linux_arm64 windows_amd64 darwin_amd64 darwin_arm64"
34+
SUPPORTED_TARGETS="Linux_x86_64 Linux_arm64 Windows_x86_64 Darwin_x86_64 Darwin_arm64"
3535

3636
get_latest_release() {
3737
curl --silent "https://api.github.com/repos/mr-karan/doggo/releases/latest" |
@@ -40,11 +40,11 @@ get_latest_release() {
4040
}
4141

4242
detect_platform() {
43-
platform="$(uname -s | tr '[:upper:]' '[:lower:]')"
43+
platform="$(uname -s)"
4444
case "${platform}" in
45-
linux) platform="linux" ;;
46-
darwin) platform="darwin" ;;
47-
msys*|mingw*) platform="windows" ;;
45+
Linux*) platform="Linux" ;;
46+
Darwin*) platform="Darwin" ;;
47+
MINGW*|MSYS*|CYGWIN*) platform="Windows" ;;
4848
*)
4949
error "Unsupported platform: ${platform}"
5050
exit 1
@@ -56,7 +56,7 @@ detect_platform() {
5656
detect_arch() {
5757
arch="$(uname -m)"
5858
case "${arch}" in
59-
x86_64) arch="amd64" ;;
59+
x86_64) arch="x86_64" ;;
6060
aarch64|arm64) arch="arm64" ;;
6161
*)
6262
error "Unsupported architecture: ${arch}"
@@ -73,7 +73,11 @@ download_and_install() {
7373

7474
# Remove 'v' prefix from version for filename
7575
version_no_v="${version#v}"
76-
filename="doggo_${version_no_v}_${platform}_${arch}.tar.gz"
76+
if [ "${platform}" = "Windows" ]; then
77+
filename="doggo_${version_no_v}_${platform}_${arch}.zip"
78+
else
79+
filename="doggo_${version_no_v}_${platform}_${arch}.tar.gz"
80+
fi
7781
url="https://github.com/mr-karan/doggo/releases/download/${version}/${filename}"
7882

7983
info "Downloading doggo ${version} for ${platform}_${arch}..."
@@ -99,39 +103,67 @@ download_and_install() {
99103
fi
100104

101105
info "Verifying downloaded file..."
102-
if ! file "${filename}" | grep -q "gzip compressed data"; then
103-
error "Downloaded file is not in gzip format. Installation failed."
104-
error "File type:"
105-
file "${filename}"
106-
rm -f "${filename}"
107-
exit 1
106+
if [ "${platform}" = "Windows" ]; then
107+
if ! file "${filename}" | grep -q "Zip archive data"; then
108+
error "Downloaded file is not in zip format. Installation failed."
109+
error "File type:"
110+
file "${filename}"
111+
rm -f "${filename}"
112+
exit 1
113+
fi
114+
else
115+
if ! file "${filename}" | grep -q "gzip compressed data"; then
116+
error "Downloaded file is not in gzip format. Installation failed."
117+
error "File type:"
118+
file "${filename}"
119+
rm -f "${filename}"
120+
exit 1
121+
fi
108122
fi
109123

110124
info "Extracting ${filename}..."
111-
if ! tar -xzvf "${filename}"; then
112-
error "Failed to extract ${filename}"
113-
rm -f "${filename}"
114-
exit 1
125+
extract_dir="doggo_extract"
126+
mkdir -p "${extract_dir}"
127+
if [ "${platform}" = "Windows" ]; then
128+
if ! unzip -q "${filename}" -d "${extract_dir}"; then
129+
error "Failed to extract ${filename}"
130+
rm -rf "${filename}" "${extract_dir}"
131+
exit 1
132+
fi
133+
else
134+
if ! tar -xzvf "${filename}" -C "${extract_dir}"; then
135+
error "Failed to extract ${filename}"
136+
rm -rf "${filename}" "${extract_dir}"
137+
exit 1
138+
fi
115139
fi
116140

117141
info "Installing doggo..."
118-
if [ ! -f "doggo" ]; then
119-
error "doggo binary not found in the extracted files"
142+
binary_name="doggo"
143+
if [ "${platform}" = "Windows" ]; then
144+
binary_name="doggo.exe"
145+
fi
146+
147+
# Find the doggo binary in the extracted directory
148+
binary_path=$(find "${extract_dir}" -name "${binary_name}" -type f)
149+
150+
if [ -z "${binary_path}" ]; then
151+
error "${binary_name} not found in the extracted files"
120152
error "Extracted files:"
121-
ls -la
122-
rm -f "${filename}"
153+
ls -R "${extract_dir}"
154+
rm -rf "${filename}" "${extract_dir}"
123155
exit 1
124156
fi
125157

126-
chmod +x doggo
127-
if ! sudo mv doggo /usr/local/bin/; then
158+
chmod +x "${binary_path}"
159+
if ! sudo mv "${binary_path}" /usr/local/bin/doggo; then
128160
error "Failed to move doggo to /usr/local/bin/"
129-
rm -f "${filename}" "doggo"
161+
rm -rf "${filename}" "${extract_dir}"
130162
exit 1
131163
fi
132164

133165
info "Cleaning up..."
134-
rm -f "${filename}"
166+
rm -rf "${filename}" "${extract_dir}"
135167

136168
completed "doggo ${version} has been installed to /usr/local/bin/doggo"
137169
}

0 commit comments

Comments
 (0)