From f1962e12e24097be79b8c3ead8e716448a79330c Mon Sep 17 00:00:00 2001 From: nohehf Date: Wed, 25 Sep 2024 15:02:38 +0200 Subject: [PATCH] feat: add install script --- install.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 install.sh diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..1e21d30 --- /dev/null +++ b/install.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# GitHub repository details +REPO="Escape-Technologies/cloudfinder" + +# Determine the latest version tag from GitHub API +LATEST_TAG=$(curl -s https://api.github.com/repos/$REPO/releases/latest | grep tag_name | cut -d '"' -f 4) + +# Check if the tag was found +if [ -z "$LATEST_TAG" ]; then + echo "Unable to find the latest release tag. Exiting." + exit 1 +fi + +# Remove the 'v' prefix to get the release version +LATEST_RELEASE=${LATEST_TAG#v} + +# Determine OS and ARCH +OS=$(uname | tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m) + +# Translate uname output to Go architecture naming convention +if [ "$ARCH" == "x86_64" ]; then + ARCH="amd64" +elif [ "$ARCH" == "arm64" ]; then + ARCH="arm64" +else + echo "Unsupported architecture: $ARCH" + exit 1 +fi + +# Define the filename based on the OS and architecture +FILENAME="cloudfinder_${LATEST_RELEASE}_${OS}_${ARCH}.tar.gz" +DOWNLOAD_URL="https://github.com/$REPO/releases/download/${LATEST_TAG}/${FILENAME}" + +# Download the tar.gz file +echo "Downloading $FILENAME from $DOWNLOAD_URL..." +curl -L -o "$FILENAME" "$DOWNLOAD_URL" + +# Check if the file was downloaded successfully +if [ ! -f "$FILENAME" ]; then + echo "Failed to download $FILENAME. Exiting." + exit 1 +fi + +# Extract cloudfinder bin from the tar.gz file +echo "Extracting $FILENAME..." +tar -xzvf "$FILENAME" cloudfinder + +# Check if the binary exists after extraction +if [ ! -f "cloudfinder" ]; then + echo "Extraction failed or binary not found. Exiting." + exit 1 +fi + +# Move the binary to /usr/local/bin for global access +echo "Installing cloudfinder to /usr/local/bin..." +sudo mv cloudfinder /usr/local/bin/ + +# Clean up +rm "$FILENAME" + +echo "cloudfinder ${LATEST_TAG} installed successfully!"