git.iko.soy/xmrig-bash-scripts
on master help sign in
Merge branch 'release/v1.0.6'
commitfb5f3cc6ac79c29b14331d2946bc6a47908c24f0 authorSean Wheller <sean@prepaidmeters.com> dateSun 11 Aug 2019, 10:28 (7 years ago) parenta47baa39a6ad6d
16 files changed+286−242
.gitignore+2 README.md+19−10 build.sh+1−10 config.sh+1−57 crontab-off.sh+5−7 crontab-on.sh+5−6 crontab.sh+1−12 depends.sh+1−9 functions.sh+77−10 input.sh+60 install.sh+16−5 maintenance.sh+1−9 settings.sh+80−84 start.sh+7−12 stop.sh+1−11 update.sh+9
.gitignore+2
@@ -2,3 +2,5 @@ xmrig-cpu/
22*.swp
33crontab
44config.json
5+myconfig.json
6+mysettings.sh
README.md+19−10
@@ -19,11 +19,11 @@ At the start the expectation is that you have:
1919
2020Some knowledge of:
2121* Linux Command Line Interface
22−* Unix shell `bash`
22+* Linux shell `bash`
2323
2424There is more to install but the install script will install the rest.
2525
26−### Installion
26+### Installation
2727
28281. Change to your user home directory.
2929 `cd ~`
@@ -43,34 +43,40 @@ There is more to install but the install script will install the rest.
43436. Run the install script
4444 `./install.sh`
4545
46−7. Attach to the screen session created during the installation.
46+7. After install is complete. Attach to the screen session created during the installation.
4747 `screen -r`
4848
4949### Operation
5050
51−With the exception of the 'xmrig' binary, which is installed to `/usr/bin/xmrig`, all files remain in the cloned project directory `~/xmrig-bash-scripts`. Any files generated while running the scripts are created in this directory.
51+Defaults - The settings.sh contains a number of variables. With the exception of the 'xmrig' binary, which is installed to `/usr/bin/xmrig`, all files remain in the cloned project directory `~/xmrig-bash-scripts`. Any files generated while running the scripts are also created in this directory.
5252
53−During install the folder source for [xmrig cpu](https://github.com/xmrig/xmrig) is cloned to `xmrig-cpu/`in the path. The `config.json` is also created in this path.
53+During install the folder source for [xmrig cpu](https://github.com/xmrig/xmrig) is cloned to `~/xmrig-bash-scripts/xmrig-cpu/`. The `config.json` is also created in this path.
5454
55−This should work out the box, if you edit only the top section of `settings.sh`.
55+This should work out the box, if you edit only the top section of `settings.sh` and followed the steps here.
5656
5757Once you have a running xmrig then you can start playing around and tweaking to suite requirements.
5858
59−What follows is a brief of the shell scripts you will find. The names are mostly self explanatory. Comments and notes are used liberally in the scripts to help give you hints as to how it works. The scripts are designed to be modular to promote resuse, execute exclusion and standalone execution.
59+What follows is a brief of the shell scripts you will find. The names are mostly self explanatory.
60+Comments and notes are used liberally in the scripts to help give you hints as to how it works.
61+The scripts are designed to be modular to promote resuse, execute exclusion and standalone execution.
6062
6163* build.sh - clones xmrig to ``~/xmrig-bash-scripts`/xmrig-cpu`, configures, builds and copies xmrig to `/usr/bin/`
6264* config.sh - contains variables that aid in defining the values for the attributes found in config.json.
6365* crontab.sh - installs a cron to start and a cron to stop at specific times (Can be commented out of install if desired).
66+* crontab-off - removed the users crontab created during install.
67+* crontab-on.sh - redefines the users crontab as created during install.
6468* depends.sh - installs dependancies required by xmrig and these scripts.
6569* functions.sh - a collection of functions used in various of the scripts.
6670* install.sh - the main entry point when first installing.
67−* maintenance.sh - performs apt update and upgrade.
71+* maintenance.sh - performs apt update, upgrade, autoremove and autoclean operations.
6872* settings.sh - contains variables used by these scripts.
6973* start.sh - starts xmrig in a screen session.
7074* stop.sh - stops xmrig screen session.
7175
7276### Viewing the log
73−Default of the start script is to create a screen session named 'xmrig-cpu'. This can be changed in the settings script if required. To view the log after installation is finished or after running the start script, used the following command:
77+Default of the start script is to create a screen session named 'xmrig-cpu'.
78+This can be changed in the settings script if required.
79+To view the log after installation is finished or after running the start script, used the following command:
7480`screen -r xmrig-cpu`
7581
7682### Updating
@@ -79,11 +85,14 @@ A simple `git update` in `~/xmrig-bash-scripts` will update these scripts.
7985The install script can be run at any time to update the xmrig source found `~/xmrig-bash-scripts/xmrig-cpu`.
8086The branch checkout is taken from the `_XMRIG_BRANCH` variable in `settings.sh`.
8187
88+A script named update.sh is provided to perform both these steps in a single command.
89+
8290## Reporting issues
8391
8492[xmrig cpu](https://github.com/xmrig/xmrig) and [xmrig bash scripts](https://github.com/seanwhe/xmrig-bash-scripts.git) are different projects run by different people.
8593
86−While the developers of both projects may be seen interacting with one another on either project, we ask that you report issues to the respective projects. In other words, post issues for:
94+While the developers of both projects may be seen interacting with one another on either project, we ask that you report issues to the respective projects.
95+In other words, post issues for:
8796* xmrig, the Monero (XMR) CPU miner, over at [xmrig issues tracker](https://github.com/xmrig/xmrig/issues)
8897* xmrig-bash-scripts, these conveniece scripts, over at [xmrig-bash-scripts](https://github.com/seanwhe/xmrig-bash-scripts/issues)
8998
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 "${_GREEN}BUILD COMPLETE${_RESET}"
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 "${_GREEN}CONFIG CREATED${_RESET}"
626
crontab-off.sh+5−7
@@ -1,9 +1,9 @@
11#!/bin/bash
22
3−echo "#################################"
4−echo "# DISABLING CRONTAB #"
5−echo "#################################"
6−
3+# Removes a user crontab
4+# Used in conjunction with crontab-on.sh to toggle user crontab between states:
5+# on - start/stop xmrig at specified times
6+# off - do not start/stop xmrig
77
88# Remove existing crontab
99echo "Backup existing crontab"
@@ -12,7 +12,5 @@ crontab -l > crontab
1212echo "Removing exiting crontab"
1313crontab -r
1414
15−echo "#################################"
16−echo "# CRONTAB DISABLED #"
17−echo "#################################"
15+echo "${_GREEN}CRONTAB DISABLED${_RESET}"
1816
crontab-on.sh+5−6
@@ -1,8 +1,9 @@
11#!/bin/bash
22
3−echo "####################################"
4−echo "# ENABLING CRONTAB #"
5−echo "####################################"
3+# Defines a user crontab with schedules as defined in settings.sh
4+# Used in conjunction with crontab-off.sh to toggle user crontab between states:
5+# on - start/stop xmrig at specified times
6+# off - do not start/stop xmrig
67
78# Get settings
89. settings.sh
@@ -13,7 +14,5 @@ sleep 5
1314. crontab.sh
1415sleep 5
1516
16−echo "####################################"
17−echo "# CRONTAB ENABLED #"
18−echo "####################################"
17+echo "${_GREEN}CRONTAB ENABLED${_RESET}"
1918
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 "${_GREEN}CRONTAB CREATED${_RESET}"
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 "${_GREEN}DEPENDENCIES INSTALLED${_RESET}"
functions.sh+77−10
@@ -1,39 +1,106 @@
1−#!/usr/bin/env bash
1+#!/bin/bash
22
3−build_xmrig () {
3+function prompt_confirm() {
4+ while true; do
5+ read -r -n 1 -p "${1:-Continue?} [y/n]: " REPLY
6+ case $REPLY in
7+ [yY]) echo ; return 0 ;;
8+ [nN]) echo ; return 1 ;;
9+ *) printf " \033[31m %s \n\033[0m" "invalid input [y/n]"
10+ esac
11+ done
12+}
13+
14+function show_mysettings () {
15+ if [ -f $_WORK_DIR/$_MYSETTINGS_FILE ]; then
16+ . $_MYSETTINGS_FILE
17+ echo "${_GREEN}Settings from loaded from mysettings.sh.${_RESET}"
18+ echo "${_GREEN}Pool URL:${_RESET}: $_POOL_SERVER_URL"
19+ echo "${_GREEN}Pool Port:${_RESET}: $_POOL_SERVER_PORT"
20+ echo "${_GREEN}Recieve Wallet:${_RESET}: $_RECEIVE_WALLET"
21+ echo "${_GREEN}Email Address:${_RESET}: $_EMAIL"
22+ echo "${_GREEN}Worker Identity:${_RESET}: $_API_WORKER_ID"
23+ fi
24+}
25+
26+function build_xmrig () {
427 if [ -d $_XMRIG_BUILD_LOCATION ]; then
528 # Remove existing build directory
6− echo "Found old build directory. Removing"
729 rm -rf $_XMRIG_BUILD_LOCATION
830
931 # Make new build directory
10− echo "Creating a build directory"
1132 mkdir $_XMRIG_BUILD_LOCATION
1233 else
1334 # Make new build directory
14− echo "Creating a build directory"
1535 mkdir $_XMRIG_BUILD_LOCATION
1636 fi
1737
1838 # Change to build directory
19− echo "Changing to build directory"
2039 cd $_XMRIG_BUILD_LOCATION
2140
2241 # Configure cmake scafolding
23− echo "Configuring cmake scafolding"
2442 cmake .. -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7
2543
2644 # Compile the software
27− echo "Starting build"
2845 make
2946}
3047
3148
32−start_xmrig () {
49+function start_xmrig () {
3350 screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
3451}
3552
3653
37−stop_xmrig () {
54+function stop_xmrig () {
3855 screen -S $_XMRIG_SCREEN -X kill
3956}
57+
58+function check_cpu () {
59+ # Check if CPU supports AES-NI
60+ cpuid | grep -i aes > hw-aes.txt
61+ if grep -q true "hw-aes.txt"; then
62+ _AES_NI=true
63+ else
64+ _AES_NI=false
65+ fi
66+ rm hw-aes.txt
67+
68+ # Get number of available CPU Cores
69+ _ENV_CORE=$(nproc --all)
70+
71+ # Get CPU L3 cache value
72+ _ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
73+}
74+
75+function calc_threads () {
76+ # Each thread needs 2048 byte (2 Megabyte)
77+ # Calculate number of threads supported with L3 cache size
78+
79+ _ENV_THREAD_QTY=$(( ($_ENV_CORE_L3/2048)/1000 ))
80+
81+ # Affine number of threads for _CPU_CN
82+ _COUNTER="$(( $_ENV_THREAD_QTY-1 ))"
83+
84+ _ENV_CPU_THREAD_AFFINITY="$(seq -s " " 0 $_COUNTER)"
85+
86+}
87+
88+function calc_hugepages () {
89+ # Setting according to cpu cores but xmrig will not use all
90+ # change to make value use _ENV_CORE_THREADS
91+ # Check that hugepages set in /etc/sysctl.conf
92+
93+ _ENV_CHECK="nr_hugepages"
94+
95+ if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
96+ sudo sysctl -p
97+ else
98+ # Set value in current env
99+ sudo sysctl -w vm.nr_hugepages="$_ENV_THREAD_QTY"
100+ # Add value to sysctl
101+ sudo sysctl -p
102+ fi
103+
104+}
105+
106+echo -e "${_GREEN}FUNCTIONS LOADED${_RESET}"
input.shnew file+60
@@ -0,0 +1,60 @@
1+#!/bin/bash
2+
3+# Ask user questions
4+# Capture input
5+. functions.sh
6+. settings.sh
7+
8+echo -e "${_YELLOW}Choose to use default settings or enter your own.\n"
9+
10+echo -e "Use defaults and values will be taken from 'settings.sh'."
11+echo -e "Enter your own and settings will persist to 'mysettings.sh'.\n"
12+
13+echo -e "Preference is given to settings in 'mysettings.sh'."
14+echo -e "When starting from 'start.sh' and 'mysettings.sh' exists it will be loaded instead of 'settings.sh'.${_RESET}\n"
15+
16+if [ -f $_WORK_DIR/$_MYSETTINGS_FILE ]; then
17+
18+ # Call function
19+ show_mysettings
20+
21+else
22+
23+ prompt_confirm "Enter your own settings?"
24+
25+ if [ "$?" -eq 0 ]; then
26+
27+ # Create a file
28+
29+ touch $_MYSETTINGS_FILE_LOCATION
30+ chmod +x $_MYSETTINGS_FILE_LOCATION
31+ echo "#!/bin/bash" > $_MYSETTINGS_FILE_LOCATION
32+
33+ # Prompt user input
34+
35+ echo "Current pool URL: $_POOL_SERVER_URL"
36+ read -p "Enter new pool URL: " _POOL_SERVER_URL
37+
38+ echo "Current pool TCP Port: $_POOL_SERVER_PORT"
39+ read -p "Enter new pool TCP Port: " _POOL_SERVER_PORT
40+
41+ echo "Current Receive Wallet address: $_RECEIVE_WALLET"
42+ read -p "Enter new Receive Wallet address: " _RECEIVE_WALLET
43+
44+ echo "Current email address: $_EMAIL"
45+ read -p "Enter new email address: " _EMAIL
46+
47+ echo "Current Miner Identifier: $_API_WORKER_ID"
48+ read -p "Enter Miner Identifier: " _API_WORKER_ID
49+
50+ # Write user input to file
51+
52+ echo "_POOL_SERVER_URL=\"$_POOL_SERVER_URL\"" >> $_MYSETTINGS_FILE_LOCATION
53+ echo "_POOL_SERVER_PORT=\"$_POOL_SERVER_PORT\"" >> $_MYSETTINGS_FILE_LOCATION
54+ echo "_RECEIVE_WALLET=\"$_RECEIVE_WALLET\"" >> $_MYSETTINGS_FILE_LOCATION
55+ echo "_EMAIL=\"$_EMAIL\"" >> $_MYSETTINGS_FILE_LOCATION
56+ echo "_API_WORKER_ID=\"$_API_WORKER_ID\"" >> $_MYSETTINGS_FILE_LOCATION
57+
58+ fi
59+
60+fi
install.sh+16−5
@@ -1,7 +1,14 @@
11#!/bin/bash
22
3−# Set that user passwdless sudo
3+_DEBUG=$1
44
5+if $_DEBUG; then
6+ set +x
7+else
8+ set -x
9+fi
10+
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,15 @@ 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−. functions.sh
24+sleep 5
25+
26+# User input
27+. input.sh
1528sleep 5
1629
1730# Stop running instance
@@ -44,6 +57,4 @@ SCREEN=""
4457. start.sh
4558
4659
47−echo "####################################"
48−echo "# ALL DONE - INSTALLATION COMPLETE #"
49−echo "####################################"
60+echo -e "${_GREEN}INSTALLATION COMPLETE${_RESET}"
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 "${_GREEN}MAINTENANCE COMPLETE${_RESET}"
1810
settings.sh+80−84
@@ -1,132 +1,122 @@
1−#!/usr/bin/env bash
2−
3−echo "#################################"
4−echo " LOADING SETTINGS "
5−echo "#################################"
1+#!/bin/bash
62
73_EMAIL="miners@prepaidmeters.com"
84
95_RECEIVE_WALLET="854sqm2Cm4TB2XgPHWqSPSbnFAe3SMzdEDzZHpukQ8NHBPFropbnkFmEKiZPgwjMFC9PTjaFscR2UU6ZwFCqJzGMUiZVbTM"
106
11−_POOL_SERVER_URL="192.168.4.5"
7+_POOL_SERVER_URL="pool.supportxmr.com"
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"
40+
41+_DONATE_OVER_PROXY="1"
1542
16−# DO NOT CHANGE AFTER THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING
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"
1748
18−#####################################################################
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 -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)
1975
2076# Set working directory
2177_WORK_DIR="$(pwd)"
2278cd $_WORK_DIR
23−echo -e "Working directory: $_WORK_DIR\n"
2479
2580# Set repository from which to get the source
2681_XMRIG_REPO="https://github.com/xmrig/xmrig.git"
27−echo -e "Git source repo: $_XMRIG_REPO\n"
2882
2983# Set name of folder to create when cloning from REPO
3084_XMRIG_CLONE="xmrig-cpu"
31−echo -e "Source folder name: $_XMRIG_CLONE\n"
3285
3386# Set clone directory path
3487_XMRIG_CLONE_LOCATION="$_WORK_DIR/$_XMRIG_CLONE"
35−echo -e "Source folder location: $_XMRIG_CLONE_LOCATION\n"
3688
3789# Set branch from which to build
3890_XMRIG_BRANCH="beta"
39−echo -e "Build branch: $_XMRIG_BRANCH\n"
4091
4192# Set build directory
4293_XMRIG_BUILD="build"
43−echo -e "Build directory: $_XMRIG_BUILD\n"
4494
4595# Set build directory location
4696_XMRIG_BUILD_LOCATION="$_XMRIG_CLONE_LOCATION/$_XMRIG_BUILD"
47−echo -e "Build directory location: $_XMRIG_BUILD_LOCATION\n"
4897
4998# Set where to install binary
5099_XMRIG_TARGET_LOCATION="/usr/bin/"
51−echo -e "Install path: $_XMRIG_TARGET_LOCATION\n"
100+
101+# Set mysettings file
102+_MYSETTINGS_FILE="mysettings.sh"
103+
104+# Set mysettings file location
105+_MYSETTINGS_FILE_LOCATION="$_WORK_DIR/$_MYSETTINGS_FILE"
52106
53107# Set the config file name
54108_XMRIG_CONFIG="config.json"
55−echo -e "Config file: $_XMRIG_CONFIG\n"
56109
57110# Set config location
58111_XMRIG_CONFIG_LOCATION="$_WORK_DIR/$_XMRIG_CONFIG"
59−echo -e "Config file location: $_XMRIG_CONFIG_LOCATION\n"
60112
61113# Set values for crontab
62114_USER_CRONSTART="18"
63115_USER_CRONSTOP="6"
64116_USER_CRONDAYS="1-5"
65−echo -e "Cron job start: $_USER_CRONSTART\n"
66−echo -e "Cron job stop: $_USER_CRONSTOP\n"
67−echo -e "Cron on days: $_USER_CRONDAYS\n"
68117
69118# Set the name of the screen created by start script
70119_XMRIG_SCREEN="xmrig-cpu"
71−echo -e "Screen session name: $_XMRIG_SCREEN\n"
72−
73−# Check if CPU supports AES-NI
74−cpuid | grep -i aes > hw-aes.txt
75−if grep -q true "hw-aes.txt"; then
76− _AES_NI=true
77−else
78− _AES_NI=false
79−fi
80−rm hw-aes.txt
81−
82−# Get number of available CPU Cores
83−_ENV_CORE=$(nproc --all)
84−echo -e "CPU Cores: $_ENV_CORE\n"
85−
86−# Get CPU L3 cache value
87−_ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
88−echo -e "L3 Cache in byte: $_ENV_CORE_L3\n"
89−
90−# Determine number of threads possible
91−_ENV_CORE_L3_MB="$(($_ENV_CORE_L3 / 1000000))"
92−echo -e "L3 cache in Megabyte: $_ENV_CORE_L3_MB\n"
93−
94−# Determine number of threads possible
95−_ENV_CORE_THREADS="$(($_ENV_CORE_L3_MB / 2))"
96−echo "Each thread requires 2 MB of cache"
97−echo -e "Number of threads possible is: $_ENV_CORE_THREADS\n"
98−
99−# Affine number of threads for _CPU_CN
100−_COUNTER="$(($_ENV_CORE_THREADS - 1))"
101−_ENV_CPU_THREADS=()
102−
103−for i in `seq 0 $_COUNTER`; do
104− _ENV_CPU_THREADS+=("$i")
105−done
106−
107−echo "Thread CPU Affinity: ${_ENV_CPU_THREADS[@]}"
108−
109−_ENV_CPU_THREAD_AFFINITY="${_ENV_CPU_THREADS[@]}"
110−
111−
112−# Setting according to cpu cores but xmrig will not use all
113−# change to make value use _ENV_CORE_THREADS
114−# Check that hugepages set in /etc/sysctl.conf
115−_ENV_CHECK="nr_hugepages"
116−
117−if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
118− echo "Found nr_hugepages in /etc/sysctl.conf. All good!!"
119− echo -e "Refreshing sysctl configuration just to be sure.\n"
120− sudo sysctl -p
121−else
122− # Set value in current env
123− echo -e "Did not find nr_hugepages in /etc/sysctl.conf. Fixing that!!\n"
124− sudo sysctl -w vm.nr_hugepages="$_ENV_CORE"
125− sudo sysctl -p
126−
127− # Add value to sysctl
128− echo "vm.nr_hugepages=$_ENV_CORE" | sudo tee -a /etc/sysctl.conf
129−fi
130120
131121# Run apt maintenance
132122# 1 = yes 0 = no
@@ -136,7 +126,13 @@ _APT_MAINETANCE="1"
136126# 1 = yes 0 = no
137127_APT_DEPENDS="1"
138128
139−echo "#################################"
140−echo " SETTINGS LOADED"
141−echo "#################################"
129+# Colors
130+_GREEN=`tput setaf 2`
131+_YELLOW=`tput setaf 3`
132+_BLUE=`tput setaf 4`
133+_MAGENTA=`tput setaf 5`
134+_CYAN=`tput setaf 6`
135+_RESET=`tput sgr0`
136+
137+echo -e "${_GREEN}SETTINGS LOADED${_RESET}"
142138
start.sh+7−12
@@ -1,32 +1,27 @@
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 "####################################"
10−. settings.sh
7+# Reload settings and functions for when running standalone
118. functions.sh
9+. settings.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 functions
14+ show_mysettings
1615 start_xmrig
1716
1817 # List screen
1918 screen -ls
2019else
21− # Call function
22− echo "Found existing screen session. Leaving."
2320
2421 # List screen
2522 screen -ls
2623
2724fi
2825
29−echo "####################################"
30−echo " STARTED - use screen -r to view "
31−echo "####################################"
26+echo "${_GREEN}MINING STARTED${_RESET}"
3227
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 "${_GREEN}MINING STOPPED${_RESET}"
2720
28−echo "#################################"
29−echo " SCREEN KILLED"
30−echo "#################################"
update.shnew file+9
@@ -0,0 +1,9 @@
1+#!/bin/bash
2+
3+git pull
4+
5+# install
6+. install.sh
7+sleep 5
8+
9+echo "${_GREEN}UPDATE COMPLETE${_RESET}"