From f87eb0b2c74e42ea72324392380f28c5047477a1 Mon Sep 17 00:00:00 2001 From: Varun Guleria <152203177+varunguleriaCodes@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:19:45 +0530 Subject: [PATCH] feat: lodestar script setup (#7254) * feat: lodestar_setup * feat: script_updates + docs * feat: script_addition_in_docs + command_update * Remove duplicate script from docs folder * Minor script updates * Update script to prepare docs and ignore copied file * Update installation page * Wording --------- Co-authored-by: Nico Flaig --- .gitignore | 1 + .../pages/run/getting-started/installation.md | 6 ++ scripts/install-binary.sh | 91 +++++++++++++++++++ scripts/prepare-docs.sh | 3 + 4 files changed, 101 insertions(+) create mode 100755 scripts/install-binary.sh diff --git a/.gitignore b/.gitignore index 52d9bc66e5b6..e54f7440864d 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,7 @@ docs/pages/libraries/lightclient-prover/lightclient.md docs/pages/libraries/lightclient-prover/prover.md docs/pages/api/api-reference.md docs/pages/contribution/getting-started.md +docs/static/install ## Docusaurus docs/.docusaurus/ docs/build/ diff --git a/docs/pages/run/getting-started/installation.md b/docs/pages/run/getting-started/installation.md index 40c4865f7726..b2b4003f90a5 100644 --- a/docs/pages/run/getting-started/installation.md +++ b/docs/pages/run/getting-started/installation.md @@ -4,6 +4,12 @@ Binaries can be downloaded from the Lodestar [release page](https://github.com/ChainSafe/lodestar/releases/latest) under the `Assets` section. +Run the following command to install the latest version + +```bash +curl -fsSL https://chainsafe.github.io/lodestar/install | bash +``` + ## Docker Installation The [`chainsafe/lodestar`](https://hub.docker.com/r/chainsafe/lodestar) Docker Hub repository is maintained actively. It contains the `lodestar` CLI preinstalled. diff --git a/scripts/install-binary.sh b/scripts/install-binary.sh new file mode 100755 index 000000000000..f6db9948eeda --- /dev/null +++ b/scripts/install-binary.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +# ASCII art +echo " _ _ _ " +echo " | | | | | | " +echo " | | ___ __| | ___ ___| |_ __ _ _ __ " +echo " | |/ _ \ / _ |/ _ \/ __| __/ _ | __|" +echo " | | (_) | (_| | __/\__ \ || (_| | | " +echo " |_|\___/ \__ _|\___||___/\__\__ _|_| " +echo "" + +# Declare directories +TEMP_DIR=$(mktemp -d) +LOCAL_BIN="$HOME/.local/bin" + +# Ensure ~/.local/bin exists +mkdir -p "$LOCAL_BIN" + +# Inform the user about temporary directory usage +echo "Using temporary directory: $TEMP_DIR" + +# Fetch the latest release tag from GitHub +echo "Fetching the latest version information..." +VERSION=$(curl -s "https://api.github.com/repos/ChainSafe/lodestar/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + +# Check if VERSION is empty +if [ -z "$VERSION" ]; then + echo "Failed to fetch the latest version. Exiting." + exit 1 +fi + +echo "Latest version detected: $VERSION" + +# Detect the operating system and architecture +OS=$(uname -s) +ARCH=$(uname -m) + +# Translate architecture to expected format +case $ARCH in + x86_64) ARCH="amd64" ;; + aarch64|arm64) ARCH="arm64" ;; + *) + echo "Unsupported architecture: $ARCH. Exiting." + exit 1 + ;; +esac + +# Translate OS to expected format +case $OS in + Linux) PLATFORM="linux-$ARCH" ;; + *) + echo "Unsupported operating system: $OS. Exiting." + exit 1 + ;; +esac + +# Construct the download URL +URL="https://github.com/ChainSafe/lodestar/releases/download/$VERSION/lodestar-$VERSION-$PLATFORM.tar.gz" +echo "Downloading from: $URL" + +# Download the tarball +if ! wget "$URL" -O "$TEMP_DIR/lodestar-$VERSION-$PLATFORM.tar.gz"; then + echo "Download failed. Exiting." + exit 1 +fi + +# Extract the tarball +echo "Extracting the binary..." +if ! tar -xzf "$TEMP_DIR/lodestar-$VERSION-$PLATFORM.tar.gz" -C "$TEMP_DIR"; then + echo "Extraction failed. Exiting." + exit 1 +fi + +# Move the binary to ~/.local/bin +echo "Moving the binary to $LOCAL_BIN..." +mv "$TEMP_DIR/lodestar" "$LOCAL_BIN/" +chmod +x "$LOCAL_BIN/lodestar" + +# Verify if ~/.local/bin is in PATH +if [[ ":$PATH:" != *":$LOCAL_BIN:"* ]]; then + echo "Adding $LOCAL_BIN to PATH..." + echo 'export PATH="$PATH:$HOME/.local/bin"' >> "$HOME/.bashrc" + echo "Run 'source ~/.bashrc' to apply changes to your shell." +fi + +# Clean up the temporary directory +rm -rf "$TEMP_DIR" + +# Inform the user of successful installation +echo "Installation complete!" +echo "Run 'lodestar --help' to get started." diff --git a/scripts/prepare-docs.sh b/scripts/prepare-docs.sh index d2bac519a7f2..2fa16a7cc759 100755 --- a/scripts/prepare-docs.sh +++ b/scripts/prepare-docs.sh @@ -17,3 +17,6 @@ cp -r packages/prover/README.md $DOCS_DIR/pages/libraries/lightclient-prover/pro # Copy visual assets rm -rf $DOCS_DIR/pages/assets $DOCS_DIR/pages/images cp -r $ASSETS_DIR $DOCS_DIR/pages/assets + +# Copy binary install script to docs +cp scripts/install-binary.sh $DOCS_DIR/static/install