Skip to content

Instantly share code, notes, and snippets.

@zoonderkins
Created March 28, 2024 05:33
Show Gist options
  • Save zoonderkins/4e7503d257ab1e98e2bc6e9cc536cdd6 to your computer and use it in GitHub Desktop.
Save zoonderkins/4e7503d257ab1e98e2bc6e9cc536cdd6 to your computer and use it in GitHub Desktop.
xmrig-install-ubuntu-debian
#!/bin/bash
# GitHub user/repo
GITHUB_REPO="xmrig/xmrig"
# Use GitHub API to fetch the latest release information
LATEST_RELEASE_INFO=$(curl -s https://api.github.com/repos/$GITHUB_REPO/releases/latest)
# Parse version and tarball URL from the release information
XMRIG_VERSION=$(echo "$LATEST_RELEASE_INFO" | jq -r '.tag_name')
TARBALL_URL=$(echo "$LATEST_RELEASE_INFO" | jq -r '.assets[6].browser_download_url')
# Check if xmrig directory exists and prompt for confirmation before removing
if [ -d "xmrig" ]; then
read -p "xmrig directory exists. Remove it? [y/N]: " confirm
if [[ $confirm =~ ^[Yy]$ ]]; then
rm -rf xmrig
else
echo "Operation cancelled by user."
exit 1
fi
fi
# Download xmrig
echo "Downloading xmrig version $XMRIG_VERSION..."
wget -O xmrig.tar.gz "$TARBALL_URL"
# Extract the downloaded file and check if successful
echo "Extracting xmrig..."
tar xvf xmrig.tar.gz && rm xmrig.tar.gz
if [ $? -ne 0 ]; then
echo "Failed to extract xmrig. Exiting."
exit 1
fi
# Rename extracted directory to a generic name for ease of use
mv xmrig-${XMRIG_VERSION:1} xmrig
# Kill existing xmrig processes safely
pkill -f xmrig || echo "No xmrig process was running."
sleep 1
# Run xmrig.sh if exists
XMIRG_SCRIPT="/root/xmrig/xmrig.sh"
if [ -f "$XMIRG_SCRIPT" ]; then
echo "Running xmrig.sh..."
$XMIRG_SCRIPT
else
echo "xmrig.sh does not exist in the xmrig directory."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment