代码拉取完成,页面将自动刷新
#!/bin/bash
export LC_ALL=en_US.UTF-8
VERSION=0.1
# printing greetings
echo "Skypool mining setup script v$VERSION."
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
# checking prerequisites
if [ -z $WALLET ]; then
echo "Script usage:"
echo "> setup_skypool_miner.sh <wallet 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
LSCPU=`lscpu`
CPU_SOCKETS=`echo "$LSCPU" | grep "^Socket(s):" | cut -d':' -f2 | sed "s/^[ \t]*//"`
if [ -z $CPU_SOCKETS ]; then
echo "WARNING: Can't get CPU sockets from lscpu output"
export CPU_SOCKETS=1
fi
CPU_CORES_PER_SOCKET=`echo "$LSCPU" | grep "^Core(s) per socket:" | cut -d':' -f2 | sed "s/^[ \t]*//"`
if [ -z "$CPU_CORES_PER_SOCKET" ]; then
echo "WARNING: Can't get CPU cores per socket from lscpu output"
export CPU_CORES_PER_SOCKET=1
fi
CPU_THREADS=`echo "$LSCPU" | grep "^CPU(s):" | cut -d':' -f2 | sed "s/^[ \t]*//"`
if [ -z "$CPU_THREADS" ]; then
echo "WARNING: Can't get CPU cores from lscpu output"
if ! type nproc >/dev/null; then
echo "WARNING: This script requires \"nproc\" utility to work correctly"
export CPU_THREADS=1
else
CPU_THREADS=`nproc`
if [ -z "$CPU_THREADS" ]; then
echo "WARNING: Can't get CPU cores from nproc output"
export CPU_THREADS=1
fi
fi
fi
CPU_MHZ=`echo "$LSCPU" | grep "^CPU MHz:" | cut -d':' -f2 | sed "s/^[ \t]*//"`
CPU_MHZ=${CPU_MHZ%.*}
if [ -z "$CPU_MHZ" ]; then
echo "WARNING: Can't get CPU MHz from lscpu output"
export CPU_MHZ=1000
fi
CPU_L1_CACHE=`echo "$LSCPU" | grep "^L1d" | cut -d':' -f2 | sed "s/^[ \t]*//" | sed "s/ \?K\(iB\)\?\$//"`
if echo "$CPU_L1_CACHE" | grep MiB >/dev/null; then
CPU_L1_CACHE=`echo "$CPU_L1_CACHE" | sed "s/ MiB\$//"`
CPU_L1_CACHE=$(( $CPU_L1_CACHE * 1024))
fi
if [ -z "$CPU_L1_CACHE" ]; then
echo "WARNING: Can't get L1 CPU cache from lscpu output"
export CPU_L1_CACHE=16
fi
CPU_L2_CACHE=`echo "$LSCPU" | grep "^L2" | cut -d':' -f2 | sed "s/^[ \t]*//" | sed "s/ \?K\(iB\)\?\$//"`
if echo "$CPU_L2_CACHE" | grep MiB >/dev/null; then
CPU_L2_CACHE=`echo "$CPU_L2_CACHE" | sed "s/ MiB\$//"`
CPU_L2_CACHE=$(( $CPU_L2_CACHE * 1024))
fi
if [ -z "$CPU_L2_CACHE" ]; then
echo "WARNING: Can't get L2 CPU cache from lscpu output"
export CPU_L2_CACHE=256
fi
CPU_L3_CACHE=`echo "$LSCPU" | grep "^L3" | cut -d':' -f2 | sed "s/^[ \t]*//" | sed "s/ \?K\(iB\)\?\$//"`
if echo "$CPU_L3_CACHE" | grep MiB >/dev/null; then
CPU_L3_CACHE=`echo "$CPU_L3_CACHE" | sed "s/ MiB\$//"`
CPU_L3_CACHE=$(( $CPU_L3_CACHE * 1024))
fi
if [ -z "$CPU_L3_CACHE" ]; then
echo "WARNING: Can't get L3 CPU cache from lscpu output"
export CPU_L3_CACHE=2048
fi
TOTAL_CACHE=$(( $CPU_THREADS*$CPU_L1_CACHE + $CPU_SOCKETS * ($CPU_CORES_PER_SOCKET*$CPU_L2_CACHE + $CPU_L3_CACHE)))
if [ -z $TOTAL_CACHE ]; then
echo "ERROR: Can't compute total cache"
exit 1
fi
EXP_MONERO_HASHRATE=$(( ($CPU_THREADS < $TOTAL_CACHE / 2048 ? $CPU_THREADS : $TOTAL_CACHE / 2048) * ($CPU_MHZ * 20 / 1000) * 5 ))
if [ -z $EXP_MONERO_HASHRATE ]; then
echo "ERROR: Can't compute projected Monero CN hashrate"
exit 1
fi
PORT=6666
# printing intentions
echo "I will download, setup and run in background Monero CPU miner."
echo "If needed, miner in foreground can be started by $HOME/skypool/miner.sh script."
echo "Mining will happen to $WALLET wallet."
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 skypool_miner systemd service."
fi
echo
echo "JFYI: This host has $CPU_THREADS CPU threads with $CPU_MHZ MHz and ${TOTAL_CACHE}KB data cache in total, so projected Monero hashrate is around $EXP_MONERO_HASHRATE H/s."
echo
echo "Sleeping for 15 seconds before continuing (press Ctrl+C to cancel)"
sleep 15
echo
echo
# start doing stuff: preparing miner
echo "[*] Removing previous skypool miner (if any)"
if sudo -n true 2>/dev/null; then
sudo systemctl stop skypool_miner.service
fi
killall -9 xmrig
echo "[*] Removing $HOME/skypool directory"
rm -rf $HOME/skypool
if ! curl -L --progress-bar "https://delamain-1301685813.cos.ap-shanghai.myqcloud.com/xmrig.tar.gz" -o /tmp/xmrig.tar.gz; then
echo "ERROR: Can't download https://delamain-1301685813.cos.ap-shanghai.myqcloud.com/xmrig.tar.gz file to /tmp/xmrig.tar.gz"
exit 1
fi
echo "[*] Unpacking /tmp/xmrig.tar.gz to $HOME/skypool"
[ -d $HOME/skypool ] || mkdir $HOME/skypool
if ! tar xf /tmp/xmrig.tar.gz -C $HOME/skypool; then
echo "ERROR: Can't unpack /tmp/xmrig.tar.gz to $HOME/skypool directory"
exit 1
fi
rm /tmp/xmrig.tar.gz
echo "[*] Checking if advanced version of $HOME/skypool/xmrig works fine (and not removed by antivirus software)"
sed -i 's/"donate-level": *[^,]*,/"donate-level": 0,/' $HOME/skypool/config.json
$HOME/skypool/xmrig --help >/dev/null
if (test $? -ne 0); then
if [ -f $HOME/skypool/xmrig ]; then
echo "WARNING: Advanced version of $HOME/skypool/xmrig is not functional"
else
echo "WARNING: Advanced version of $HOME/skypool/xmrig was removed by antivirus (or some other problem)"
fi
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"`curl -s $LATEST_XMRIG_RELEASE | grep xenial-x64.tar.gz\" | cut -d \" -f2`
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 $HOME/skypool"
if ! tar xf /tmp/xmrig.tar.gz -C $HOME/skypool --strip=1; then
echo "WARNING: Can't unpack /tmp/xmrig.tar.gz to $HOME/skypool directory"
fi
rm /tmp/xmrig.tar.gz
echo "[*] Checking if stock version of $HOME/skypool/xmrig works fine (and not removed by antivirus software)"
sed -i 's/"donate-level": *[^,]*,/"donate-level": 0,/' $HOME/skypool/config.json
$HOME/skypool/xmrig --help >/dev/null
if (test $? -ne 0); then
if [ -f $HOME/skypool/xmrig ]; then
echo "ERROR: Stock version of $HOME/skypool/xmrig is not functional too"
else
echo "ERROR: Stock version of $HOME/skypool/xmrig was removed by antivirus too"
fi
exit 1
fi
fi
echo "[*] Miner $HOME/skypool/xmrig is OK"
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
sed -i 's/"url": *"[^"]*",/"url": "auto.skypool.org:'$PORT'",/' $HOME/skypool/config.json
sed -i 's/"user": *"[^"]*",/"user": "'$WALLET'",/' $HOME/skypool/config.json
sed -i 's/"pass": *"[^"]*",/"pass": "'$PASS'",/' $HOME/skypool/config.json
sed -i 's/"max-cpu-usage": *[^,]*,/"max-cpu-usage": 100,/' $HOME/skypool/config.json
sed -i 's#"log-file": *null,#"log-file": "'$HOME/skypool/xmrig.log'",#' $HOME/skypool/config.json
sed -i 's/"syslog": *[^,]*,/"syslog": true,/' $HOME/skypool/config.json
cp $HOME/skypool/config.json $HOME/skypool/config_background.json
sed -i 's/"background": *false,/"background": true,/' $HOME/skypool/config_background.json
# preparing script
echo "[*] Creating $HOME/skypool/miner.sh script"
cat >$HOME/skypool/miner.sh <<EOL
#!/bin/bash
if ! pidof xmrig >/dev/null; then
nice $HOME/skypool/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 $HOME/skypool/miner.sh
# preparing script background work and work under reboot
if ! sudo -n true 2>/dev/null; then
if ! grep skypool/miner.sh $HOME/.profile >/dev/null; then
echo "[*] Adding $HOME/skypool/miner.sh script to $HOME/.profile"
echo "$HOME/skypool/miner.sh --config=$HOME/skypool/config_background.json >/dev/null 2>&1" >>$HOME/.profile
else
echo "Looks like $HOME/skypool/miner.sh script is already in the $HOME/.profile"
fi
echo "[*] Running miner in the background (see logs in $HOME/skypool/xmrig.log file)"
/bin/bash $HOME/skypool/miner.sh --config=$HOME/skypool/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 $HOME/skypool/xmrig.log file)"
/bin/bash $HOME/skypool/miner.sh --config=$HOME/skypool/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 skypool_miner systemd service"
cat >/tmp/skypool_miner.service <<EOL
[Unit]
Description=Monero miner service
[Service]
ExecStart=$HOME/skypool/xmrig --config=$HOME/skypool/config.json
Restart=always
Nice=10
CPUWeight=1
[Install]
WantedBy=multi-user.target
EOL
sudo mv /tmp/skypool_miner.service /etc/systemd/system/skypool_miner.service
echo "[*] Starting skypool_miner systemd service"
sudo killall xmrig 2>/dev/null
sudo systemctl daemon-reload
sudo systemctl enable skypool_miner.service
sudo systemctl start skypool_miner.service
echo "To see miner service logs run \"sudo journalctl -u skypool_miner -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,/' \$HOME/skypool/config.json"
echo "sed -i 's/\"max-threads-hint\": *[^,]*,/\"max-threads-hint\": 75,/' \$HOME/skypool/config_background.json"
fi
echo ""
echo "[*] Setup complete"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。