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