git.iko.soy/xmrig-bash-scripts
on master help sign in
.gitignore+3
since splitsnapshots
unifiedsplit
@@ -1,4 +1,7 @@
1xmrig-cpu/
1xmrig-cpu/
2*.swp
2*.swp
3crontab
3crontab
4+null
4config.json
5config.json
6+myconfig.json
7+mysettings.sh
README.md+18−17
@@ -11,6 +11,7 @@ A set of convenience scripts, written in bash, to help manage installation, conf
11There is allot to install so the install script will do most of the heavy lifting.
11There is allot to install so the install script will do most of the heavy lifting.
12At the start the expectation is that you have:
12At the start the expectation is that you have:
13* Computer running Ubuntu 18.04 (LTS)
13* Computer running Ubuntu 18.04 (LTS)
14+* Bash shell
14* User account with sudo privileges
15* User account with sudo privileges
15* Installed git
16* Installed git
16* Optionally installed [xmrig-proxy](https://github.com/xmrig/xmrig-proxy)
17* Optionally installed [xmrig-proxy](https://github.com/xmrig/xmrig-proxy)
@@ -21,38 +22,37 @@ Some knowledge of:
21* Linux Command Line Interface
22* Linux Command Line Interface
22* Linux shell `bash`
23* Linux shell `bash`
23
24
24−There is more to install but the install script will install the rest.
25−
26### Installation
25### Installation
27
26
281. Change to your user home directory.
271. Change to your user home directory.
29 `cd ~`
28 `cd ~`
30−
31−2. Install git.
29+1. Install git.
32 `sudo apt install git`
30 `sudo apt install git`
33−
34−3. Clone this project.
31+1. Clone this project.
35 `git clone https://github.com/seanwhe/xmrig-bash-scripts`
32 `git clone https://github.com/seanwhe/xmrig-bash-scripts`
36−
37−4. Change into the cloned directory.
33+1. Change into the cloned directory.
38 `cd xmrig-bash-scripts`
34 `cd xmrig-bash-scripts`
39−
40−5. Edit the settings file to your preference.
41− `vim settings.sh`
42−
43−6. Run the install script
35+1. Run the install script
44 `./install.sh`
36 `./install.sh`
45−
37+1. When prompted: "Enter your own settings?" enter 'y'es.
38+1. Enter values for your:
39+ 1. Pool server URL
40+ 1. Pool server TCP port
41+ 1. Receive wallet address
42+ 1. Email address
43+ 1. Miner identifier name
46−7. After install is complete. Attach to the screen session created during the installation.
44+1. After install is complete. Attach to the screen session created during the installation.
47 `screen -r`
45 `screen -r`
48
46
49### Operation
47### Operation
50
48
51Defaults - 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.
49Defaults - 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
50
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.
51+During install the folder source for [xmrig cpu](https://github.com/xmrig/xmrig) is cloned to `~/xmrig-bash-scripts/xmrig-cpu/`. The file `config.json`, used to configure xmrig, is also created in this path and is passed to xmrig at startup.
52+
53+During installation it is recomended to enter your own settings. This creates a file named 'mysettings.sh' which will not be overwritten during future installs or upgrades. Values for variables found in 'mysettings.sh' are used to create 'config.json'.
54
54
55−This should work out the box, if you edit only the top section of `settings.sh` and followed the steps here.
55+This should work out the box, if you follow the installation steps and enter your own values for 'mysettings.sh.
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
@@ -67,6 +67,7 @@ The scripts are designed to be modular to promote resuse, execute exclusion and
67* crontab-on.sh - redefines the users crontab as created during install.
67* crontab-on.sh - redefines the users crontab as created during install.
68* depends.sh - installs dependancies required by xmrig and these scripts.
68* depends.sh - installs dependancies required by xmrig and these scripts.
69* 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.
70+* input.sh - prompts to enter values for creating 'mysettings.sh'
70* install.sh - the main entry point when first installing.
71* install.sh - the main entry point when first installing.
71* maintenance.sh - performs apt update, upgrade, autoremove and autoclean operations.
72* maintenance.sh - performs apt update, upgrade, autoremove and autoclean operations.
72* settings.sh - contains variables used by these scripts.
73* settings.sh - contains variables used by these scripts.
build.sh+2−9
@@ -1,12 +1,9 @@
1#!/bin/bash
1#!/bin/bash
2
2
3−echo "#################################"
3+echo "${_GREEN}BUILD STARTED${_RESET}"
4−echo " BUILD STARTING"
5−echo "#################################"
6
4
7# Clone source
5# Clone source
8if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
6if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
9− echo "Clone already exists"
10
7
11 # Change to clone directory
8 # Change to clone directory
12 cd $_XMRIG_CLONE
9 cd $_XMRIG_CLONE
@@ -20,7 +17,6 @@ if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
20
17
21 else
18 else
22 # Switch to required branch
19 # Switch to required branch
23− echo "Require: $_XMRIG_BRANCH Switching !!!"
24 git checkout $_XMRIG_BRANCH
20 git checkout $_XMRIG_BRANCH
25
21
26 # Pull changes from source
22 # Pull changes from source
@@ -31,7 +27,6 @@ if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
31 fi
27 fi
32else
28else
33 # Clone the source
29 # Clone the source
34− echo "Cloning source to $_WORK_DIR/$_XMRIG_CLONE"
35 git clone $_XMRIG_REPO $_XMRIG_CLONE
30 git clone $_XMRIG_REPO $_XMRIG_CLONE
36
31
37 # Change to clone directory
32 # Change to clone directory
@@ -52,7 +47,5 @@ sudo cp $_XMRIG_BUILD_LOCATION/xmrig $_XMRIG_TARGET_LOCATION
52
47
53cd $_WORK_DIR
48cd $_WORK_DIR
54
49
55−echo "#################################"
50+echo "${_CYAN}BUILD STOPPED${_RESET}"
56−echo " BUILD COMPLETE"
57−echo "#################################"
58
51
config.sh+2−56
@@ -1,62 +1,8 @@
1#!/bin/bash
1#!/bin/bash
2
2
3−_API_ID="null"
3+echo "${_GREEN}CONFIG STARTED${_RESET}"
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
4
59echo "$_CONFIG_JSON" | tee config.json
5echo "$_CONFIG_JSON" | tee config.json
60
6
61−
7+echo "${_CYAN}CONFIG STOPPED${_RESET}"
62
8
crontab-off.sh+3−8
@@ -1,15 +1,12 @@
1#!/bin/bash
1#!/bin/bash
2
2
3+echo "${_GREEN}DISABLE CRONTAB STARTED${_RESET}"
4+
3# Removes a user crontab
5# Removes a user crontab
4# Used in conjunction with crontab-on.sh to toggle user crontab between states:
6# Used in conjunction with crontab-on.sh to toggle user crontab between states:
5# on - start/stop xmrig at specified times
7# on - start/stop xmrig at specified times
6# off - do not start/stop xmrig
8# off - do not start/stop xmrig
7
9
8−echo "#################################"
9−echo "# DISABLING CRONTAB #"
10−echo "#################################"
11−
12−
13# Remove existing crontab
10# Remove existing crontab
14echo "Backup existing crontab"
11echo "Backup existing crontab"
15crontab -l > crontab
12crontab -l > crontab
@@ -17,7 +14,5 @@ crontab -l > crontab
17echo "Removing exiting crontab"
14echo "Removing exiting crontab"
18crontab -r
15crontab -r
19
16
20−echo "#################################"
17+echo "${_CYAN}DISABLE CRONTAB STOPPED${_RESET}"
21−echo "# CRONTAB DISABLED #"
22−echo "#################################"
23
18
crontab-on.sh+3−7
@@ -1,14 +1,12 @@
1#!/bin/bash
1#!/bin/bash
2
2
3+echo "${_GREEN}ENABLE CRONTAB STARTED${_RESET}"
4+
3# Defines a user crontab with schedules as defined in settings.sh
5# 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:
6# Used in conjunction with crontab-off.sh to toggle user crontab between states:
5# on - start/stop xmrig at specified times
7# on - start/stop xmrig at specified times
6# off - do not start/stop xmrig
8# off - do not start/stop xmrig
7
9
8−echo "####################################"
9−echo "# ENABLING CRONTAB #"
10−echo "####################################"
11−
12# Get settings
10# Get settings
13. settings.sh
11. settings.sh
14. functions.sh
12. functions.sh
@@ -18,7 +16,5 @@ sleep 5
18. crontab.sh
16. crontab.sh
19sleep 5
17sleep 5
20
18
21−echo "####################################"
19+echo "${_CYAN}ENABLE CRONTAB STOPPED${_RESET}"
22−echo "# CRONTAB ENABLED #"
23−echo "####################################"
24
20
crontab.sh+4−12
@@ -1,30 +1,22 @@
1#!/bin/bash
1#!/bin/bash
2
2
3−# Set values in settings script
4
3
5−echo "#################################"
4+echo "${_GREEN}CRONTAB STARTED${_RESET}"
6−echo " UPDATING CRONTAB"
7−echo "#################################"
8
5
6+# Set values in settings script
9
7
10# Remove existing crontab
8# Remove existing crontab
11−echo "Backup existing crontab"
12crontab -l > crontab
9crontab -l > crontab
13
10
14−echo "Removing exiting crontab"
15crontab -r
11crontab -r
16
12
17# Setup users contab
13# Setup users contab
18−echo "Creating new crontab"
19
14
20−crontab -l | { cat; echo "#Start at $_USER_TIMESTART on days $_USER_CRONDAYS
15+crontab -l | { cat; echo "#Start at $_USER_CRONSTART on days $_USER_CRONDAYS
210 $_USER_CRONSTART * * $_USER_CRONDAYS screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION"; } | crontab -
160 $_USER_CRONSTART * * $_USER_CRONDAYS screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION"; } | crontab -
22
17
23crontab -l | { cat; echo "#Stop at $_USER_TIMESTOP on days $_USER_CRONDAYS
18crontab -l | { cat; echo "#Stop at $_USER_TIMESTOP on days $_USER_CRONDAYS
240 $_USER_CRONSTOP * * $_USER_CRONDAYS screen -S $_XMRIG_SCREEN -X kill"; } | crontab -
190 $_USER_CRONSTOP * * $_USER_CRONDAYS screen -S $_XMRIG_SCREEN -X kill"; } | crontab -
25
20
26−
21+echo "${_CYAN}CRONTAB STOPPED${_RESET}"
27−echo "#################################"
28−echo " CRONTAB UPDATED"
29−echo "#################################"
30
22
depends.sh+4−10
@@ -1,23 +1,17 @@
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
5+echo "${_GREEN}INSTALL DEPENDS STARTED${_RESET}"
6+
8−if [ $_APT_DEPENDS = 1 ]; then
7+if [ "$_APT_DEPENDS" -eq "1" ]; then
9
8
10 # Install xmrig depends
9 # Install xmrig depends
11 sudo apt install -y software-properties-common git build-essential cmake libuv1-dev libssl-dev libmicrohttpd-dev libhwloc-dev gcc g++
10 sudo apt install -y software-properties-common git build-essential cmake libuv1-dev libssl-dev libmicrohttpd-dev libhwloc-dev gcc g++
12
11
13 # Install xmrig-bash-scripts depends
12 # Install xmrig-bash-scripts depends
14 sudo apt install -y jo cpuid screen
13 sudo apt install -y jo cpuid screen
15−else
16−
17− echo "Depend install is set to NO ($_APT_DEPENDS) Skipping"
18
14
19fi
15fi
20
16
21−echo "#################################"
17+echo "${_CYAN}INSTALL DEPENDS STOPPED${_RESET}"
22−echo " DEPENDENCIES INSTALLED "
23−echo "#################################"
functions.sh+72−40
@@ -1,44 +1,80 @@
1−#!/usr/bin/env bash
1+#!/bin/bash
2+
3+echo -e "${_GREEN}LOADING FUNCTIONS${_RESET}"
4+
5+function prompt_confirm() {
6+ while true; do
7+ read -r -n 1 -p "${1:-Continue?} [y/n]: " REPLY
8+ case $REPLY in
9+ [yY]) echo ; return 0 ;;
10+ [nN]) echo ; return 1 ;;
11+ *) printf " \033[31m %s \n\033[0m" "invalid input [y/n]"
12+ esac
13+ done
14+}
15+
16+function show_settings () {
17+ echo "${_CYAN}Settings from loaded environment:${_RESET}"
18+ echo "${_GREEN}Pool URL:${_RESET}: $_POOLS_URL"
19+ echo "${_GREEN}Recieve Wallet:${_RESET}: $_POOLS_USER"
20+ echo "${_GREEN}Email Address:${_RESET}: $_POOLS_PASS"
21+}
22+
23+function show_mysettings () {
24+ if [ -f $_WORK_DIR/$_MYSETTINGS_FILE ]; then
25+ load_mysettings
26+ echo "${_CYAN}Settings from mysettings.sh:${_RESET}"
27+ echo "${_GREEN}Pool URL:${_RESET}: $_POOLS_URL"
28+ echo "${_GREEN}Recieve Wallet:${_RESET}: $_POOLS_USER"
29+ echo "${_GREEN}Email Address:${_RESET}: $_POOLS_PASS"
30+ fi
31+}
32+
33+function load_mysettings () {
34+ if [ -f $_WORK_DIR/$_MYSETTINGS_FILE ]; then
35+ . $_MYSETTINGS_FILE
36+ fi
37+}
38+
39+function my_config_json () {
2
40
41+ _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) opencl=$(jo enabled=$_OPENCL_ENABLED cache=$_OPENCL_CACHE loader=$_OPENCL_LOADER platform=$_OPENCL_PLATFORM) 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) log-file=$_LOG_FILE 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)
42+
43+}
44+
3−build_xmrig () {
45+function build_xmrig () {
4 if [ -d $_XMRIG_BUILD_LOCATION ]; then
46 if [ -d $_XMRIG_BUILD_LOCATION ]; then
5 # Remove existing build directory
47 # Remove existing build directory
6− echo "Found old build directory. Removing"
7 rm -rf $_XMRIG_BUILD_LOCATION
48 rm -rf $_XMRIG_BUILD_LOCATION
8
49
9 # Make new build directory
50 # Make new build directory
10− echo "Creating a build directory"
11 mkdir $_XMRIG_BUILD_LOCATION
51 mkdir $_XMRIG_BUILD_LOCATION
12 else
52 else
13 # Make new build directory
53 # Make new build directory
14− echo "Creating a build directory"
15 mkdir $_XMRIG_BUILD_LOCATION
54 mkdir $_XMRIG_BUILD_LOCATION
16 fi
55 fi
17
56
18 # Change to build directory
57 # Change to build directory
19− echo "Changing to build directory"
20 cd $_XMRIG_BUILD_LOCATION
58 cd $_XMRIG_BUILD_LOCATION
21
59
22 # Configure cmake scafolding
60 # Configure cmake scafolding
23− echo "Configuring cmake scafolding"
61+ cmake ..
24− cmake .. -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7
25
62
26 # Compile the software
63 # Compile the software
27− echo "Starting build"
28 make
64 make
29}
65}
30
66
31
67
32−start_xmrig () {
68+function start_xmrig () {
33 screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
69 screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
34}
70}
35
71
36
72
37−stop_xmrig () {
73+function stop_xmrig () {
38 screen -S $_XMRIG_SCREEN -X kill
74 screen -S $_XMRIG_SCREEN -X kill
39}
75}
40
76
41−check_cpu () {
77+function check_cpu () {
42 # Check if CPU supports AES-NI
78 # Check if CPU supports AES-NI
43 cpuid | grep -i aes > hw-aes.txt
79 cpuid | grep -i aes > hw-aes.txt
44 if grep -q true "hw-aes.txt"; then
80 if grep -q true "hw-aes.txt"; then
@@ -50,44 +86,40 @@ check_cpu () {
50
86
51 # Get number of available CPU Cores
87 # Get number of available CPU Cores
52 _ENV_CORE=$(nproc --all)
88 _ENV_CORE=$(nproc --all)
53− echo -e "CPU Cores: $_ENV_CORE\n"
54
89
55 # Get CPU L3 cache value
90 # Get CPU L3 cache value
56 _ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
91 _ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
57− echo -e "L3 Cache in byte: $_ENV_CORE_L3\n"
58}
92}
59
93
60−calc_threads () {
94+function calc_threads () {
61−
95+ # Each thread needs 2048 byte (2 Megabyte)
62− # Affine number of threads for _CPU_CN
96+ # Calculate number of threads supported with L3 cache size
63− _COUNTER="$(($_ENV_CORE_THREADS - 1))"
64− _ENV_CPU_THREADS=()
65
97
66− for i in `seq 0 $_COUNTER`; do
98+ _ENV_THREAD_QTY=$(( ($_ENV_CORE_L3/2048)/1000 ))
67− _ENV_CPU_THREADS+=("$i")
68− done
69
99
70− echo "Thread CPU Affinity: ${_ENV_CPU_THREADS[@]}"
100+ # Affine number of threads for _CPU_CN
71− _ENV_CPU_THREAD_AFFINITY="${_ENV_CPU_THREADS[@]}"
101+ _COUNTER="$(( $_ENV_THREAD_QTY-1 ))"
72
102
73− # Setting according to cpu cores but xmrig will not use all
103+ _ENV_CPU_THREAD_AFFINITY="$(seq -s " " 0 $_COUNTER)"
74− # change to make value use _ENV_CORE_THREADS
75− # Check that hugepages set in /etc/sysctl.conf
76− _ENV_CHECK="nr_hugepages"
77
104
78− if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
105+}
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
82− 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"
86− sudo sysctl -p
87
106
88− # Add value to sysctl
107+function calc_hugepages () {
89− echo "vm.nr_hugepages=$_ENV_CORE" | sudo tee -a /etc/sysctl.conf
108+ # Setting according to cpu cores but xmrig will not use all
109+ # change to make value use _ENV_CORE_THREADS
110+ # Check that hugepages set in /etc/sysctl.conf
111+
112+ _ENV_CHECK="nr_hugepages"
113+
114+ if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
115+ sudo sysctl -p
116+ else
117+ # Set value in current env
118+ sudo sysctl -w vm.nr_hugepages="$_ENV_THREAD_QTY"
119+ # Add value to sysctl
120+ sudo sysctl -p
90− fi
121+ fi
91
122
92}
123}
93
124
125+echo -e "${_CYAN}FUNCTIONS LOADED${_RESET}"
input.shnew file+61
@@ -0,0 +1,61 @@
1+#!/bin/bash
2+
3+# Ask user questions
4+# Capture input
5+# if setting already exist use existing
6+
7+echo -e "${_GREEN}USER SETTINGS STARTED${_RESET}"
8+
9+if [ -f $_WORK_DIR/$_MYSETTINGS_FILE ]; then
10+
11+ # Call function
12+
13+ load_mysettings
14+
15+ my_config_json
16+
17+else
18+ echo -e " ${_YELLOW}Opt for default settings or enter your own.\n"
19+
20+ echo -e " No - 'config.json' created with values from 'settings.sh'."
21+ echo -e " Yes - 'config.json' created with values from 'mysettings.sh' (recomended).\n"
22+
23+ echo -e " When 'mysettings.sh' exists this prompt will be skipped at furture installation."
24+ echo -e " Own settings is recomended to avoid your settings being overidden in upgrades.${_RESET}\n"
25+
26+
27+ prompt_confirm "Enter your own settings?"
28+
29+ if [ "$?" -eq 0 ]; then
30+
31+ # Create a file
32+
33+ touch $_MYSETTINGS_FILE_LOCATION
34+ chmod +x $_MYSETTINGS_FILE_LOCATION
35+ echo "#!/bin/bash" > $_MYSETTINGS_FILE_LOCATION
36+
37+ # Prompt user input
38+
39+ echo "Current pool URL: $_POOLS_URL"
40+ read -p "Enter new pool URL: " _POOLS_URL
41+ echo "_POOLS_URL=\"$_POOLS_URL\"" >> $_MYSETTINGS_FILE_LOCATION
42+
43+ echo "Current Receive Wallet address: $_POOLS_USER"
44+ read -p "Enter new Receive Wallet address: " _POOLS_USER
45+ echo "_POOLS_USER=\"$_POOLS_USER\"" >> $_MYSETTINGS_FILE_LOCATION
46+
47+ echo "Current email address: $_POOLS_PASS"
48+ read -p "Enter new email address: " _POOLS_PASS
49+ echo "_POOLS_PASS=\"$_POOLS_PASS\"" >> $_MYSETTINGS_FILE_LOCATION
50+
51+ fi
52+
53+ # Call function
54+
55+ load_mysettings
56+
57+ my_config_json
58+
59+fi
60+
61+echo "${_CYAN}USER SETTINGS STOPPED${_RESET}"
install.sh+30−16
@@ -1,7 +1,26 @@
1#!/bin/bash
1#!/bin/bash
2
2
3−# Set that user passwdless sudo
4
3
4+# Colors
5+_CYAN=`tput setaf 1`
6+_GREEN=`tput setaf 2`
7+_YELLOW=`tput setaf 3`
8+_BLUE=`tput setaf 4`
9+_MAGENTA=`tput setaf 5`
10+_CYAN=`tput setaf 6`
11+_RESET=`tput sgr0`
12+
13+echo "${_GREEN}INSTALLATION STARTED${_RESET}"
14+
15+_DEBUG=$1
16+
17+if $_DEBUG; then
18+ set +x
19+else
20+ set -x
21+fi
22+
23+# Set that user passwdless sudo
5if sudo grep -q $USER /etc/sudoers.d/README; then
24if sudo grep -q $USER /etc/sudoers.d/README; then
6 echo -e "User $USER found in /etc/sudoers.d/README. All good!!\n"
25 echo -e "User $USER found in /etc/sudoers.d/README. All good!!\n"
7else
26else
@@ -9,32 +28,29 @@ else
9 echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/README
28 echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/README
10fi
29fi
11
30
31+# Load functions
32+. functions.sh
33+
12# Get settings
34# Get settings
13. settings.sh
35. settings.sh
14−sleep 5
15−
16−# Stop running instance
17−. stop.sh
18
36
19# Update system
37# Update system
20. maintenance.sh
38. maintenance.sh
21−sleep 5
22
39
23# Install dependencies
40# Install dependencies
24. depends.sh
41. depends.sh
25−sleep 5
42+
43+# User input
44+. input.sh
45+
46+# Stop running instance
47+. stop.sh
26
48
27# Get source and build by sourcing our build file
49# Get source and build by sourcing our build file
28. build.sh
50. build.sh
29−sleep 5
30
51
31# Create a config.json
52# Create a config.json
32. config.sh
53. config.sh
33−sleep 5
34−
35−# Setup crontab for user
36−. crontab.sh
37−sleep 5
38
54
39# Unset REPO variable so start script will execute program
55# Unset REPO variable so start script will execute program
40SCREEN=""
56SCREEN=""
@@ -43,6 +59,4 @@ SCREEN=""
43. start.sh
59. start.sh
44
60
45
61
46−echo "####################################"
62+echo -e "${_CYAN}INSTALLATION COMPLETED${_RESET}"
47−echo "# ALL DONE - INSTALLATION COMPLETE #"
48−echo "####################################"
maintenance.sh+3−9
@@ -1,18 +1,12 @@
1#!/bin/bash
1#!/bin/bash
2
2
3−echo "####################################"
3+echo "${_GREEN}MAINTENANCE STARTED${_RESET}"
4−echo "# STARTING SYSTEM MAINTENANCE #"
5−echo "####################################"
6
4
7−if [ $_APT_MAINETANCE = 1 ]; then
5+if [ "$_APT_MAINETANCE" -eq "1" ]; then
8
6
9 sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean
7 sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean
10
8
11−else
12− echo "Apt maintenance is set to NO ($_APT_MAINETANCE) Skipping"
13fi
9fi
14
10
15−echo "####################################"
11+echo "${_CYAN}MAINTENANCE STOPPED${_RESET}"
16−echo "# SYSTEM MAINTENANCE COMPLETE #"
17−echo "####################################"
18
12
settings.sh+85−39
@@ -1,83 +1,130 @@
1−#!/usr/bin/env bash
1+#!/bin/bash
2
2
3−echo "#################################"
4−echo " LOADING SETTINGS "
3+echo -e "${_GREEN}LOADING DEFAULT SETTINGS${_RESET}"
5−echo "#################################"
6
4
7−_EMAIL="miners@prepaidmeters.com"
5+_EMAIL="spam@iko.soy"
8
6
9−_RECEIVE_WALLET="854sqm2Cm4TB2XgPHWqSPSbnFAe3SMzdEDzZHpukQ8NHBPFropbnkFmEKiZPgwjMFC9PTjaFscR2UU6ZwFCqJzGMUiZVbTM"
7+_RECEIVE_WALLET="44FADBDhNRvjJszF5mLS4VCwZ71mY7ftfUErEisPoT724hb5eYuvuFqWthniY8dGPBTcWuBoeLrLJVkxLHCb1Lsd4DdbZzZ"
10
8
11−_POOL_SERVER_URL="192.168.4.5"
9+_POOL_SERVER_URL="xmrpool.eu"
12−_POOL_SERVER_PORT="3333"
10+_POOL_SERVER_PORT="5555"
13
11
14−#####################################################################
12+# Call function
13+show_settings
15
14
15+#######################################################################
16−# DO NOT CHANGE AFTER THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING
16+# DO NOT CHANGE AFTER THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING #
17+#######################################################################
17
18
18−#####################################################################
19+_API_ID='null'
20+_API_WORKER_ID="$HOSTNAME"
19
21
20−# Load functions
22+_AUTOSAVE="true"
21−. functions.sh
23+
24+_BACKGROUND="false"
25+
26+_COLORS="true"
27+
28+# call check_cpu
29+check_cpu
30+
31+# call calc_threads
32+calc_threads
33+
34+_CPU_ENABLED="true"
35+_CPU_HUGE_PAGES="true"
36+_CPU_HW_AES="$_AES_NI"
37+_CPU_PRIORITY='null'
38+_CPU_ASM="true"
39+_CPU_CN="$_ENV_CPU_THREAD_AFFINITY"
40+
41+_CPU_CN_0="false"
42+_CPU_CN_LITE_0="false"
43+
44+_OPENCL_ENABLED="false"
45+_OPENCL_CACHE="true"
46+_OPENCL_LOADER='null'
47+_OPENCL_PLATFORM="AMD"
48+
49+_DONATE_LEVEL="0"
50+
51+_DONATE_OVER_PROXY="1"
52+
53+_HTTP_ENABLED="true"
54+_HTTP_HOST=$(hostname --all-ip-addresses | awk '{print $1}')
55+_HTTP_PORT="8080"
56+_HTTP_ACCESS_TOKEN='null'
57+_HTTP_RESTRICTED="false"
58+
59+_LOG_FILE='null'
60+
61+_POOLS_ALGO="cn/r"
62+_POOLS_URL="$_POOL_SERVER_URL:$_POOL_SERVER_PORT"
63+_POOLS_USER="$_RECEIVE_WALLET"
64+_POOLS_PASS="$HOSTNAME:$_EMAIL"
65+_POOLS_RIG_ID="$HOSTNAME"
66+_POOLS_NICEHASH="true"
67+_POOLS_KEEPALIVE="true"
68+_POOLS_ENABLED="true"
69+_POOLS_TLS='null'
70+_POOLS_TLS_FINDERPRINT='null'
71+_POOLS_DAEMON="false"
72+
73+_PRINT_TIME="30"
74+
75+_RETRIES="5"
76+_RETRIES_PAUSE="5"
77+
78+_SYSLOG="false"
79+
80+_USER_AGENT='null'
81+
82+_WATCH="true"
22
83
23# Set working directory
84# Set working directory
24_WORK_DIR="$(pwd)"
85_WORK_DIR="$(pwd)"
25cd $_WORK_DIR
86cd $_WORK_DIR
26−echo -e "Working directory: $_WORK_DIR\n"
27
87
28# Set repository from which to get the source
88# Set repository from which to get the source
29_XMRIG_REPO="https://github.com/xmrig/xmrig.git"
89_XMRIG_REPO="https://github.com/xmrig/xmrig.git"
30−echo -e "Git source repo: $_XMRIG_REPO\n"
31
90
32# Set name of folder to create when cloning from REPO
91# Set name of folder to create when cloning from REPO
33_XMRIG_CLONE="xmrig-cpu"
92_XMRIG_CLONE="xmrig-cpu"
34−echo -e "Source folder name: $_XMRIG_CLONE\n"
35
93
36# Set clone directory path
94# Set clone directory path
37_XMRIG_CLONE_LOCATION="$_WORK_DIR/$_XMRIG_CLONE"
95_XMRIG_CLONE_LOCATION="$_WORK_DIR/$_XMRIG_CLONE"
38−echo -e "Source folder location: $_XMRIG_CLONE_LOCATION\n"
39
96
40# Set branch from which to build
97# Set branch from which to build
41−_XMRIG_BRANCH="beta"
98+_XMRIG_BRANCH="master"
42−echo -e "Build branch: $_XMRIG_BRANCH\n"
43
99
44# Set build directory
100# Set build directory
45_XMRIG_BUILD="build"
101_XMRIG_BUILD="build"
46−echo -e "Build directory: $_XMRIG_BUILD\n"
47
102
48# Set build directory location
103# Set build directory location
49_XMRIG_BUILD_LOCATION="$_XMRIG_CLONE_LOCATION/$_XMRIG_BUILD"
104_XMRIG_BUILD_LOCATION="$_XMRIG_CLONE_LOCATION/$_XMRIG_BUILD"
50−echo -e "Build directory location: $_XMRIG_BUILD_LOCATION\n"
51
105
52# Set where to install binary
106# Set where to install binary
53_XMRIG_TARGET_LOCATION="/usr/bin/"
107_XMRIG_TARGET_LOCATION="/usr/bin/"
54−echo -e "Install path: $_XMRIG_TARGET_LOCATION\n"
108+
109+# Set mysettings file
110+_MYSETTINGS_FILE="mysettings.sh"
111+
112+# Set mysettings file location
113+_MYSETTINGS_FILE_LOCATION="$_WORK_DIR/$_MYSETTINGS_FILE"
55
114
56# Set the config file name
115# Set the config file name
57_XMRIG_CONFIG="config.json"
116_XMRIG_CONFIG="config.json"
58−echo -e "Config file: $_XMRIG_CONFIG\n"
59
117
60# Set config location
118# Set config location
61_XMRIG_CONFIG_LOCATION="$_WORK_DIR/$_XMRIG_CONFIG"
119_XMRIG_CONFIG_LOCATION="$_WORK_DIR/$_XMRIG_CONFIG"
62−echo -e "Config file location: $_XMRIG_CONFIG_LOCATION\n"
63
120
64# Set values for crontab
121# Set values for crontab
65−_USER_CRONSTART="18"
122+_USER_CRONSTART="17"
66−_USER_CRONSTOP="6"
123+_USER_CRONSTOP="8"
67_USER_CRONDAYS="1-5"
124_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"
71
125
72# Set the name of the screen created by start script
126# Set the name of the screen created by start script
73_XMRIG_SCREEN="xmrig-cpu"
127_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
81
128
82# Run apt maintenance
129# Run apt maintenance
83# 1 = yes 0 = no
130# 1 = yes 0 = no
@@ -87,7 +134,6 @@ _APT_MAINETANCE="1"
87# 1 = yes 0 = no
134# 1 = yes 0 = no
88_APT_DEPENDS="1"
135_APT_DEPENDS="1"
89
136
90−echo "#################################"
137+
91−echo " SETTINGS LOADED"
138+echo -e "${_CYAN}DEFAULT SETTINGS LOADED${_RESET}"
92−echo "#################################"
93
139
start.sh+47−20
@@ -1,32 +1,59 @@
1−#!/usr/bin/env bash
1+#!/bin/bash
2+
3+echo "${_GREEN}MINING STARTED${_RESET}"
2
4
3# When this script is:
5# When this script is:
4# * run by crontab, load the settings
6# * run by crontab, load the settings
5# * run by install, do not load settings
7# * run by install, do not load settings
6
8
7−echo "####################################"
9+# Reload settings and functions for when running standalone
8−echo " STARTING "
9−echo "####################################"
10−. settings.sh
11. functions.sh
10. functions.sh
11+. settings.sh
12
12
13−if ! screen -list | grep -q "$_XMRIG_SCREEN"; then
13+# if ! screen -list | grep -q "$_XMRIG_SCREEN"; then
14− # Call function
14+
15− echo "No screen sessionfound. Starting new screen session."
15+ # Call functions
16+ show_settings
17+ show_mysettings
16− start_xmrig
18+ # start_xmrig
17
19
18 # List screen
20 # List screen
19− screen -ls
21+ # screen -ls
20−else
22+# else
21− # Call function
22− echo "Found existing screen session. Leaving."
23
23
24 # List screen
24 # List screen
25− screen -ls
25+ # screen -ls
26−
26+
27−fi
27+# fi
28−
28+echo "[Unit]" | sudo tee /etc/systemd/system/xmrig.service
29−echo "####################################"
29+echo "Description=XMRIG service" | sudo tee -a /etc/systemd/system/xmrig.service
30−echo " STARTED - use screen -r to view "
30+echo "After=network.target" | sudo tee -a /etc/systemd/system/xmrig.service
31−echo "####################################"
31+echo "StartLimitIntervalSec=0" | sudo tee -a /etc/systemd/system/xmrig.service
32+echo "[Service]" | sudo tee -a /etc/systemd/system/xmrig.service
33+echo "Type=simple" | sudo tee -a /etc/systemd/system/xmrig.service
34+echo "Restart=always" | sudo tee -a /etc/systemd/system/xmrig.service
35+echo "RestartSec=3" | sudo tee -a /etc/systemd/system/xmrig.service
36+echo "User=root" | sudo tee -a /etc/systemd/system/xmrig.service
37+echo "ExecStart=$_XMRIG_BUILD_LOCATION/xmrig --config=$_XMRIG_CONFIG_LOCATION" | sudo tee -a /etc/systemd/system/xmrig.service
38+echo "" | sudo tee -a /etc/systemd/system/xmrig.service
39+echo "[Install]" | sudo tee -a /etc/systemd/system/xmrig.service
40+echo "WantedBy=multi-user.target" | sudo tee -a /etc/systemd/system/xmrig.service
41+
42+echo "STARTING XMRIG/SERVICES"
43+
44+sudo service logrotate start
45+sudo service ntp start
46+sudo service xmrig start
47+
48+echo "STARTING XMRIG/SERVICES @ BOOT"
49+
50+sudo systemctl enable logrotate
51+sudo systemctl enable ntp
52+sudo systemctl enable xmrig
53+
54+echo "${_CYAN}MINING RUNNING${_RESET}"
55+echo "${_YELLOW} The process is running in a screen session."
56+echo "${_YELLOW} The screen session is named:${_RESET} $_XMRIG_SCREEN"
57+echo "${_YELLOW} Command to view process:${_RESET} screen -r $_XMRIG_SCREEN"
58+echo "${_MAGENTA} ENJOY!!!${_RESET}"
32
59
stop.sh+2−10
@@ -4,13 +4,10 @@
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+echo "${_GREEN}END MINING STARTED${_RESET}"
8−echo " KILLING SCREEN"
9−echo "#################################"
10
8
11if [ -z "$_XMRIG_SCREEN" ]; then
9if [ -z "$_XMRIG_SCREEN" ]; then
12 # Load settings when run by crontab
10 # Load settings when run by crontab
13− echo "Loading settings and functions"
14 . settings.sh
11 . settings.sh
15 . functions.sh
12 . functions.sh
16
13
@@ -21,10 +18,5 @@ else
21 stop_xmrig
18 stop_xmrig
22fi
19fi
23
20
24−# Check results
21+echo "${_CYAN}END MINING STOPPED${_RESET}"
25−echo "Screen listing"
26−screen -ls
27
22
28−echo "#################################"
29−echo " SCREEN KILLED"
30−echo "#################################"
update.sh+4
@@ -1,7 +1,11 @@
1#!/bin/bash
1#!/bin/bash
2
2
3+echo "${_GREEN}UPDATE STARTED${_RESET}"
4+
3git pull
5git pull
4
6
5# install
7# install
6. install.sh
8. install.sh
7sleep 5
9sleep 5
10+
11+echo "${_CYAN}UPDATE COMPLETE${_RESET}"