git.iko.soy/xmrig-bash-scripts
on master help sign in
Merge branch 'master' into develop
commit3cfa2d1cc708e1eb145cf4540ff93693358fcdc4 authorSean Wheller <sean@prepaidmeters.com> dateSat 27 Jul 2019, 02:20 (7 years ago) parenteefe51d07a3b08
9 files changed+431
.gitignore+3 build.sh+80 config.json+105 crontab.sh+29 install.sh+27 settings.sh+93 start.sh+40 stop.sh+33 update.sh+21
.gitignorenew file+3
@@ -0,0 +1,3 @@
1+xmrig-cpu/
2+*.swp
3+crontab
build.shnew file+80
@@ -0,0 +1,80 @@
1+#!/bin/bash
2+
3+build_xmrig () {
4+ if [ -d $_XMRIG_BUILD_LOCATION ]; then
5+ # Remove existing build directory
6+ echo "Found old build directory. Removing"
7+ rm -rf $_XMRIG_BUILD_LOCATION
8+
9+ # Make new build directory
10+ echo "Creating a build directory"
11+ mkdir $_XMRIG_BUILD_LOCATION
12+ else
13+ # Make new build directory
14+ echo "Creating a build directory"
15+ mkdir $_XMRIG_BUILD_LOCATION
16+ fi
17+
18+ # Change to build directory
19+ echo "Changing to build directory"
20+ cd $_XMRIG_BUILD_LOCATION
21+
22+ # Configure cmake scafolding
23+ echo "Configuring cmake scafolding"
24+ cmake .. -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7
25+
26+ # Compile the software
27+ echo "Starting build"
28+ make
29+}
30+
31+echo "#################################"
32+echo " BUILD STARTING"
33+echo "#################################"
34+
35+# Update system
36+sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean
37+
38+# Install the software requirements
39+sudo apt install -y screen software-properties-common git build-essential cmake libuv1-dev libssl-dev libmicrohttpd-dev gcc g++
40+
41+# Clone source
42+if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
43+ echo "Clone already exists"
44+
45+ # Change to clone directory
46+ cd $_XMRIG_CLONE
47+
48+ # Pull changes from source
49+ git pull
50+
51+ # Call function
52+ build_xmrig
53+
54+else
55+ # Clone the source
56+ echo "Cloning source to $_WORK_DIR/$_XMRIG_CLONE"
57+ git clone $_XMRIG_REPO $_XMRIG_CLONE
58+
59+ # Change to clone directory
60+ cd $_XMRIG_CLONE
61+
62+ # Fetch list of branches in origin
63+ git branch -a
64+
65+ # Checkout required branch
66+ git checkout $_XMRIG_BRANCH
67+
68+ # Call function
69+ build_xmrig
70+fi
71+
72+# Copy binary to directory in env path
73+sudo cp $_XMRIG_BUILD_LOCATION/xmrig $_XMRIG_TARGET_LOCATION
74+
75+cd $_WORK_DIR
76+
77+echo "#################################"
78+echo " BUILD COMPLETE"
79+echo "#################################"
80+
config.jsonnew file+105
@@ -0,0 +1,105 @@
1+{
2+ "api": {
3+ "id": null,
4+ "worker-id": "sean-wks"
5+ },
6+ "autosave": true,
7+ "background": false,
8+ "colors": true,
9+ "cpu": {
10+ "enabled": true,
11+ "huge-pages": true,
12+ "hw-aes": null,
13+ "priority": null,
14+ "asm": true,
15+ "cn": [
16+ -1,
17+ -1,
18+ -1,
19+ -1
20+ ],
21+ "cn-heavy": [
22+ -1,
23+ -1
24+ ],
25+ "cn-lite": [
26+ -1,
27+ -1,
28+ -1,
29+ -1,
30+ -1,
31+ -1,
32+ -1,
33+ -1
34+ ],
35+ "cn-pico": [
36+ -1,
37+ -1,
38+ -1,
39+ -1,
40+ -1,
41+ -1,
42+ -1,
43+ -1
44+ ],
45+ "cn/gpu": [
46+ -1,
47+ -1,
48+ -1,
49+ -1,
50+ -1,
51+ -1,
52+ -1,
53+ -1
54+ ],
55+ "rx": [
56+ -1,
57+ -1,
58+ -1,
59+ -1
60+ ],
61+ "rx/wow": [
62+ -1,
63+ -1,
64+ -1,
65+ -1,
66+ -1,
67+ -1,
68+ -1,
69+ -1
70+ ],
71+ "cn/0": false,
72+ "cn-lite/0": false
73+ },
74+ "donate-level": 5,
75+ "donate-over-proxy": 1,
76+ "http": {
77+ "enabled": false,
78+ "host": "127.0.0.1",
79+ "port": 0,
80+ "access-token": null,
81+ "restricted": true
82+ },
83+ "log-file": null,
84+ "pools": [
85+ {
86+ "algo": null,
87+ "url": "192.168.4.5:3333",
88+ "user": "854sqm2Cm4TB2XgPHWqSPSbnFAe3SMzdEDzZHpukQ8NHBPFropbnkFmEKiZPgwjMFC9PTjaFscR2UU6ZwFCqJzGMUiZVbTM",
89+ "pass": "sean-wks:miners@prepaidmeters.com",
90+ "rig-id": "sean-wks",
91+ "nicehash": true,
92+ "keepalive": true,
93+ "enabled": true,
94+ "tls": false,
95+ "tls-fingerprint": null,
96+ "daemon": false
97+ }
98+ ],
99+ "print-time": 30,
100+ "retries": 5,
101+ "retry-pause": 5,
102+ "syslog": false,
103+ "user-agent": null,
104+ "watch": true
105+}
crontab.shnew file+29
@@ -0,0 +1,29 @@
1+#!/bin/bash
2+
3+# Set values in settings script
4+
5+echo "#################################"
6+echo " UPDATING CRONTAB"
7+echo "#################################"
8+
9+
10+# Remove existing crontab
11+echo "Backup existing crontab"
12+crontab -l > crontab
13+
14+echo "Removing exiting crontab"
15+crontab -r
16+
17+# Setup users contab
18+crontab -l | { cat; echo "#Start at $_USER_TIMESTART on days $_USER_CRONDAYS
19+0 $_USER_CRONSTART * * $_USER_CRONDAYS $_WORK_DIR/start.sh"; } | crontab -
20+
21+crontab -l | { cat; echo "#Stop at $_USER_TIMESTOP on days $_USER_CRONDAYS
22+0 $_USER_CRONSTOP * * $_USER_CRONDAYS $_WORK_DIR/stop.sh"; } | crontab -
23+
24+crontab -l
25+
26+echo "#################################"
27+echo " CRONTAB UPDATED"
28+echo "#################################"
29+
install.shnew file+27
@@ -0,0 +1,27 @@
1+#!/bin/bash
2+
3+# Get settings
4+. settings.sh
5+sleep 5
6+
7+# Stop running instance
8+. stop.sh
9+
10+# Get source and build by sourcing our build file
11+. build.sh
12+sleep 5
13+
14+# Setup crontab for user
15+. crontab.sh
16+sleep 5
17+
18+# Unset REPO variable so start script will execute program
19+SCREEN=""
20+
21+# Start mining
22+. start.sh
23+
24+
25+echo "####################################"
26+echo "# ALL DONE - INSTALLATION COMPLETE #"
27+echo "####################################"
settings.shnew file+93
@@ -0,0 +1,93 @@
1+#!/bin/bash
2+
3+echo "#################################"
4+echo " LOADING SETTINGS "
5+echo "#################################"
6+
7+# Set working directory
8+_WORK_DIR="$(pwd)"
9+cd $_WORK_DIR
10+echo -e "Working directory: $_WORK_DIR\n"
11+
12+# Set repository from which to get the source
13+_XMRIG_REPO="https://github.com/xmrig/xmrig.git"
14+echo -e "Git source repo: $_XMRIG_REPO\n"
15+
16+# Set name of folder to create when cloning from REPO
17+_XMRIG_CLONE="xmrig-cpu"
18+echo -e "Source folder name: $_XMRIG_CLONE\n"
19+
20+# Set clone directory path
21+_XMRIG_CLONE_LOCATION="$_WORK_DIR/$_XMRIG_CLONE"
22+echo -e "Source folder location: $_XMRIG_CLONE_LOCATION\n"
23+
24+# Set branch from which to build
25+_XMRIG_BRANCH="beta"
26+echo -e "Build branch: $_XMRIG_BRANCH\n"
27+
28+# Set build directory
29+_XMRIG_BUILD="build"
30+echo -e "Build directory: $_XMRIG_BUILD\n"
31+
32+# Set build directory location
33+_XMRIG_BUILD_LOCATION="$_XMRIG_CLONE_LOCATION/$_XMRIG_BUILD"
34+echo -e "Build directory location: $_XMRIG_BUILD_LOCATION\n"
35+
36+# Set where to install binary
37+_XMRIG_TARGET_LOCATION="/usr/bin/"
38+echo -e "Install path: $_XMRIG_TARGET_LOCATION\n"
39+
40+# Set the config file name
41+_XMRIG_CONFIG="config.json"
42+echo -e "Config file: $_XMRIG_CONFIG\n"
43+
44+# Set config location
45+_XMRIG_CONFIG_LOCATION="$_WORK_DIR/$_XMRIG_CONFIG"
46+echo -e "Config file location: $_XMRIG_CONFIG_LOCATION\n"
47+
48+# Set values for crontab
49+_USER_CRONSTART="18"
50+_USER_CRONSTOP="6"
51+_USER_CRONDAYS="1-5"
52+echo -e "Cron job start: $_USER_CRONSTART\n"
53+echo -e "Cron job stop: $_USER_CRONSTOP\n"
54+echo -e "Cron on days: $_USER_CRONDAYS\n"
55+
56+# Set the name of the screen created by start script
57+_XMRIG_SCREEN="xmrig-cpu"
58+echo -e "Screen session name: $_XMRIG_SCREEN\n"
59+
60+# Get number of available CPU Cores
61+_ENV_CORE=$(nproc --all)
62+echo -e "CPU Cores: $_ENV_CORE\n"
63+
64+# Set that user passwdless sudo
65+#sudo grep $USER /etc/sudoers.d/README
66+
67+if sudo grep -q $USER /etc/sudoers.d/README; then
68+ echo -e "User $USER found in /etc/sudoers.d/README. All good!!\n"
69+else
70+ echo -e "$USER does not have passwdles sudo. Fixing that!!\n"
71+ echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/README
72+fi
73+
74+# Check that hugepages set in /etc/sysctl.conf
75+_ENV_CHECK="nr_hugepages"
76+
77+if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
78+ echo "Found nr_hugepages in /etc/sysctl.conf. All good!!"
79+ echo -e "Refreshing sysctl configuration just to be sure.\n"
80+ sudo sysctl -p
81+else
82+ # Set value in current env
83+ echo -e "Did not find nr_hugepages in /etc/sysctl.conf. Fixing that!!\n"
84+ sudo sysctl -w vm.nr_hugepages="$_ENV_CORE"
85+
86+ # Add value to sysctl
87+ echo "vm.nr_hugepages=$_ENV_CORE" | sudo tee -a /etc/sysctl.conf
88+fi
89+
90+echo "#################################"
91+echo " SETTINGS LOADED"
92+echo "#################################"
93+
start.shnew file+40
@@ -0,0 +1,40 @@
1+#!/bin/bash
2+
3+# When this script is:
4+# * run by crontab, load the settings
5+# * run by install, do not load settings
6+
7+start_xmrig () {
8+ screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
9+}
10+
11+echo "####################################"
12+echo " STARTING "
13+echo "####################################"
14+
15+if [ -z "$_XMRIG_SCREEN" ]; then
16+ # Load settings when run by crontab
17+ # Also ensures vm.nr_hugepages is set
18+ . settings.sh
19+
20+ # Check another instance is not already running
21+ if ! screen -list | grep -q "$_XMRIG_SCREEN"; then
22+ # Call function
23+ start_xmrig
24+ fi
25+else
26+ # Call function
27+ start_xmrig
28+
29+ # Unset _XMRIG_SCREEN variable.
30+ # The start script will have to load settings on next start
31+ $_XMRIG_SCREEN=""
32+fi
33+
34+# List screen
35+screen -ls
36+
37+echo "####################################"
38+echo " STARTED - use screen -r to view "
39+echo "####################################"
40+
stop.shnew file+33
@@ -0,0 +1,33 @@
1+#!/bin/bash
2+
3+# When this script is:
4+# * run by crontab, load the settings
5+# * run by install, do not load settings
6+
7+stop_xmrig () {
8+ screen -S $_XMRIG_SCREEN -X kill
9+}
10+
11+echo "#################################"
12+echo " KILLING SCREEN"
13+echo "#################################"
14+
15+if [ -z "$_XMRIG_SCREEN" ]; then
16+ # Load settings when run by crontab
17+ echo "Loading settings"
18+ . settings.sh
19+
20+ # Call function
21+ stop_xmrig
22+else
23+ # Call function
24+ stop_xmrig
25+fi
26+
27+# Check results
28+echo "Screen listing"
29+screen -ls
30+
31+echo "#################################"
32+echo " SCREEN KILLED"
33+echo "#################################"
update.shnew file+21
@@ -0,0 +1,21 @@
1+#!/bin/bash
2+
3+# Set get xmrig repository and version by sourcing our version file
4+. settings.sh
5+
6+# Kill any current xmrig process
7+. stop.sh
8+
9+# Get source and build by sourcing our build file
10+. build.sh
11+
12+# Clean users contab
13+crontab -r $USER
14+
15+# Source our start script to start process again in a screen
16+. start.sh
17+
18+echo "####################################"
19+echo "# ALL DONE - UPDATE COMPLETE #"
20+echo "####################################"
21+