Skip to content

Commit

Permalink
Issue 384 fix cli script (#391)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Co-authored-by: nitro-neal <[email protected]>
  • Loading branch information
mushahidq and nitro-neal authored Oct 16, 2024
1 parent 4193238 commit a766dc2
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions crates/web5_cli/install.sh
Original file line number Diff line number Diff line change
@@ -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 <version>"
exit 1
Expand All @@ -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
;;
Expand All @@ -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
Expand Down

0 comments on commit a766dc2

Please sign in to comment.