From 279d2dd5746d14107b2e4468de6a51f68d4dd999 Mon Sep 17 00:00:00 2001 From: Xabi Losada Date: Tue, 26 Nov 2024 11:36:35 +0700 Subject: [PATCH] feat: add install script --- .github/workflows/test_install.yml | 33 ++++++++++++++++ scripts/install.sh | 61 ++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 .github/workflows/test_install.yml create mode 100755 scripts/install.sh diff --git a/.github/workflows/test_install.yml b/.github/workflows/test_install.yml new file mode 100644 index 000000000..55ecc50d2 --- /dev/null +++ b/.github/workflows/test_install.yml @@ -0,0 +1,33 @@ +name: Test Install Script + +on: + push: + branches: + - xilosada/test-install-script + pull_request: + branches: + - xilosada/test-install-script + +jobs: + test-install: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + arch: [x86_64, aarch64] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + # Run the installation script + - name: Test installation script + run: | + curl -s https://raw.githubusercontent.com/calimero-network/core/xilosada\/test-install-script/scripts/install.sh | bash + + # Validate the binary installation + - name: Validate installation + run: | + which meroctl + meroctl --version diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 000000000..70bdec5f8 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e + +# Define version and repository +VERSION="v0.1.1" +REPO="calimero-network/core" +BINARY_NAME="meroctl" + +# Detect OS +OS=$(uname | tr '[:upper:]' '[:lower:]') + +# Detect Architecture +ARCH=$(uname -m) +case "$ARCH" in + "x86_64") ARCH="x86_64" ;; + "arm64" | "aarch64") ARCH="aarch64" ;; + *) + echo "Unsupported architecture: $ARCH." + exit 1 + ;; +esac + +# Determine platform +if [ "$OS" == "darwin" ]; then + PLATFORM="apple-darwin" +elif [ "$OS" == "linux" ]; then + PLATFORM="unknown-linux-gnu" +else + echo "Unsupported operating system: $OS." + exit 1 +fi + +# Construct download URL and tarball name +TARBALL_NAME="${BINARY_NAME}_${ARCH}-${PLATFORM}.tar.gz" +DOWNLOAD_URL="https://github.com/$REPO/releases/download/$VERSION/$TARBALL_NAME" + +# Download binary tarball +echo "Downloading $TARBALL_NAME from $DOWNLOAD_URL..." +curl -L -o "$TARBALL_NAME" "$DOWNLOAD_URL" + +# Extract tarball +echo "Extracting $TARBALL_NAME..." +tar -xzf "$TARBALL_NAME" + +# Make binary executable +chmod +x "$BINARY_NAME" + +# Move to /usr/local/bin (or another PATH directory) +INSTALL_DIR="/usr/local/bin" +if [ ! -w "$INSTALL_DIR" ]; then + echo "You need sudo permissions to install to $INSTALL_DIR" + sudo mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME" +else + mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME" +fi + +# Clean up tarball +rm "$TARBALL_NAME" + +echo "$BINARY_NAME installed successfully! Run '$BINARY_NAME' to get started."