How to Upgrade znnd to v0.0.8 with the HC1 Binary

I’ve put together a Bash script to simplify updating the znnd binary for the go-zenon service on Linux systems. This script automates downloading the latest binary, verifying its integrity, stopping the service, updating the binary, and restarting the service. Here’s a step-by-step guide on how to use it.

What the Script Does

  • Ensures the script is run as root (required for service management and file operations).
  • Removes any existing temporary file to avoid conflicts.
  • Downloads the znnd-linux-amd64.tar.gz binary (version 0.0.8-private) from the HC1 repo
  • Verifies the downloaded file’s SHA-256 checksum for security.
  • Stops the go-zenon service.
  • Extracts the binary and renames it from znnd-linux-amd64 to znnd.
  • Installs the binary to /usr/local/bin/znnd, overwriting any existing file.
  • Sets executable permissions.
  • Restarts the go-zenon service.
  • Cleans up temporary files.

The Script

Save the following code to a file named update_znnd.sh:

#!/bin/bash

# Check if running as root
if [ "$EUID" -ne 0 ]; then
    echo "This script must be run as root"
    exit 1
fi

# Define expected checksum
EXPECTED_CHECKSUM="4bee99d2f69b71e22f5b29bc6d1866f9672bbe002487209447306c518ee8336b"
DOWNLOAD_URL="https://github.com/hypercore-one/go-zenon/releases/download/v0.0.8-private/znnd-linux-amd64.tar.gz"
TEMP_FILE="/tmp/znnd-linux-amd64.tar.gz"

# Log memory usage before any operations
echo "Initial memory usage:"
free -h

# Remove existing file if it exists
if [ -f "$TEMP_FILE" ]; then
    echo "Removing existing file at $TEMP_FILE"
    rm "$TEMP_FILE"
fi

# Download the binary
echo "Downloading znnd binary..."
wget -O "$TEMP_FILE" "$DOWNLOAD_URL"

# Check if download was successful
if [ $? -ne 0 ]; then
    echo "Failed to download binary"
    exit 1
fi

# Verify checksum
echo "Verifying checksum..."
COMPUTED_CHECKSUM=$(sha256sum "$TEMP_FILE" | cut -d ' ' -f 1)
if [ "$COMPUTED_CHECKSUM" != "$EXPECTED_CHECKSUM" ]; then
    echo "Checksum verification failed!"
    echo "Expected: $EXPECTED_CHECKSUM"
    echo "Got: $COMPUTED_CHECKSUM"
    rm "$TEMP_FILE"
    exit 1
fi
echo "Checksum verified successfully"

# Check if go-zenon service is running
echo "Checking go-zenon service status..."
if ! systemctl is-active --quiet go-zenon; then
    echo "go-zenon service is not running, no need to stop"
else
    # Log memory usage before stopping service
    echo "Memory usage before stopping go-zenon service:"
    free -h

    # Stop go-zenon service
    echo "Stopping go-zenon service..."
    systemctl stop go-zenon

    # Wait 10 seconds for the service to stop
    echo "Waiting 10 seconds for go-zenon service to stop..."
    sleep 10

    # Check if the service is stopped
    if systemctl is-active --quiet go-zenon; then
        echo "go-zenon service still running, attempting to forcefully kill..."
        systemctl kill go-zenon
        sleep 2
        if systemctl is-active --quiet go-zenon; then
            echo "systemctl kill failed, attempting manual kill of znnd process..."
            pkill -f znnd
            sleep 2
            if pgrep -f znnd > /dev/null; then
                echo "Error: Failed to stop go-zenon service or znnd process"
                exit 1
            fi
        fi
    fi
    echo "go-zenon service stopped successfully"
fi

# Inspect archive contents
echo "Archive contents:"
tar -tzf "$TEMP_FILE"

# Extract binary to /tmp/
echo "Extracting binary..."
tar -xzf "$TEMP_FILE" -C /tmp/

# Check if the expected binary exists
if [ ! -f "/tmp/znnd-linux-amd64" ]; then
    echo "Error: znnd-linux-amd64 binary not found in archive"
    exit 1
fi

