git.iko.soy/xmrig-bash-scripts
on master help sign in
Merge branch 'release/v1.0.6'
fb5f3ccSean Wheller
.gitignore+2
@@ -2,3 +2,5 @@ xmrig-cpu/
2*.swp
2*.swp
3crontab
3crontab
4config.json
4config.json
5+myconfig.json
6+mysettings.sh
README.md+19−10
@@ -19,11 +19,11 @@ At the start the expectation is that you have:
19
19
20Some knowledge of:
20Some knowledge of:
21* Linux Command Line Interface
21* Linux Command Line Interface
22−* Unix shell `bash`
22+* Linux shell `bash`
23
23
24There is more to install but the install script will install the rest.
24There is more to install but the install script will install the rest.
25
25
26−### Installion
26+### Installation
27
27
281. Change to your user home directory.
281. Change to your user home directory.
29 `cd ~`
29 `cd ~`
@@ -43,34 +43,40 @@ There is more to install but the install script will install the rest.
436. Run the install script
436. Run the install script
44 `./install.sh`
44 `./install.sh`
45
45
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.
47 `screen -r`
47 `screen -r`
48
48
49### Operation
49### Operation
50
50
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.
52
52
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.
54
54
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.
56
56
57Once you have a running xmrig then you can start playing around and tweaking to suite requirements.
57Once you have a running xmrig then you can start playing around and tweaking to suite requirements.
58
58
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.
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.
61+The scripts are designed to be modular to promote resuse, execute exclusion and standalone execution.
60
62
61* build.sh - clones xmrig to ``~/xmrig-bash-scripts`/xmrig-cpu`, configures, builds and copies xmrig to `/usr/bin/`
63* build.sh - clones xmrig to ``~/xmrig-bash-scripts`/xmrig-cpu`, configures, builds and copies xmrig to `/usr/bin/`
62* config.sh - contains variables that aid in defining the values for the attributes found in config.json.
64* config.sh - contains variables that aid in defining the values for the attributes found in config.json.
63* crontab.sh - installs a cron to start and a cron to stop at specific times (Can be commented out of install if desired).
65* 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.
64* depends.sh - installs dependancies required by xmrig and these scripts.
68* depends.sh - installs dependancies required by xmrig and these scripts.
65* functions.sh - a collection of functions used in various of the scripts.
69* functions.sh - a collection of functions used in various of the scripts.
66* install.sh - the main entry point when first installing.
70* 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.
68* settings.sh - contains variables used by these scripts.
72* settings.sh - contains variables used by these scripts.
69* start.sh - starts xmrig in a screen session.
73* start.sh - starts xmrig in a screen session.
70* stop.sh - stops xmrig screen session.
74* stop.sh - stops xmrig screen session.
71
75
72### Viewing the log
76### Viewing the log
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.
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:
79+To view the log after installation is finished or after running the start script, used the following command:
74`screen -r xmrig-cpu`
80`screen -r xmrig-cpu`
75
81
76### Updating
82### Updating
@@ -79,11 +85,14 @@ A simple `git update` in `~/xmrig-bash-scripts` will update these scripts.
79The install script can be run at any time to update the xmrig source found `~/xmrig-bash-scripts/xmrig-cpu`.
85The install script can be run at any time to update the xmrig source found `~/xmrig-bash-scripts/xmrig-cpu`.
80The branch checkout is taken from the `_XMRIG_BRANCH` variable in `settings.sh`.
86The branch checkout is taken from the `_XMRIG_BRANCH` variable in `settings.sh`.
81
87
88+A script named update.sh is provided to perform both these steps in a single command.
89+
82## Reporting issues
90## Reporting issues
83
91
84[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.
92[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.
85
93
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:
87* xmrig, the Monero (XMR) CPU miner, over at [xmrig issues tracker](https://github.com/xmrig/xmrig/issues)
96* xmrig, the Monero (XMR) CPU miner, over at [xmrig issues tracker](https://github.com/xmrig/xmrig/issues)
88* xmrig-bash-scripts, these conveniece scripts, over at [xmrig-bash-scripts](https://github.com/seanwhe/xmrig-bash-scripts/issues)
97* xmrig-bash-scripts, these conveniece scripts, over at [xmrig-bash-scripts](https://github.com/seanwhe/xmrig-bash-scripts/issues)
89
98
build.sh+1−10
@@ -1,12 +1,7 @@
1#!/bin/bash
1#!/bin/bash
2
2
3−echo "#################################"
4−echo " BUILD STARTING"
5−echo "#################################"
6−
7# Clone source
3# Clone source
8if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
4if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
9− echo "Clone already exists"
10
5
11 # Change to clone directory
6 # Change to clone directory
12 cd $_XMRIG_CLONE
7 cd $_XMRIG_CLONE
@@ -20,7 +15,6 @@ if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
20
15
21 else
16 else
22 # Switch to required branch
17 # Switch to required branch
23− echo "Require: $_XMRIG_BRANCH Switching !!!"
24 git checkout $_XMRIG_BRANCH
18 git checkout $_XMRIG_BRANCH
25
19
26 # Pull changes from source
20 # Pull changes from source
@@ -31,7 +25,6 @@ if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
31 fi
25 fi
32else
26else
33 # Clone the source
27 # Clone the source
34− echo "Cloning source to $_WORK_DIR/$_XMRIG_CLONE"
35 git clone $_XMRIG_REPO $_XMRIG_CLONE
28 git clone $_XMRIG_REPO $_XMRIG_CLONE
36
29
37 # Change to clone directory
30 # Change to clone directory
@@ -52,7 +45,5 @@ sudo cp $_XMRIG_BUILD_LOCATION/xmrig $_XMRIG_TARGET_LOCATION
52
45
53cd $_WORK_DIR
46cd $_WORK_DIR
54
47
55−echo "#################################"
56−echo " BUILD COMPLETE"
48+echo "${_GREEN}BUILD COMPLETE${_RESET}"
57−echo "#################################"
58
49
config.sh+1−57
@@ -1,62 +1,6 @@
1#!/bin/bash
1#!/bin/bash
2
2
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−
59echo "$_CONFIG_JSON" | tee config.json
3echo "$_CONFIG_JSON" | tee config.json
60
4
61−
5+echo "${_GREEN}CONFIG CREATED${_RESET}"
62
6
crontab-off.sh+5−7
@@ -1,9 +1,9 @@
1#!/bin/bash
1#!/bin/bash
2
2
3−echo "#################################"
3+# Removes a user crontab
4−echo "# DISABLING CRONTAB #"
4+# Used in conjunction with crontab-on.sh to toggle user crontab between states:
5−echo "#################################"
5+# on - start/stop xmrig at specified times
6−
6+# off - do not start/stop xmrig
7
7
8# Remove existing crontab
8# Remove existing crontab
9echo "Backup existing crontab"
9echo "Backup existing crontab"
@@ -12,7 +12,5 @@ crontab -l > crontab
12echo "Removing exiting crontab"
12echo "Removing exiting crontab"
13crontab -r
13crontab -r
14
14
15−echo "#################################"
16−echo "# CRONTAB DISABLED #"
15+echo "${_GREEN}CRONTAB DISABLED${_RESET}"
17−echo "#################################"
18
16
crontab-on.sh+5−6
@@ -1,8 +1,9 @@
1#!/bin/bash
1#!/bin/bash
2
2
3−echo "####################################"
3+# Defines a user crontab with schedules as defined in settings.sh
4−echo "# ENABLING CRONTAB #"
4+# Used in conjunction with crontab-off.sh to toggle user crontab between states:
5−echo "####################################"
5+# on - start/stop xmrig at specified times
6+# off - do not start/stop xmrig
6
7
7# Get settings
8# Get settings
8. settings.sh
9. settings.sh
@@ -13,7 +14,5 @@ sleep 5
13. crontab.sh
14. crontab.sh
14sleep 5
15sleep 5
15
16
16−echo "####################################"
17−echo "# CRONTAB ENABLED #"
17+echo "${_GREEN}CRONTAB ENABLED${_RESET}"
18−echo "####################################"
19
18
crontab.sh+1−12
@@ -2,20 +2,12 @@
2
2
3# Set values in settings script
3# Set values in settings script
4
4
5−echo "#################################"
6−echo " UPDATING CRONTAB"
7−echo "#################################"
8−
9−
10# Remove existing crontab
5# Remove existing crontab
11−echo "Backup existing crontab"
12crontab -l > crontab
6crontab -l > crontab
13
7
14−echo "Removing exiting crontab"
15crontab -r
8crontab -r
16
9
17# Setup users contab
10# Setup users contab
18−echo "Creating new crontab"
19
11
20crontab -l | { cat; echo "#Start at $_USER_TIMESTART on days $_USER_CRONDAYS
12crontab -l | { cat; echo "#Start at $_USER_TIMESTART on days $_USER_CRONDAYS
210 $_USER_CRONSTART * * $_USER_CRONDAYS screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION"; } | crontab -
130 $_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
23crontab -l | { cat; echo "#Stop at $_USER_TIMESTOP on days $_USER_CRONDAYS
15crontab -l | { cat; echo "#Stop at $_USER_TIMESTOP on days $_USER_CRONDAYS
240 $_USER_CRONSTOP * * $_USER_CRONDAYS screen -S $_XMRIG_SCREEN -X kill"; } | crontab -
160 $_USER_CRONSTOP * * $_USER_CRONDAYS screen -S $_XMRIG_SCREEN -X kill"; } | crontab -
25
17
26−
18+echo "${_GREEN}CRONTAB CREATED${_RESET}"
27−echo "#################################"
28−echo " CRONTAB UPDATED"
29−echo "#################################"
30
19
depends.sh+1−9
@@ -1,7 +1,4 @@
1#!/bin/bash
1#!/bin/bash
2−echo "#################################"
3−echo " INSTALLING DEPENDENCIES "
4−echo "#################################"
5
2
6# Install the software requirements
3# Install the software requirements
7
4
@@ -12,12 +9,7 @@ if [ $_APT_DEPENDS = 1 ]; then
12
9
13 # Install xmrig-bash-scripts depends
10 # Install xmrig-bash-scripts depends
14 sudo apt install -y jo cpuid screen
11 sudo apt install -y jo cpuid screen
15−else
16−
17− echo "Depend install is set to NO ($_APT_DEPENDS) Skipping"
18
12
19fi
13fi
20
14
21−echo "#################################"
22−echo " DEPENDENCIES INSTALLED "
15+echo "${_GREEN}DEPENDENCIES INSTALLED${_RESET}"
23−echo "#################################"
functions.sh+77−10
@@ -1,39 +1,106 @@
1−#!/usr/bin/env bash
1+#!/bin/bash
2
2
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+
3−build_xmrig () {
26+function build_xmrig () {
4 if [ -d $_XMRIG_BUILD_LOCATION ]; then
27 if [ -d $_XMRIG_BUILD_LOCATION ]; then
5 # Remove existing build directory
28 # Remove existing build directory
6− echo "Found old build directory. Removing"
7 rm -rf $_XMRIG_BUILD_LOCATION
29 rm -rf $_XMRIG_BUILD_LOCATION
8
30
9 # Make new build directory
31 # Make new build directory
10− echo "Creating a build directory"
11 mkdir $_XMRIG_BUILD_LOCATION
32 mkdir $_XMRIG_BUILD_LOCATION
12 else
33 else
13 # Make new build directory
34 # Make new build directory
14− echo "Creating a build directory"
15 mkdir $_XMRIG_BUILD_LOCATION
35 mkdir $_XMRIG_BUILD_LOCATION
16 fi
36 fi
17
37
18 # Change to build directory
38 # Change to build directory
19− echo "Changing to build directory"
20 cd $_XMRIG_BUILD_LOCATION
39 cd $_XMRIG_BUILD_LOCATION
21
40
22 # Configure cmake scafolding
41 # Configure cmake scafolding
23− echo "Configuring cmake scafolding"
24 cmake .. -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7
42 cmake .. -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7
25
43
26 # Compile the software
44 # Compile the software
27− echo "Starting build"
28 make
45 make
29}
46}
30
47
31
48
32−start_xmrig () {
49+function start_xmrig () {
33 screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
50 screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
34}
51}
35
52
36
53
37−stop_xmrig () {
54+function stop_xmrig () {
38 screen -S $_XMRIG_SCREEN -X kill
55 screen -S $_XMRIG_SCREEN -X kill
39}
56}
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 @@
1#!/bin/bash
1#!/bin/bash
2
2
3−# Set that user passwdless sudo
3+_DEBUG=$1
4
4
5+if $_DEBUG; then
6+ set +x
7+else
8+ set -x
9+fi
10+
11+# Set that user passwdless sudo
5if sudo grep -q $USER /etc/sudoers.d/README; then
12if sudo grep -q $USER /etc/sudoers.d/README; then
6 echo -e "User $USER found in /etc/sudoers.d/README. All good!!\n"
13 echo -e "User $USER found in /etc/sudoers.d/README. All good!!\n"
7else
14else
@@ -9,9 +16,15 @@ else
9 echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/README
16 echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/README
10fi
17fi
11
18
19+# Load functions
20+. functions.sh
21+
12# Get settings
22# Get settings
13. settings.sh
23. settings.sh
14−. functions.sh
24+sleep 5
25+
26+# User input
27+. input.sh
15sleep 5
28sleep 5
16
29
17# Stop running instance
30# Stop running instance
@@ -44,6 +57,4 @@ SCREEN=""
44. start.sh
57. start.sh
45
58
46
59
47−echo "####################################"
48−echo "# ALL DONE - INSTALLATION COMPLETE #"
60+echo -e "${_GREEN}INSTALLATION COMPLETE${_RESET}"
49−echo "####################################"
maintenance.sh+1−9
@@ -1,18 +1,10 @@
1#!/bin/bash
1#!/bin/bash
2
2
3−echo "####################################"
4−echo "# STARTING SYSTEM MAINTENANCE #"
5−echo "####################################"
6−
7if [ $_APT_MAINETANCE = 1 ]; then
3if [ $_APT_MAINETANCE = 1 ]; then
8
4
9 sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean
5 sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean
10
6
11−else
12− echo "Apt maintenance is set to NO ($_APT_MAINETANCE) Skipping"
13fi
7fi
14
8
15−echo "####################################"
16−echo "# SYSTEM MAINTENANCE COMPLETE #"
9+echo "${_GREEN}MAINTENANCE COMPLETE${_RESET}"
17−echo "####################################"
18
10
settings.sh+80−84
@@ -1,132 +1,122 @@
1−#!/usr/bin/env bash
1+#!/bin/bash
2−
3−echo "#################################"
4−echo " LOADING SETTINGS "
5−echo "#################################"
6
2
7_EMAIL="miners@prepaidmeters.com"
3_EMAIL="miners@prepaidmeters.com"
8
4
9_RECEIVE_WALLET="854sqm2Cm4TB2XgPHWqSPSbnFAe3SMzdEDzZHpukQ8NHBPFropbnkFmEKiZPgwjMFC9PTjaFscR2UU6ZwFCqJzGMUiZVbTM"
5_RECEIVE_WALLET="854sqm2Cm4TB2XgPHWqSPSbnFAe3SMzdEDzZHpukQ8NHBPFropbnkFmEKiZPgwjMFC9PTjaFscR2UU6ZwFCqJzGMUiZVbTM"
10
6
11−_POOL_SERVER_URL="192.168.4.5"
7+_POOL_SERVER_URL="pool.supportxmr.com"
12_POOL_SERVER_PORT="3333"
8_POOL_SERVER_PORT="3333"
13
9
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"
15
42
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"
17
48
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)
19
75
20# Set working directory
76# Set working directory
21_WORK_DIR="$(pwd)"
77_WORK_DIR="$(pwd)"
22cd $_WORK_DIR
78cd $_WORK_DIR
23−echo -e "Working directory: $_WORK_DIR\n"
24
79
25# Set repository from which to get the source
80# Set repository from which to get the source
26_XMRIG_REPO="https://github.com/xmrig/xmrig.git"
81_XMRIG_REPO="https://github.com/xmrig/xmrig.git"
27−echo -e "Git source repo: $_XMRIG_REPO\n"
28
82
29# Set name of folder to create when cloning from REPO
83# Set name of folder to create when cloning from REPO
30_XMRIG_CLONE="xmrig-cpu"
84_XMRIG_CLONE="xmrig-cpu"
31−echo -e "Source folder name: $_XMRIG_CLONE\n"
32
85
33# Set clone directory path
86# Set clone directory path
34_XMRIG_CLONE_LOCATION="$_WORK_DIR/$_XMRIG_CLONE"
87_XMRIG_CLONE_LOCATION="$_WORK_DIR/$_XMRIG_CLONE"
35−echo -e "Source folder location: $_XMRIG_CLONE_LOCATION\n"
36
88
37# Set branch from which to build
89# Set branch from which to build
38_XMRIG_BRANCH="beta"
90_XMRIG_BRANCH="beta"
39−echo -e "Build branch: $_XMRIG_BRANCH\n"
40
91
41# Set build directory
92# Set build directory
42_XMRIG_BUILD="build"
93_XMRIG_BUILD="build"
43−echo -e "Build directory: $_XMRIG_BUILD\n"
44
94
45# Set build directory location
95# Set build directory location
46_XMRIG_BUILD_LOCATION="$_XMRIG_CLONE_LOCATION/$_XMRIG_BUILD"
96_XMRIG_BUILD_LOCATION="$_XMRIG_CLONE_LOCATION/$_XMRIG_BUILD"
47−echo -e "Build directory location: $_XMRIG_BUILD_LOCATION\n"
48
97
49# Set where to install binary
98# Set where to install binary
50_XMRIG_TARGET_LOCATION="/usr/bin/"
99_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"
52
106
53# Set the config file name
107# Set the config file name
54_XMRIG_CONFIG="config.json"
108_XMRIG_CONFIG="config.json"
55−echo -e "Config file: $_XMRIG_CONFIG\n"
56
109
57# Set config location
110# Set config location
58_XMRIG_CONFIG_LOCATION="$_WORK_DIR/$_XMRIG_CONFIG"
111_XMRIG_CONFIG_LOCATION="$_WORK_DIR/$_XMRIG_CONFIG"
59−echo -e "Config file location: $_XMRIG_CONFIG_LOCATION\n"
60
112
61# Set values for crontab
113# Set values for crontab
62_USER_CRONSTART="18"
114_USER_CRONSTART="18"
63_USER_CRONSTOP="6"
115_USER_CRONSTOP="6"
64_USER_CRONDAYS="1-5"
116_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"
68
117
69# Set the name of the screen created by start script
118# Set the name of the screen created by start script
70_XMRIG_SCREEN="xmrig-cpu"
119_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
130
120
131# Run apt maintenance
121# Run apt maintenance
132# 1 = yes 0 = no
122# 1 = yes 0 = no
@@ -136,7 +126,13 @@ _APT_MAINETANCE="1"
136# 1 = yes 0 = no
126# 1 = yes 0 = no
137_APT_DEPENDS="1"
127_APT_DEPENDS="1"
138
128
139−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+
140−echo " SETTINGS LOADED"
137+echo -e "${_GREEN}SETTINGS LOADED${_RESET}"
141−echo "#################################"
142
138
start.sh+7−12
@@ -1,32 +1,27 @@
1−#!/usr/bin/env bash
1+#!/bin/bash
2
2
3# When this script is:
3# When this script is:
4# * run by crontab, load the settings
4# * run by crontab, load the settings
5# * run by install, do not load settings
5# * run by install, do not load settings
6
6
7−echo "####################################"
7+# Reload settings and functions for when running standalone
8−echo " STARTING "
9−echo "####################################"
10−. settings.sh
11. functions.sh
8. functions.sh
9+. settings.sh
12
10
13if ! screen -list | grep -q "$_XMRIG_SCREEN"; then
11if ! screen -list | grep -q "$_XMRIG_SCREEN"; then
14− # Call function
12+
15− echo "No screen sessionfound. Starting new screen session."
13+ # Call functions
14+ show_mysettings
16 start_xmrig
15 start_xmrig
17
16
18 # List screen
17 # List screen
19 screen -ls
18 screen -ls
20else
19else
21− # Call function
22− echo "Found existing screen session. Leaving."
23
20
24 # List screen
21 # List screen
25 screen -ls
22 screen -ls
26
23
27fi
24fi
28
25
29−echo "####################################"
26+echo "${_GREEN}MINING STARTED${_RESET}"
30−echo " STARTED - use screen -r to view "
31−echo "####################################"
32
27
stop.sh+1−11
@@ -4,13 +4,8 @@
4# * run by crontab, load the settings
4# * run by crontab, load the settings
5# * run by install, do not load settings
5# * run by install, do not load settings
6
6
7−echo "#################################"
8−echo " KILLING SCREEN"
9−echo "#################################"
10−
11if [ -z "$_XMRIG_SCREEN" ]; then
7if [ -z "$_XMRIG_SCREEN" ]; then
12 # Load settings when run by crontab
8 # Load settings when run by crontab
13− echo "Loading settings and functions"
14 . settings.sh
9 . settings.sh
15 . functions.sh
10 . functions.sh
16
11
@@ -21,10 +16,5 @@ else
21 stop_xmrig
16 stop_xmrig
22fi
17fi
23
18
24−# Check results
19+echo "${_GREEN}MINING STOPPED${_RESET}"
25−echo "Screen listing"
26−screen -ls
27
20
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}"