From a766dc2a5aceaa2aca39885406e8d95ad7df8723 Mon Sep 17 00:00:00 2001 From: Mohammed Mushahid Qureshi Date: Wed, 16 Oct 2024 10:09:47 +0530 Subject: [PATCH] Issue 384 fix cli script (#391) * fixes #384 - fix for web cli installation script error * Added verbose messages * Update filename for newer versions and fix incorrect variable in clean_up_temp Update filename for newer versions and fix incorrect variable in clean_up_temp * Fix directory exist check * Update crates/web5_cli/install.sh - fix in bin directory check Co-authored-by: nitro-neal <5314059+nitro-neal@users.noreply.github.com> --------- Co-authored-by: nitro-neal <5314059+nitro-neal@users.noreply.github.com> --- crates/web5_cli/install.sh | 44 ++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/crates/web5_cli/install.sh b/crates/web5_cli/install.sh index 457bd3b6..553ba42c 100755 --- a/crates/web5_cli/install.sh +++ b/crates/web5_cli/install.sh @@ -1,5 +1,12 @@ #!/bin/bash +# Clean up files in case of error +clean_up_temp () { + [[ -f "/tmp/$FILENAME" ]] && rm -f "/tmp/$FILENAME" +} + +trap clean_up_temp EXIT + if [ -z "$1" ]; then echo "Usage: $0 " exit 1 @@ -11,15 +18,32 @@ ARCH=$(uname -m) case $OS in "linux") + echo "Operating System - Architecture: Linux - $ARCH" case $ARCH in - "x86_64") FILENAME="web5-x86_64-linux-gnu" ;; + "x86_64") + if [[ "$VERSION" == "v0.0.2" || "$VERSION" == "v0.0.3" || "$VERSION" == "v0.0.4" ]]; then + FILENAME="web5-x86_64-linux-gnu.zip" + else + FILENAME="web5_cli-x86_64-unknown-linux-gnu" + fi;; *) echo "Unsupported architecture: $ARCH"; exit 1 ;; esac ;; "darwin") + echo "Operating System - Architecture: macOS - $ARCH" case $ARCH in - "x86_64") FILENAME="web5-x86_64-apple-darwin" ;; - "arm64") FILENAME="web5-aarch64-apple-darwin" ;; + "x86_64") + if [[ "$VERSION" == "v0.0.2" || "$VERSION" == "v0.0.3" || "$VERSION" == "v0.0.4" ]]; then + FILENAME="web5-x86_64-apple-darwin.zip" + else + FILENAME="web5_cli-x86_64-apple-darwin" + fi;; + "arm64") + if [[ "$VERSION" == "v0.0.2" || "$VERSION" == "v0.0.3" || "$VERSION" == "v0.0.4" ]]; then + FILENAME="web5-aarch64-apple-darwin.zip" + else + FILENAME="web5_cli-aarch64-apple-darwin" + fi;; *) echo "Unsupported architecture: $ARCH"; exit 1 ;; esac ;; @@ -28,12 +52,24 @@ case $OS in esac # Download -curl -L -o /tmp/$FILENAME https://github.com/TBD54566975/web5-rs/releases/download/$VERSION/$FILENAME +echo "Downloading $FILENAME" +curl -L -f -o /tmp/$FILENAME https://github.com/TBD54566975/web5-rs/releases/download/$VERSION/$FILENAME + +# Check download errors +if [ $? -ne 0 ] ; then + echo "Error while downloading $FILENAME" + echo "Exiting..." + exit 1 +fi # give it executable permissions chmod +x /tmp/$FILENAME # Move the executable to /usr/local/bin +if [ ! -d "/usr/local/bin" ]; then + echo "Creating /usr/local/bin" + mkdir -p /usr/local/bin +fi sudo mv /tmp/$FILENAME /usr/local/bin/web5 # Cleanup