# Move and rename the binary to /usr/local/bin/znnd with overwrite
mv -f /tmp/znnd-linux-amd64 /usr/local/bin/znnd

# Check if move was successful
if [ $? -ne 0 ]; then
    echo "Failed to move binary to /usr/local/bin/"
    exit 1
fi

# Set proper permissions
chmod +x /usr/local/bin/znnd

# Start go-zenon service
echo "Starting go-zenon service..."
systemctl start go-zenon

# Check if service started successfully
if [ $? -ne 0 ]; then
    echo "Failed to start go-zenon service"
    exit 1
fi

# Clean up
rm "$TEMP_FILE"

echo "Update completed successfully"

How to Use the Script

  1. Save the Script:
  • Copy the code above into a text editor.
  • Save it as update_znnd.sh in a convenient location (e.g., ~/update_znnd.sh).
  1. Make the Script Executable:
  • Open a terminal and run:
chmod +x update_znnd.sh
  1. Run the Script as Root:
  • Execute the script with sudo:
sudo ./update_znnd.sh
  • The script will provide output at each step, including download progress, checksum verification, and service status.
  1. Check the Output:
  • If successful, you’ll see: Update completed successfully.
  • If there are errors (e.g., checksum mismatch, download failure, or service issues), the script will exit with a descriptive error message.
1 Like

Simplified Step-by-Step Guide to Upgrade znnd to v0.0.8 on Your Pillar (Using a Mac)

This guide will help you update znnd on your Pillar to version 0.0.8 using your Mac. You’ll use the Terminal app to connect to the pillar and run commands. Follow each step carefully.


Step 1: Open the Terminal App

  1. Click the magnifying glass (Spotlight Search) in the top-right corner of your Mac’s screen.

  2. Type Terminal and press Enter. A window with a black background and white text will open. This is the Terminal.


Step 2: Connect to Your Pillar Using SSH

  1. You need the IP address or hostname of your pillar (e.g., 192.168.1.100 or yourpillar.example.com) and your login details (username and password).

  2. In the Terminal, type the following command, replacing username with your pillar’s username and your.pillar.ip with your pillar’s IP address or hostname, then press Enter:

ssh username@your.pillar.ip

Example: If your username is admin and your pillar’s IP is 192.168.1.100, type:

ssh admin@192.168.1.100
  1. If prompted with a message like “Are you sure you want to continue connecting?”, type yes and press Enter.

  2. Enter your password when prompted. Note: You won’t see the password as you type. Press Enter after typing it.

  3. If successful, the Terminal will show a new prompt, indicating you’re connected to the pillar.


Step 3: Download the Update Script

  1. Download the script file by typing this command exactly as shown and pressing Enter:
curl -o update_znnd.sh https://gist.githubusercontent.com/0x3639/55adce44326c6acaa384bcabac8705ef/raw/31fd6e73b171d95252e2392e8c47869bcc53503f/update_znnd.sh

This downloads a file called update_znnd.sh to your pillar.


Step 4: Make the Script Executable

  1. To allow the script to run, type this command and press Enter:
chmod +x update_znnd.sh

Step 5: Stop the go-zenon Service

  1. Stop the running go-zenon service by typing this command and pressing Enter:
sudo systemctl stop go-zenon

Step 6: Run the Update Script

  1. Run the script by typing this command and pressing Enter:
sudo ./update_znnd.sh

The script will:

  • Download the new version of znnd (0.0.8).
  • Replace the old znnd with the new one.
  • Restart the service.
  1. Wait for the script to finish. It may take a minute or two. You’ll see messages in the Terminal as it works. When it’s done, you’ll return to the Terminal prompt.

Troubleshooting

  • If SSH fails:

    • Double-check the IP address/hostname and username.
    • Ensure you have the correct password.
    • If you see “connection refused,” the pillar might not be reachable. Ask for help.
  • If systemctl stop go-zenon fails:

    • Ensure you used sudo if needed (sudo systemctl stop go-zenon).
    • If it says “service not found,” the service might have a different name. Ask for help.
  • If the script fails:

    • Try running it again (sudo ./update_znnd.sh).
    • Copy any error messages and share below.
  • To check if the update worked:

    • Type znnd --version and press Enter. You should see znnd version 0.0.8.