From 856cf30809250ad5f4ae6f13ee78510396994075 Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Mon, 1 Jul 2024 12:05:40 +0530 Subject: [PATCH] fix: install script --- .goreleaser.yml | 5 ++- install.sh | 82 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 2328c5f..04439bb 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,3 +1,5 @@ +version: 2 + env: - GO111MODULE=on - CGO_ENABLED=0 @@ -48,7 +50,8 @@ builds: archives: - id: cli - allow_different_binary_count: true + builds: + - cli format_overrides: - goos: windows format: zip diff --git a/install.sh b/install.sh index 55aa284..dce394b 100755 --- a/install.sh +++ b/install.sh @@ -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" | @@ -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 @@ -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}" @@ -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}..." @@ -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" }