DevilXD / TwitchDropsMiner

An app that allows you to AFK mine timed Twitch drops, with automatic drop claiming and channel switching.
MIT License
1.73k stars 170 forks source link

Potential wiki entry? - Guide for successful setup on the Raspberry Pi 5(+) #588

Open 28Black opened 1 month ago

28Black commented 1 month ago

This guide is intended to help (new) users find all the information in one place, to get the miner running on their Raspberry Pi 5 (with Raspberry Pi OS).

Background:

I recently received a Raspberry Pi 5 and tried to realize various projects on it. Unfortunately, I am still a newcomer to the Linux ecosystem, which is why I had problems getting the Twitch Drops Miner to work. Especially because the display server and thus the entire PI hung up during execution (as discussed here and described by @TeddJohnson here).

That's why I decided to create a short beginner-friendly step-by-step tutorial based on the information and experience I've gathered to help others facing this or similar problems.

Note:

  1. I am neither a developer nor do I have in-depth experience with Linux and/or bash scripting. Therefore, suggestions for improvement are welcome and appreciated.
  2. If you are an experienced user, here is the “simple solution” for you: change the display server on your Pi (5 and newer) from Wayland (Wayfire) to X11. Done!

Beginner-friendly step-by-step guide

Part 1: Basic setup (special thanks again to @TeddJohnson for his original post).

The navigation can of course also be done completely via the terminal (using cd), but for beginners or newcomers the navigation via the file browser, which is used here, might be easier.

  1. First, we make sure that the operating system is up-to-date. To do this, we use the two commands sudo apt update and sudo apt upgrade in the terminal and reboot if necessary.
  2. Install the packages required for the Drops Miner with sudo apt install libcairo2-dev libgirepository1.0-dev ttf-ancient-fonts-symbola
  3. Use the file manager to navigate to the area (/folder) where you want to save the Twitch Drops Miner. This could look like this: “/home/username/scripts/”, where 'username' stands for your current user name.
  4. Press F4 to open the terminal in this folder and clone the Twitch Drops Miner with the command git clone https://github.com/DevilXD/TwitchDropsMiner
  5. Now navigate to the newly created Drops Miner folder with the command cd /home/username/Scripts/TwitchDropsMiner
  6. To install the dependencies and not risk our system integrity, we create a virtual Python environment with the command python -m venv .env
  7. Activate the virtual environment with the command source .env/bin/activate.

    Note: This virtual environment must be started each time before the Twitch Drops Miner is executed. This can also be done automatically by executing a script, see below.

  8. Now we install the dependencies from the requirements.txt into this virtual environment with the command pip install -r requirements.txt

At this point, the Twitch Drops Miner would in principle be fully installed and ready for use and could be started with the command PYSTRAY_BACKEND=gtk python3 main.py. Well, unless you’re logged in with your Twitch account. To ensure that the system does not hang up after you log in, we need to take care of the display server. According to my research, there are various display servers, whereby X11 was used on older Raspberry models, but has since been replaced (on the Pi 5) by Wayland. Wayland seems to be more efficient and faster, but is still buggy here and there.

Part 2: Changing the display server

First, we check via the terminal with the command echo $XDG_SESSION_TYPE which display server is currently being used. If the output is 'X11', we do not need to do anything else. By default, however, 'Wayland' is set on the Pi 5, and we need to change it.

  1. Open the Raspberry Config with the command sudo raspi-config and navigate to point 6: 'Advanced Options'.
  2. Navigate to A6 'Wayland' and press Enter. By default, 'W2 Wayfire' is used here.
  3. Select 'W1 X11' and confirm with Enter.
  4. Restart your Raspberry.

Note: After the first restart, the system may feel a little slower for a short time - don't panic, it will settle!

Now, everything is set up and the Twitch Drops Miner should run properly on your Raspberry Pi 5(+)! So, navigate to your Twitch Drops Miner folder (for example /home/username/Scripts/TwitchDropsMiner/), press F4 to open the terminal here. Activate the virtual Python environment with source .env/bin/activate and start the miner PYSTRAY_BACKEND=gtk python3 main.py and set it up. Happy mining!

Addendum:

To make starting and maintaining the miner noticeably easier, I have created a simple but effective script.

Please note that you have to change the folder path for your own purposes!!

What does the script do? Quite simply: It takes care of the navigation and activates the virtual Python environment for us. It then downloads the latest changes of Twitch Drops Miner from github (using only fast-forward merges) and checks whether the requirements.txt has been changed. If so, it installs the new requirements for us. Then it asks us if we want to check for updates for the existing dependencies (yes or no) - this does not have to be done every time, but should be done regularly to stay up to date. After all this has been processed, the miner will finally be started and begin its work.

Script:

#!/bin/bash

echo "Going to the miner directory"
cd /home/username/Scripts/TwitchDropsMiner || exit 1

echo "Activating the virtual environment..."
source .env/bin/activate

echo "Checking for Twitch Drops Miner updates and install..."
# Save the current hash of the requirements.txt
OLD_REQUIREMENTS_HASH=$(md5sum requirements.txt)

# Use git pull with --ff-only to allow only fast-forward merges
git pull --ff-only || { echo "Fast-forward merge not possible. Please check your local changes."; exit 1; }

# Save the new hash of the requirements.txt
NEW_REQUIREMENTS_HASH=$(md5sum requirements.txt)

# Compare the hashes and only install if there are changes
if [ "$OLD_REQUIREMENTS_HASH" != "$NEW_REQUIREMENTS_HASH" ]; then
    echo "requirements.txt has changed. Installing dependencies..."
    pip install --quiet -r requirements.txt
else
    echo "requirements.txt unchanged. No new dependencies installed."
fi

# Ask user whether to check for updates
read -p "Do you want to check for dependency updates? (Yes/No): " choice
case "$choice" in 
  [Yy]* ) 
    echo "Checking and installing dependency updates..."
    # Use --upgrade and --quiet to show output only when something is updated
    pip install --upgrade --quiet -r requirements.txt
    ;;
  [Nn]* ) 
    echo "Skip installing dependency updates."
    ;;
  * ) 
    echo "Invalid input. Skip the installation of dependency updates."
    ;;
esac

echo "Starting the Twitch Drops Miner and begin..."
PYSTRAY_BACKEND=gtk python3 main.py

echo "The script has been executed. Miner will start now."

To use the script, save it to the location of your choice, as 'runminer.sh', for example. Don't forget to make the script executable! When you are in the file browser in the folder with the script, press F4 and enter 'chmod +x runminer.sh' in the terminal. It can then be executed without any problems. Again: I am not an expert. The script is probably neither particularly elegant nor “pretty”. But it fulfills its intended purpose. Feel free to use your own script, or modify and improve mine to your liking!

TeddJohnson commented 1 month ago

Looks good!

Following the thread in case anyone has issues and I could be of assistance