Skip to content

Commit

Permalink
fix: install script
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-karan committed Jul 1, 2024
1 parent 6db870f commit a01e451
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 26 deletions.
5 changes: 4 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version: 2

env:
- GO111MODULE=on
- CGO_ENABLED=0
Expand Down Expand Up @@ -48,7 +50,8 @@ builds:

archives:
- id: cli
allow_different_binary_count: true
builds:
- cli
format_overrides:
- goos: windows
format: zip
Expand Down
82 changes: 57 additions & 25 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ has() {
command -v "$1" 1>/dev/null 2>&1
}

SUPPORTED_TARGETS="linux_amd64 linux_arm64 windows_amd64 darwin_amd64 darwin_arm64"
SUPPORTED_TARGETS="Linux_x86_64 Linux_arm64 Windows_x86_64 Darwin_x86_64 Darwin_arm64"

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

detect_platform() {
platform="$(uname -s | tr '[:upper:]' '[:lower:]')"
platform="$(uname -s)"
case "${platform}" in
linux) platform="linux" ;;
darwin) platform="darwin" ;;
msys*|mingw*) platform="windows" ;;
Linux*) platform="Linux" ;;
Darwin*) platform="Darwin" ;;
MINGW*|MSYS*|CYGWIN*) platform="Windows" ;;
*)
error "Unsupported platform: ${platform}"
exit 1
Expand All @@ -56,7 +56,7 @@ detect_platform() {
detect_arch() {
arch="$(uname -m)"
case "${arch}" in
x86_64) arch="amd64" ;;
x86_64) arch="x86_64" ;;
aarch64|arm64) arch="arm64" ;;
*)
error "Unsupported architecture: ${arch}"
Expand All @@ -73,7 +73,11 @@ download_and_install() {

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

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

info "Verifying downloaded file..."
if ! file "${filename}" | grep -q "gzip compressed data"; then
error "Downloaded file is not in gzip format. Installation failed."
error "File type:"
file "${filename}"
rm -f "${filename}"
exit 1
if [ "${platform}" = "Windows" ]; then
if ! file "${filename}" | grep -q "Zip archive data"; then
error "Downloaded file is not in zip format. Installation failed."
error "File type:"
file "${filename}"
rm -f "${filename}"
exit 1
fi
else
if ! file "${filename}" | grep -q "gzip compressed data"; then
error "Downloaded file is not in gzip format. Installation failed."
error "File type:"
file "${filename}"
rm -f "${filename}"
exit 1
fi
fi

info "Extracting ${filename}..."
if ! tar -xzvf "${filename}"; then
error "Failed to extract ${filename}"
rm -f "${filename}"
exit 1
extract_dir="doggo_extract"
mkdir -p "${extract_dir}"
if [ "${platform}" = "Windows" ]; then
if ! unzip -q "${filename}" -d "${extract_dir}"; then
error "Failed to extract ${filename}"
rm -rf "${filename}" "${extract_dir}"
exit 1
fi
else
if ! tar -xzvf "${filename}" -C "${extract_dir}"; then
error "Failed to extract ${filename}"
rm -rf "${filename}" "${extract_dir}"
exit 1
fi
fi

info "Installing doggo..."
if [ ! -f "doggo" ]; then
error "doggo binary not found in the extracted files"
binary_name="doggo"
if [ "${platform}" = "Windows" ]; then
binary_name="doggo.exe"
fi

# Find the doggo binary in the extracted directory
binary_path=$(find "${extract_dir}" -name "${binary_name}" -type f)

if [ -z "${binary_path}" ]; then
error "${binary_name} not found in the extracted files"
error "Extracted files:"
ls -la
rm -f "${filename}"
ls -R "${extract_dir}"
rm -rf "${filename}" "${extract_dir}"
exit 1
fi

chmod +x doggo
if ! sudo mv doggo /usr/local/bin/; then
chmod +x "${binary_path}"
if ! sudo mv "${binary_path}" /usr/local/bin/doggo; then
error "Failed to move doggo to /usr/local/bin/"
rm -f "${filename}" "doggo"
rm -rf "${filename}" "${extract_dir}"
exit 1
fi

info "Cleaning up..."
rm -f "${filename}"
rm -rf "${filename}" "${extract_dir}"

completed "doggo ${version} has been installed to /usr/local/bin/doggo"
}
Expand Down

0 comments on commit a01e451

Please sign in to comment.