git.iko.soy/xmrig-bash-scripts
on master help sign in
reoganise
commit94d6c657c9765e40fc307c24c4691446f8f18ec8 authorSean Wheller <sean@prepaidmeters.com> dateSat 10 Aug 2019, 17:27 (7 years ago) parent065c2e6
11 files changed+98−177
build.sh+1−10 config.sh+1−57 crontab.sh+1−12 depends.sh+1−9 functions.sh+8−20 install.sh+13−5 maintenance.sh+1−9 settings.sh+64−33 start.sh+5−11 stop.sh+1−11 update.sh+2
build.sh+1−10
@@ -1,12 +1,7 @@
11#!/bin/bash
22
3−echo "#################################"
4−echo " BUILD STARTING"
5−echo "#################################"
6−
73# Clone source
84if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
9− echo "Clone already exists"
105
116 # Change to clone directory
127 cd $_XMRIG_CLONE
@@ -20,7 +15,6 @@ if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
2015
2116 else
2217 # Switch to required branch
23− echo "Require: $_XMRIG_BRANCH Switching !!!"
2418 git checkout $_XMRIG_BRANCH
2519
2620 # Pull changes from source
@@ -31,7 +25,6 @@ if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
3125 fi
3226else
3327 # Clone the source
34− echo "Cloning source to $_WORK_DIR/$_XMRIG_CLONE"
3528 git clone $_XMRIG_REPO $_XMRIG_CLONE
3629
3730 # Change to clone directory
@@ -52,7 +45,5 @@ sudo cp $_XMRIG_BUILD_LOCATION/xmrig $_XMRIG_TARGET_LOCATION
5245
5346cd $_WORK_DIR
5447
55−echo "#################################"
56−echo " BUILD COMPLETE"
57−echo "#################################"
48+echo "BUILD COMPLETE"
5849
config.sh+1−57
@@ -1,62 +1,6 @@
11#!/bin/bash
22
3−_API_ID="null"
4−_API_WORKER_ID="$HOSTNAME"
5−
6−_AUTOSAVE="true"
7−
8−_BACKGROUND="false"
9−
10−_COLORS="true"
11−
12−_CPU_ENABLED="true"
13−_CPU_HUGE_PAGES="true"
14−_CPU_HW_AES="$_AES_NI"
15−_CPU_PRIORITY="null"
16−_CPU_ASM="true"
17−_CPU_CN="$_ENV_CPU_THREAD_AFFINITY"
18−
19−_CPU_CN_0="false"
20−_CPU_CN_LITE_0="false"
21−
22−_DONATE_LEVEL="5"
23−
24−_DONATE_OVER_PROXY="1"
25−
26−_HTTP_ENABLED="true"
27−_HTTP_HOST=$(hostname --all-ip-addresses | awk '{print $1}')
28−_HTTP_PORT="8080"
29−_HTTP_ACCESS_TOKEN="null"
30−_HTTP_RESTRICTED="false"
31−
32−_LOG_FILE="null"
33−
34−_POOLS_ALGO="cn/r"
35−_POOLS_URL="$_POOL_SERVER_URL:$_POOL_SERVER_PORT"
36−_POOLS_USER="$_RECEIVE_WALLET"
37−_POOLS_PASS="$HOSTNAME:$_EMAIL"
38−_POOLS_RIG_ID="$HOSTNAME"
39−_POOLS_NICEHASH="true"
40−_POOLS_KEEPALIVE="true"
41−_POOLS_ENABLED="true"
42−_POOLS_TLS="null"
43−_POOLS_TLS_FINDERPRINT="null"
44−_POOLS_DAEMON="false"
45−
46−_PRINT_TIME="30"
47−
48−_RETRIES="5"
49−_RETRIES_PAUSE="5"
50−
51−_SYSLOG="false"
52−
53−_USER_AGENT="null"
54−
55−_WATCH="true"
56−
57−_CONFIG_JSON=$(jo -p -B api=$(jo id=$_API_ID worker-id=$_API_WORKER_ID) autosave=$_AUTOSAVE background=$_BACKGROUND colors=$_COLORS cpu=$(jo enabled=$_CPU_ENABLED huge-pages=$_CPU_HUGE_PAGES hw-aes=$_CPU_HW_AES priority=$_CPU_PRIORITY asm=$_CPU_ASM cn=$(jo -a $_CPU_CN) cn/0=$_CPU_CN_0 cn-lite/0=$_CPU_CN_LITE_0) donate-level=$_DONATE_LEVEL donate-over-proxy=$_DONATE_OVER_PROXY http=$(jo enabled=$_HTTP_ENABLED host=$_HTTP_HOST port=$_HTTP_PORT access-token=$_HTTP_ACCESS_TOKEN restricted=$_HTTP_RESTRICTED) logfile=$_LOGFILE pools=$(jo -a $(jo algo=$_POOLS_ALGO url=$_POOLS_URL user=$_POOLS_USER pass=$_POOLS_PASS rig-id=$_POOLS_RIG_ID nicehash=$_POOLS_NICEHASH keepalive=$_POOLS_KEEPALIVE enabled=$_POOLS_ENABLED tls=$_POOLS_TLS tls-fingerprint=$_POOLS_TLS_FINDERPRINT daemon=$_POOLS_DAEMON)) print-time=$_PRINT_TIME retries=$_RETRIES retry-pause=$_RETRIES_PAUSE syslog=$_SYSLOG user-agent=$_USER_AGENT watch=$_WATCH)
58−
593echo "$_CONFIG_JSON" | tee config.json
604
61−
5+echo "CONFIG CREATED"
626
crontab.sh+1−12
@@ -2,20 +2,12 @@
22
33# Set values in settings script
44
5−echo "#################################"
6−echo " UPDATING CRONTAB"
7−echo "#################################"
8−
9−
105# Remove existing crontab
11−echo "Backup existing crontab"
126crontab -l > crontab
137
14−echo "Removing exiting crontab"
158crontab -r
169
1710# Setup users contab
18−echo "Creating new crontab"
1911
2012crontab -l | { cat; echo "#Start at $_USER_TIMESTART on days $_USER_CRONDAYS
21130 $_USER_CRONSTART * * $_USER_CRONDAYS screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION"; } | crontab -
@@ -23,8 +15,5 @@ crontab -l | { cat; echo "#Start at $_USER_TIMESTART on days $_USER_CRONDAYS
2315crontab -l | { cat; echo "#Stop at $_USER_TIMESTOP on days $_USER_CRONDAYS
24160 $_USER_CRONSTOP * * $_USER_CRONDAYS screen -S $_XMRIG_SCREEN -X kill"; } | crontab -
2517
26−
27−echo "#################################"
28−echo " CRONTAB UPDATED"
29−echo "#################################"
18+echo "CRONTAB CREATED"
3019
depends.sh+1−9
@@ -1,7 +1,4 @@
11#!/bin/bash
2−echo "#################################"
3−echo " INSTALLING DEPENDENCIES "
4−echo "#################################"
52
63# Install the software requirements
74
@@ -12,12 +9,7 @@ if [ $_APT_DEPENDS = 1 ]; then
129
1310 # Install xmrig-bash-scripts depends
1411 sudo apt install -y jo cpuid screen
15−else
16−
17− echo "Depend install is set to NO ($_APT_DEPENDS) Skipping"
1812
1913fi
2014
21−echo "#################################"
22−echo " DEPENDENCIES INSTALLED "
23−echo "#################################"
15+echo "DEPENDENCIES INSTALLED"
functions.sh+8−20
@@ -1,30 +1,24 @@
1−#!/usr/bin/env bash
1+#!/bin/bash
22
33build_xmrig () {
44 if [ -d $_XMRIG_BUILD_LOCATION ]; then
55 # Remove existing build directory
6− echo "Found old build directory. Removing"
76 rm -rf $_XMRIG_BUILD_LOCATION
87
98 # Make new build directory
10− echo "Creating a build directory"
119 mkdir $_XMRIG_BUILD_LOCATION
1210 else
1311 # Make new build directory
14− echo "Creating a build directory"
1512 mkdir $_XMRIG_BUILD_LOCATION
1613 fi
1714
1815 # Change to build directory
19− echo "Changing to build directory"
2016 cd $_XMRIG_BUILD_LOCATION
2117
2218 # Configure cmake scafolding
23− echo "Configuring cmake scafolding"
2419 cmake .. -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7
2520
2621 # Compile the software
27− echo "Starting build"
2822 make
2923}
3024
@@ -50,11 +44,9 @@ check_cpu () {
5044
5145 # Get number of available CPU Cores
5246 _ENV_CORE=$(nproc --all)
53− echo -e "CPU Cores: $_ENV_CORE\n"
5447
5548 # Get CPU L3 cache value
5649 _ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
57− echo -e "L3 Cache in byte: $_ENV_CORE_L3\n"
5850}
5951
6052calc_threads () {
@@ -67,27 +59,23 @@ calc_threads () {
6759 _ENV_CPU_THREADS+=("$i")
6860 done
6961
70− echo "Thread CPU Affinity: ${_ENV_CPU_THREADS[@]}"
71− _ENV_CPU_THREAD_AFFINITY="${_ENV_CPU_THREADS[@]}"
62+ _ENV_CPU_THREAD_AFFINITY="$_ENV_CPU_THREADS"
7263
7364 # Setting according to cpu cores but xmrig will not use all
7465 # change to make value use _ENV_CORE_THREADS
7566 # Check that hugepages set in /etc/sysctl.conf
67+
7668 _ENV_CHECK="nr_hugepages"
7769
7870 if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
79− echo "Found nr_hugepages in /etc/sysctl.conf. All good!!"
80− echo -e "Refreshing sysctl configuration just to be sure.\n"
81− sudo sysctl -p
71+ sudo sysctl -p
8272 else
83− # Set value in current env
84− echo -e "Did not find nr_hugepages in /etc/sysctl.conf. Fixing that!!\n"
85− sudo sysctl -w vm.nr_hugepages="$_ENV_CORE"
73+ # Set value in current env
74+ sudo sysctl -w vm.nr_hugepages="$_ENV_CORE"
75+ # Add value to sysctl
8676 sudo sysctl -p
87−
88− # Add value to sysctl
89− echo "vm.nr_hugepages=$_ENV_CORE" | sudo tee -a /etc/sysctl.conf
9077 fi
9178
9279}
9380
81+echo -e "FUNCTIONS LOADED\n\n"
install.sh+13−5
@@ -1,7 +1,14 @@
11#!/bin/bash
22
3−# Set that user passwdless sudo
3+_DEBUG=true
4+
5+if $_DEBUG; then
6+ set -x
7+else
8+ set +x
9+fi
410
11+# Set that user passwdless sudo
512if sudo grep -q $USER /etc/sudoers.d/README; then
613 echo -e "User $USER found in /etc/sudoers.d/README. All good!!\n"
714else
@@ -9,9 +16,12 @@ else
916 echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/README
1017fi
1118
19+# Load functions
20+. functions.sh
21+
1222# Get settings
1323. settings.sh
14−sleep 5
24+sleep 5
1525
1626# Stop running instance
1727. stop.sh
@@ -43,6 +53,4 @@ SCREEN=""
4353. start.sh
4454
4555
46−echo "####################################"
47−echo "# ALL DONE - INSTALLATION COMPLETE #"
48−echo "####################################"
56+echo -e "INSTALLATION COMPLETE\n"
maintenance.sh+1−9
@@ -1,18 +1,10 @@
11#!/bin/bash
22
3−echo "####################################"
4−echo "# STARTING SYSTEM MAINTENANCE #"
5−echo "####################################"
6−
73if [ $_APT_MAINETANCE = 1 ]; then
84
95 sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean
106
11−else
12− echo "Apt maintenance is set to NO ($_APT_MAINETANCE) Skipping"
137fi
148
15−echo "####################################"
16−echo "# SYSTEM MAINTENANCE COMPLETE #"
17−echo "####################################"
9+echo "MAINTENANCE COMPLETE"
1810
settings.sh+64−33
@@ -1,8 +1,4 @@
1−#!/usr/bin/env bash
2−
3−echo "#################################"
4−echo " LOADING SETTINGS "
5−echo "#################################"
1+#!/bin/bash
62
73_EMAIL="miners@prepaidmeters.com"
84
@@ -11,73 +7,110 @@ _RECEIVE_WALLET="854sqm2Cm4TB2XgPHWqSPSbnFAe3SMzdEDzZHpukQ8NHBPFropbnkFmEKiZPgwj
117_POOL_SERVER_URL="192.168.4.5"
128_POOL_SERVER_PORT="3333"
139
14−#####################################################################
10+#######################################################################
11+# DO NOT CHANGE AFTER THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING #
12+#######################################################################
13+
14+_API_ID="null"
15+_API_WORKER_ID="$HOSTNAME"
16+
17+_AUTOSAVE="true"
18+
19+_BACKGROUND="false"
20+
21+_COLORS="true"
22+
23+# call check_cpu
24+check_cpu
25+
26+# call calc_threads
27+calc_threads
28+
29+_CPU_ENABLED="true"
30+_CPU_HUGE_PAGES="true"
31+_CPU_HW_AES="$_AES_NI"
32+_CPU_PRIORITY="null"
33+_CPU_ASM="true"
34+_CPU_CN="$_ENV_CPU_THREAD_AFFINITY"
35+
36+_CPU_CN_0="false"
37+_CPU_CN_LITE_0="false"
38+
39+_DONATE_LEVEL="5"
1540
16−# DO NOT CHANGE AFTER THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING
41+_DONATE_OVER_PROXY="1"
1742
18−#####################################################################
43+_HTTP_ENABLED="true"
44+_HTTP_HOST=$(hostname --all-ip-addresses | awk '{print $1}')
45+_HTTP_PORT="8080"
46+_HTTP_ACCESS_TOKEN="null"
47+_HTTP_RESTRICTED="false"
1948
20−# Load functions
21−. functions.sh
49+_LOG_FILE="null"
50+
51+_POOLS_ALGO="cn/r"
52+_POOLS_URL="$_POOL_SERVER_URL:$_POOL_SERVER_PORT"
53+_POOLS_USER="$_RECEIVE_WALLET"
54+_POOLS_PASS="$HOSTNAME:$_EMAIL"
55+_POOLS_RIG_ID="$HOSTNAME"
56+_POOLS_NICEHASH="true"
57+_POOLS_KEEPALIVE="true"
58+_POOLS_ENABLED="true"
59+_POOLS_TLS="null"
60+_POOLS_TLS_FINDERPRINT="null"
61+_POOLS_DAEMON="false"
62+
63+_PRINT_TIME="30"
64+
65+_RETRIES="5"
66+_RETRIES_PAUSE="5"
67+
68+_SYSLOG="false"
69+
70+_USER_AGENT="null"
71+
72+_WATCH="true"
73+
74+_CONFIG_JSON=$(jo -p -B api=$(jo id=$_API_ID worker-id=$_API_WORKER_ID) autosave=$_AUTOSAVE background=$_BACKGROUND colors=$_COLORS cpu=$(jo enabled=$_CPU_ENABLED huge-pages=$_CPU_HUGE_PAGES hw-aes=$_CPU_HW_AES priority=$_CPU_PRIORITY asm=$_CPU_ASM cn=$(jo $_CPU_CN) cn/0=$_CPU_CN_0 cn-lite/0=$_CPU_CN_LITE_0) donate-level=$_DONATE_LEVEL donate-over-proxy=$_DONATE_OVER_PROXY http=$(jo enabled=$_HTTP_ENABLED host=$_HTTP_HOST port=$_HTTP_PORT access-token=$_HTTP_ACCESS_TOKEN restricted=$_HTTP_RESTRICTED) logfile=$_LOGFILE pools=$(jo -a $(jo algo=$_POOLS_ALGO url=$_POOLS_URL user=$_POOLS_USER pass=$_POOLS_PASS rig-id=$_POOLS_RIG_ID nicehash=$_POOLS_NICEHASH keepalive=$_POOLS_KEEPALIVE enabled=$_POOLS_ENABLED tls=$_POOLS_TLS tls-fingerprint=$_POOLS_TLS_FINDERPRINT daemon=$_POOLS_DAEMON)) print-time=$_PRINT_TIME retries=$_RETRIES retry-pause=$_RETRIES_PAUSE syslog=$_SYSLOG user-agent=$_USER_AGENT watch=$_WATCH)
2275
2376# Set working directory
2477_WORK_DIR="$(pwd)"
2578cd $_WORK_DIR
26−echo -e "Working directory: $_WORK_DIR\n"
2779
2880# Set repository from which to get the source
2981_XMRIG_REPO="https://github.com/xmrig/xmrig.git"
30−echo -e "Git source repo: $_XMRIG_REPO\n"
3182
3283# Set name of folder to create when cloning from REPO
3384_XMRIG_CLONE="xmrig-cpu"
34−echo -e "Source folder name: $_XMRIG_CLONE\n"
3585
3686# Set clone directory path
3787_XMRIG_CLONE_LOCATION="$_WORK_DIR/$_XMRIG_CLONE"
38−echo -e "Source folder location: $_XMRIG_CLONE_LOCATION\n"
3988
4089# Set branch from which to build
4190_XMRIG_BRANCH="beta"
42−echo -e "Build branch: $_XMRIG_BRANCH\n"
4391
4492# Set build directory
4593_XMRIG_BUILD="build"
46−echo -e "Build directory: $_XMRIG_BUILD\n"
4794
4895# Set build directory location
4996_XMRIG_BUILD_LOCATION="$_XMRIG_CLONE_LOCATION/$_XMRIG_BUILD"
50−echo -e "Build directory location: $_XMRIG_BUILD_LOCATION\n"
5197
5298# Set where to install binary
5399_XMRIG_TARGET_LOCATION="/usr/bin/"
54−echo -e "Install path: $_XMRIG_TARGET_LOCATION\n"
55100
56101# Set the config file name
57102_XMRIG_CONFIG="config.json"
58−echo -e "Config file: $_XMRIG_CONFIG\n"
59103
60104# Set config location
61105_XMRIG_CONFIG_LOCATION="$_WORK_DIR/$_XMRIG_CONFIG"
62−echo -e "Config file location: $_XMRIG_CONFIG_LOCATION\n"
63106
64107# Set values for crontab
65108_USER_CRONSTART="18"
66109_USER_CRONSTOP="6"
67110_USER_CRONDAYS="1-5"
68−echo -e "Cron job start: $_USER_CRONSTART\n"
69−echo -e "Cron job stop: $_USER_CRONSTOP\n"
70−echo -e "Cron on days: $_USER_CRONDAYS\n"
71111
72112# Set the name of the screen created by start script
73113_XMRIG_SCREEN="xmrig-cpu"
74−echo -e "Screen session name: $_XMRIG_SCREEN\n"
75−
76−# call check_cpu
77−check_cpu
78−
79−# call calc_threads
80−calc_threads
81114
82115# Run apt maintenance
83116# 1 = yes 0 = no
@@ -87,7 +120,5 @@ _APT_MAINETANCE="1"
87120# 1 = yes 0 = no
88121_APT_DEPENDS="1"
89122
90−echo "#################################"
91−echo " SETTINGS LOADED"
92−echo "#################################"
123+echo -e "SETTINGS LOADED\n\n"
93124
start.sh+5−11
@@ -1,32 +1,26 @@
1−#!/usr/bin/env bash
1+#!/bin/bash
22
33# When this script is:
44# * run by crontab, load the settings
55# * run by install, do not load settings
66
7−echo "####################################"
8−echo " STARTING "
9−echo "####################################"
7+# Reload settings and functions for when running standalone
108. settings.sh
119. functions.sh
1210
1311if ! screen -list | grep -q "$_XMRIG_SCREEN"; then
14− # Call function
15− echo "No screen sessionfound. Starting new screen session."
12+
13+ # Call function
1614 start_xmrig
1715
1816 # List screen
1917 screen -ls
2018else
21− # Call function
22− echo "Found existing screen session. Leaving."
2319
2420 # List screen
2521 screen -ls
2622
2723fi
2824
29−echo "####################################"
30−echo " STARTED - use screen -r to view "
31−echo "####################################"
25+echo "MINING STARTED"
3226
stop.sh+1−11
@@ -4,13 +4,8 @@
44# * run by crontab, load the settings
55# * run by install, do not load settings
66
7−echo "#################################"
8−echo " KILLING SCREEN"
9−echo "#################################"
10−
117if [ -z "$_XMRIG_SCREEN" ]; then
128 # Load settings when run by crontab
13− echo "Loading settings and functions"
149 . settings.sh
1510 . functions.sh
1611
@@ -21,10 +16,5 @@ else
2116 stop_xmrig
2217fi
2318
24−# Check results
25−echo "Screen listing"
26−screen -ls
19+echo "MINING STOPPED"
2720
28−echo "#################################"
29−echo " SCREEN KILLED"
30−echo "#################################"
update.sh+2
@@ -5,3 +5,5 @@ git pull
55# install
66. install.sh
77sleep 5
8+
9+echo "UPATE COMPLETE"