|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# ASCII art |
| 4 | +echo " _ _ _ " |
| 5 | +echo " | | | | | | " |
| 6 | +echo " | | ___ __| | ___ ___| |_ __ _ _ __ " |
| 7 | +echo " | |/ _ \ / _ |/ _ \/ __| __/ _ | __|" |
| 8 | +echo " | | (_) | (_| | __/\__ \ || (_| | | " |
| 9 | +echo " |_|\___/ \__ _|\___||___/\__\__ _|_| " |
| 10 | +echo "" |
| 11 | + |
| 12 | +# Declare directories |
| 13 | +TEMP_DIR=$(mktemp -d) |
| 14 | +LOCAL_BIN="$HOME/.local/bin" |
| 15 | + |
| 16 | +# Ensure ~/.local/bin exists |
| 17 | +mkdir -p "$LOCAL_BIN" |
| 18 | + |
| 19 | +# Inform the user about temporary directory usage |
| 20 | +echo "Using temporary directory: $TEMP_DIR" |
| 21 | + |
| 22 | +# Fetch the latest release tag from GitHub |
| 23 | +echo "Fetching the latest version information..." |
| 24 | +VERSION=$(curl -s "https://api.github.com/repos/ChainSafe/lodestar/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') |
| 25 | + |
| 26 | +# Check if VERSION is empty |
| 27 | +if [ -z "$VERSION" ]; then |
| 28 | + echo "Failed to fetch the latest version. Exiting." |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +echo "Latest version detected: $VERSION" |
| 33 | + |
| 34 | +# Detect the operating system and architecture |
| 35 | +OS=$(uname -s) |
| 36 | +ARCH=$(uname -m) |
| 37 | + |
| 38 | +# Translate architecture to expected format |
| 39 | +case $ARCH in |
| 40 | + x86_64) ARCH="amd64" ;; |
| 41 | + aarch64|arm64) ARCH="arm64" ;; |
| 42 | + *) |
| 43 | + echo "Unsupported architecture: $ARCH. Exiting." |
| 44 | + exit 1 |
| 45 | + ;; |
| 46 | +esac |
| 47 | + |
| 48 | +# Translate OS to expected format |
| 49 | +case $OS in |
| 50 | + Linux) PLATFORM="linux-$ARCH" ;; |
| 51 | + *) |
| 52 | + echo "Unsupported operating system: $OS. Exiting." |
| 53 | + exit 1 |
| 54 | + ;; |
| 55 | +esac |
| 56 | + |
| 57 | +# Construct the download URL |
| 58 | +URL="https://github.com/ChainSafe/lodestar/releases/download/$VERSION/lodestar-$VERSION-$PLATFORM.tar.gz" |
| 59 | +echo "Downloading from: $URL" |
| 60 | + |
| 61 | +# Download the tarball |
| 62 | +if ! wget "$URL" -O "$TEMP_DIR/lodestar-$VERSION-$PLATFORM.tar.gz"; then |
| 63 | + echo "Download failed. Exiting." |
| 64 | + exit 1 |
| 65 | +fi |
| 66 | + |
| 67 | +# Extract the tarball |
| 68 | +echo "Extracting the binary..." |
| 69 | +if ! tar -xzf "$TEMP_DIR/lodestar-$VERSION-$PLATFORM.tar.gz" -C "$TEMP_DIR"; then |
| 70 | + echo "Extraction failed. Exiting." |
| 71 | + exit 1 |
| 72 | +fi |
| 73 | + |
| 74 | +# Move the binary to ~/.local/bin |
| 75 | +echo "Moving the binary to $LOCAL_BIN..." |
| 76 | +mv "$TEMP_DIR/lodestar" "$LOCAL_BIN/" |
| 77 | +chmod +x "$LOCAL_BIN/lodestar" |
| 78 | + |
| 79 | +# Verify if ~/.local/bin is in PATH |
| 80 | +if [[ ":$PATH:" != *":$LOCAL_BIN:"* ]]; then |
| 81 | + echo "Adding $LOCAL_BIN to PATH..." |
| 82 | + echo 'export PATH="$PATH:$HOME/.local/bin"' >> "$HOME/.bashrc" |
| 83 | + echo "Run 'source ~/.bashrc' to apply changes to your shell." |
| 84 | +fi |
| 85 | + |
| 86 | +# Clean up the temporary directory |
| 87 | +rm -rf "$TEMP_DIR" |
| 88 | + |
| 89 | +# Inform the user of successful installation |
| 90 | +echo "Installation complete!" |
| 91 | +echo "Run 'lodestar --help' to get started." |
0 commit comments