git.iko.soy/xmrig-bash-scripts
on master help sign in
19 files changed+696−291
since splitsnapshots
unifiedsplit
.gitignore+4 CONTRIBUTING.md+85 CONTRIBUTORS README.md+118−1 build.sh+17−46 config.json−105 config.sh+8 crontab-off.sh+18 crontab-on.sh+20 crontab.sh+7−14 depends.sh+17 functions.sh+125 input.sh+61 install.sh+43−8 maintenance.sh+12 settings.sh+100−54 start.sh+52−33 stop.sh+3−14 update.sh+6−16
.gitignore+4
@@ -1,3 +1,7 @@
11xmrig-cpu/
22*.swp
33crontab
4+null
5+config.json
6+myconfig.json
7+mysettings.sh
CONTRIBUTING.mdnew file+85
@@ -0,0 +1,85 @@
1+# Contributing
2+
3+When contributing to this repository, please first discuss the change you wish to make via issue with the owners of this repository before making a change.
4+
5+Please note we have a code of conduct, please follow it in all your interactions with the project.
6+
7+## Pull Request Process
8+
9+1. Ensure any install or build artifacts are not included or are removed.
10+2. Update the README.md with details of changes to the interface.
11+
12+## Code of Conduct
13+
14+### Our Pledge
15+
16+In the interest of fostering an open and welcoming environment, we as
17+contributors and maintainers pledge to making participation in our project and
18+our community a harassment-free experience for everyone, regardless of age, body
19+size, disability, ethnicity, gender identity and expression, level of experience,
20+nationality, personal appearance, race, religion, or sexual identity and
21+orientation.
22+
23+### Our Standards
24+
25+Examples of behavior that contributes to creating a positive environment
26+include:
27+
28+* Using welcoming and inclusive language
29+* Being respectful of differing viewpoints and experiences
30+* Gracefully accepting constructive criticism
31+* Focusing on what is best for the community
32+* Showing empathy towards other community members
33+
34+Examples of unacceptable behavior by participants include:
35+
36+* The use of sexualized language or imagery and unwelcome sexual attention or
37+advances
38+* Trolling, insulting/derogatory comments, and personal or political attacks
39+* Public or private harassment
40+* Publishing others' private information, such as a physical or electronic
41+ address, without explicit permission
42+* Other conduct which could reasonably be considered inappropriate in a
43+ professional setting
44+
45+### Our Responsibilities
46+
47+Project maintainers are responsible for clarifying the standards of acceptable
48+behavior and are expected to take appropriate and fair corrective action in
49+response to any instances of unacceptable behavior.
50+
51+Project maintainers have the right and responsibility to remove, edit, or
52+reject comments, commits, code, wiki edits, issues, and other contributions
53+that are not aligned to this Code of Conduct, or to ban temporarily or
54+permanently any contributor for other behaviors that they deem inappropriate,
55+threatening, offensive, or harmful.
56+
57+### Scope
58+
59+This Code of Conduct applies both within project spaces and in public spaces
60+when an individual is representing the project or its community. Examples of
61+representing a project or community include using an official project e-mail
62+address, posting via an official social media account, or acting as an appointed
63+representative at an online or offline event. Representation of a project may be
64+further defined and clarified by project maintainers.
65+
66+### Enforcement
67+
68+Instances of abusive, harassing, or otherwise unacceptable behavior may be
69+reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
70+complaints will be reviewed and investigated and will result in a response that
71+is deemed necessary and appropriate to the circumstances. The project team is
72+obligated to maintain confidentiality with regard to the reporter of an incident.
73+Further details of specific enforcement policies may be posted separately.
74+
75+Project maintainers who do not follow or enforce the Code of Conduct in good
76+faith may face temporary or permanent repercussions as determined by other
77+members of the project's leadership.
78+
79+### Attribution
80+
81+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
82+available at [http://contributor-covenant.org/version/1/4][version]
83+
84+[homepage]: http://contributor-covenant.org
85+[version]: http://contributor-covenant.org/version/1/4/
CONTRIBUTORSnew file

No changes to the content.

README.md+118−1
@@ -1,2 +1,119 @@
11# xmrig-bash-scripts
2−Simple collection of bash shell scripts I use to manage xmrig cpu
2+A set of convenience scripts, written in bash, to help manage installation, configuration and update of [xmrig cpu](https://github.com/xmrig/xmrig) across multiple hosts.
3+
4+
5+## Download
6+* https://github.com/seanwhe/xmrig-bash-scripts
7+* Git clone with `git clone https://github.com/seanwhe/xmrig-bash-scripts`
8+
9+### Prerequisites
10+
11+There is allot to install so the install script will do most of the heavy lifting.
12+At the start the expectation is that you have:
13+* Computer running Ubuntu 18.04 (LTS)
14+* Bash shell
15+* User account with sudo privileges
16+* Installed git
17+* Optionally installed [xmrig-proxy](https://github.com/xmrig/xmrig-proxy)
18+
19+### Agreeable
20+
21+Some knowledge of:
22+* Linux Command Line Interface
23+* Linux shell `bash`
24+
25+### Installation
26+
27+1. Change to your user home directory.
28+ `cd ~`
29+1. Install git.
30+ `sudo apt install git`
31+1. Clone this project.
32+ `git clone https://github.com/seanwhe/xmrig-bash-scripts`
33+1. Change into the cloned directory.
34+ `cd xmrig-bash-scripts`
35+1. Run the install script
36+ `./install.sh`
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
44+1. After install is complete. Attach to the screen session created during the installation.
45+ `screen -r`
46+
47+### Operation
48+
49+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.
50+
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+
55+This should work out the box, if you follow the installation steps and enter your own values for 'mysettings.sh.
56+
57+Once you have a running xmrig then you can start playing around and tweaking to suite requirements.
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.
61+The scripts are designed to be modular to promote resuse, execute exclusion and standalone execution.
62+
63+* build.sh - clones xmrig to ``~/xmrig-bash-scripts`/xmrig-cpu`, configures, builds and copies xmrig to `/usr/bin/`
64+* config.sh - contains variables that aid in defining the values for the attributes found in config.json.
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.
68+* depends.sh - installs dependancies required by xmrig and these 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'
71+* install.sh - the main entry point when first installing.
72+* maintenance.sh - performs apt update, upgrade, autoremove and autoclean operations.
73+* settings.sh - contains variables used by these scripts.
74+* start.sh - starts xmrig in a screen session.
75+* stop.sh - stops xmrig screen session.
76+
77+### Viewing the log
78+Default of the start script is to create a screen session named 'xmrig-cpu'.
79+This can be changed in the settings script if required.
80+To view the log after installation is finished or after running the start script, used the following command:
81+`screen -r xmrig-cpu`
82+
83+### Updating
84+A simple `git update` in `~/xmrig-bash-scripts` will update these scripts.
85+
86+The install script can be run at any time to update the xmrig source found `~/xmrig-bash-scripts/xmrig-cpu`.
87+The branch checkout is taken from the `_XMRIG_BRANCH` variable in `settings.sh`.
88+
89+A script named update.sh is provided to perform both these steps in a single command.
90+
91+## Reporting issues
92+
93+[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.
94+
95+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.
96+In other words, post issues for:
97+* xmrig, the Monero (XMR) CPU miner, over at [xmrig issues tracker](https://github.com/xmrig/xmrig/issues)
98+* xmrig-bash-scripts, these conveniece scripts, over at [xmrig-bash-scripts](https://github.com/seanwhe/xmrig-bash-scripts/issues)
99+
100+## Versioning
101+
102+We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/seanwhe/xmrig-bash-scripts/tags).
103+
104+## Contributing
105+Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.
106+
107+See also the list of [contributors](https://github.com/seanwhe/xmrig-bash-scripts/CONTRIBUTORS)
108+
109+## Authors
110+
111+* **Sean Wheller** - *Initial work* - [seanwhe](https://github.com/seanwhe)
112+
113+## License
114+
115+This project is licensed under the GNU General Public License v3.0 - see the [LICENSE.md](LICENSE.md) file for details
116+
117+## Acknowledgments
118+
119+* Thanks to [fireice-uk](https://github.com/fireice-uk) for developing and maintaining [xmrig products](https://xmrig.com/).
build.sh+17−46
@@ -1,59 +1,32 @@
11#!/bin/bash
22
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++
3+echo "${_GREEN}BUILD STARTED${_RESET}"
404
415# Clone source
426if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
43− echo "Clone already exists"
447
458 # Change to clone directory
469 cd $_XMRIG_CLONE
4710
48− # Pull changes from source
49− git pull
11+ if git branch | grep -q -m1 "* $_XMRIG_BRANCH"; then
12+ # Pull changes from source
13+ git pull
5014
51− # Call function
52− build_xmrig
15+ # Call function
16+ build_xmrig
5317
18+ else
19+ # Switch to required branch
20+ git checkout $_XMRIG_BRANCH
21+
22+ # Pull changes from source
23+ git pull
24+
25+ # Call function
26+ build_xmrig
27+ fi
5428else
5529 # Clone the source
56− echo "Cloning source to $_WORK_DIR/$_XMRIG_CLONE"
5730 git clone $_XMRIG_REPO $_XMRIG_CLONE
5831
5932 # Change to clone directory
@@ -74,7 +47,5 @@ sudo cp $_XMRIG_BUILD_LOCATION/xmrig $_XMRIG_TARGET_LOCATION
7447
7548cd $_WORK_DIR
7649
77−echo "#################################"
78−echo " BUILD COMPLETE"
79−echo "#################################"
50+echo "${_CYAN}BUILD STOPPED${_RESET}"
8051
config.jsondeleted−105
@@ -1,105 +0,0 @@
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−}
config.shnew file+8
@@ -0,0 +1,8 @@
1+#!/bin/bash
2+
3+echo "${_GREEN}CONFIG STARTED${_RESET}"
4+
5+echo "$_CONFIG_JSON" | tee config.json
6+
7+echo "${_CYAN}CONFIG STOPPED${_RESET}"
8+
crontab-off.shnew file+18
@@ -0,0 +1,18 @@
1+#!/bin/bash
2+
3+echo "${_GREEN}DISABLE CRONTAB STARTED${_RESET}"
4+
5+# Removes a user crontab
6+# Used in conjunction with crontab-on.sh to toggle user crontab between states:
7+# on - start/stop xmrig at specified times
8+# off - do not start/stop xmrig
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+echo "${_CYAN}DISABLE CRONTAB STOPPED${_RESET}"
18+
crontab-on.shnew file+20
@@ -0,0 +1,20 @@
1+#!/bin/bash
2+
3+echo "${_GREEN}ENABLE CRONTAB STARTED${_RESET}"
4+
5+# Defines a user crontab with schedules as defined in settings.sh
6+# Used in conjunction with crontab-off.sh to toggle user crontab between states:
7+# on - start/stop xmrig at specified times
8+# off - do not start/stop xmrig
9+
10+# Get settings
11+. settings.sh
12+. functions.sh
13+sleep 5
14+
15+# Setup crontab for user
16+. crontab.sh
17+sleep 5
18+
19+echo "${_CYAN}ENABLE CRONTAB STOPPED${_RESET}"
20+
crontab.sh+7−14
@@ -1,29 +1,22 @@
11#!/bin/bash
22
3−# Set values in settings script
43
5−echo "#################################"
6−echo " UPDATING CRONTAB"
7−echo "#################################"
4+echo "${_GREEN}CRONTAB STARTED${_RESET}"
85
6+# Set values in settings script
97
108# Remove existing crontab
11−echo "Backup existing crontab"
129crontab -l > crontab
1310
14−echo "Removing exiting crontab"
1511crontab -r
1612
1713# 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 -
2014
21−crontab -l | { cat; echo "#Stop at $_USER_TIMESTOP on days $_USER_CRONDAYS
22−0 $_USER_CRONSTOP * * $_USER_CRONDAYS $_WORK_DIR/stop.sh"; } | crontab -
15+crontab -l | { cat; echo "#Start at $_USER_CRONSTART on days $_USER_CRONDAYS
16+0 $_USER_CRONSTART * * $_USER_CRONDAYS screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION"; } | crontab -
2317
24−crontab -l
18+crontab -l | { cat; echo "#Stop at $_USER_TIMESTOP on days $_USER_CRONDAYS
19+0 $_USER_CRONSTOP * * $_USER_CRONDAYS screen -S $_XMRIG_SCREEN -X kill"; } | crontab -
2520
26−echo "#################################"
27−echo " CRONTAB UPDATED"
28−echo "#################################"
21+echo "${_CYAN}CRONTAB STOPPED${_RESET}"
2922
depends.shnew file+17
@@ -0,0 +1,17 @@
1+#!/bin/bash
2+
3+# Install the software requirements
4+
5+echo "${_GREEN}INSTALL DEPENDS STARTED${_RESET}"
6+
7+if [ "$_APT_DEPENDS" -eq "1" ]; then
8+
9+ # Install xmrig depends
10+ sudo apt install -y software-properties-common git build-essential cmake libuv1-dev libssl-dev libmicrohttpd-dev libhwloc-dev gcc g++
11+
12+ # Install xmrig-bash-scripts depends
13+ sudo apt install -y jo cpuid screen
14+
15+fi
16+
17+echo "${_CYAN}INSTALL DEPENDS STOPPED${_RESET}"
functions.shnew file+125
@@ -0,0 +1,125 @@
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 () {
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+
45+function build_xmrig () {
46+ if [ -d $_XMRIG_BUILD_LOCATION ]; then
47+ # Remove existing build directory
48+ rm -rf $_XMRIG_BUILD_LOCATION
49+
50+ # Make new build directory
51+ mkdir $_XMRIG_BUILD_LOCATION
52+ else
53+ # Make new build directory
54+ mkdir $_XMRIG_BUILD_LOCATION
55+ fi
56+
57+ # Change to build directory
58+ cd $_XMRIG_BUILD_LOCATION
59+
60+ # Configure cmake scafolding
61+ cmake ..
62+
63+ # Compile the software
64+ make
65+}
66+
67+
68+function start_xmrig () {
69+ screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
70+}
71+
72+
73+function stop_xmrig () {
74+ screen -S $_XMRIG_SCREEN -X kill
75+}
76+
77+function check_cpu () {
78+ # Check if CPU supports AES-NI
79+ cpuid | grep -i aes > hw-aes.txt
80+ if grep -q true "hw-aes.txt"; then
81+ _AES_NI=true
82+ else
83+ _AES_NI=false
84+ fi
85+ rm hw-aes.txt
86+
87+ # Get number of available CPU Cores
88+ _ENV_CORE=$(nproc --all)
89+
90+ # Get CPU L3 cache value
91+ _ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
92+}
93+
94+function calc_threads () {
95+ # Each thread needs 2048 byte (2 Megabyte)
96+ # Calculate number of threads supported with L3 cache size
97+
98+ _ENV_THREAD_QTY=$(( ($_ENV_CORE_L3/2048)/1000 ))
99+
100+ # Affine number of threads for _CPU_CN
101+ _COUNTER="$(( $_ENV_THREAD_QTY-1 ))"
102+
103+ _ENV_CPU_THREAD_AFFINITY="$(seq -s " " 0 $_COUNTER)"
104+
105+}
106+
107+function calc_hugepages () {
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
121+ fi
122+
123+}
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+43−8
@@ -1,19 +1,56 @@
11#!/bin/bash
22
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
24+if sudo grep -q $USER /etc/sudoers.d/README; then
25+ echo -e "User $USER found in /etc/sudoers.d/README. All good!!\n"
26+else
27+ echo -e "$USER does not have passwdles sudo. Fixing that!!\n"
28+ echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/README
29+fi
30+
31+# Load functions
32+. functions.sh
33+
334# Get settings
435. settings.sh
5−sleep 5
36+
37+# Update system
38+. maintenance.sh
39+
40+# Install dependencies
41+. depends.sh
42+
43+# User input
44+. input.sh
645
746# Stop running instance
847. stop.sh
948
1049# Get source and build by sourcing our build file
1150. build.sh
12−sleep 5
1351
14−# Setup crontab for user
15−. crontab.sh
16−sleep 5
52+# Create a config.json
53+. config.sh
1754
1855# Unset REPO variable so start script will execute program
1956SCREEN=""
@@ -22,6 +59,4 @@ SCREEN=""
2259. start.sh
2360
2461
25−echo "####################################"
26−echo "# ALL DONE - INSTALLATION COMPLETE #"
27−echo "####################################"
62+echo -e "${_CYAN}INSTALLATION COMPLETED${_RESET}"
maintenance.shnew file+12
@@ -0,0 +1,12 @@
1+#!/bin/bash
2+
3+echo "${_GREEN}MAINTENANCE STARTED${_RESET}"
4+
5+if [ "$_APT_MAINETANCE" -eq "1" ]; then
6+
7+ sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean
8+
9+fi
10+
11+echo "${_CYAN}MAINTENANCE STOPPED${_RESET}"
12+
settings.sh+100−54
@@ -1,93 +1,139 @@
11#!/bin/bash
22
3−echo "#################################"
4−echo " LOADING SETTINGS "
5−echo "#################################"
3+echo -e "${_GREEN}LOADING DEFAULT SETTINGS${_RESET}"
4+
5+_EMAIL="spam@iko.soy"
6+
7+_RECEIVE_WALLET="44FADBDhNRvjJszF5mLS4VCwZ71mY7ftfUErEisPoT724hb5eYuvuFqWthniY8dGPBTcWuBoeLrLJVkxLHCb1Lsd4DdbZzZ"
8+
9+_POOL_SERVER_URL="xmrpool.eu"
10+_POOL_SERVER_PORT="5555"
11+
12+# Call function
13+show_settings
14+
15+#######################################################################
16+# DO NOT CHANGE AFTER THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING #
17+#######################################################################
18+
19+_API_ID='null'
20+_API_WORKER_ID="$HOSTNAME"
21+
22+_AUTOSAVE="true"
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"
683
784# Set working directory
885_WORK_DIR="$(pwd)"
986cd $_WORK_DIR
10−echo -e "Working directory: $_WORK_DIR\n"
1187
1288# Set repository from which to get the source
1389_XMRIG_REPO="https://github.com/xmrig/xmrig.git"
14−echo -e "Git source repo: $_XMRIG_REPO\n"
1590
1691# Set name of folder to create when cloning from REPO
1792_XMRIG_CLONE="xmrig-cpu"
18−echo -e "Source folder name: $_XMRIG_CLONE\n"
1993
2094# Set clone directory path
2195_XMRIG_CLONE_LOCATION="$_WORK_DIR/$_XMRIG_CLONE"
22−echo -e "Source folder location: $_XMRIG_CLONE_LOCATION\n"
2396
2497# Set branch from which to build
25−_XMRIG_BRANCH="beta"
26−echo -e "Build branch: $_XMRIG_BRANCH\n"
98+_XMRIG_BRANCH="master"
2799
28100# Set build directory
29101_XMRIG_BUILD="build"
30−echo -e "Build directory: $_XMRIG_BUILD\n"
31102
32103# Set build directory location
33104_XMRIG_BUILD_LOCATION="$_XMRIG_CLONE_LOCATION/$_XMRIG_BUILD"
34−echo -e "Build directory location: $_XMRIG_BUILD_LOCATION\n"
35105
36106# Set where to install binary
37107_XMRIG_TARGET_LOCATION="/usr/bin/"
38−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"
39114
40115# Set the config file name
41116_XMRIG_CONFIG="config.json"
42−echo -e "Config file: $_XMRIG_CONFIG\n"
43117
44118# Set config location
45119_XMRIG_CONFIG_LOCATION="$_WORK_DIR/$_XMRIG_CONFIG"
46−echo -e "Config file location: $_XMRIG_CONFIG_LOCATION\n"
47120
48121# Set values for crontab
49−_USER_CRONSTART="18"
50−_USER_CRONSTOP="6"
122+_USER_CRONSTART="17"
123+_USER_CRONSTOP="8"
51124_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"
55125
56126# Set the name of the screen created by start script
57127_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 "#################################"
128+
129+# Run apt maintenance
130+# 1 = yes 0 = no
131+_APT_MAINETANCE="1"
132+
133+# Run install of depends
134+# 1 = yes 0 = no
135+_APT_DEPENDS="1"
136+
137+
138+echo -e "${_CYAN}DEFAULT SETTINGS LOADED${_RESET}"
93139
start.sh+52−33
@@ -1,40 +1,59 @@
11#!/bin/bash
22
3+echo "${_GREEN}MINING STARTED${_RESET}"
4+
35# When this script is:
46# * run by crontab, load the settings
57# * run by install, do not load settings
68
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 "####################################"
9+# Reload settings and functions for when running standalone
10+. functions.sh
11+. settings.sh
12+
13+# if ! screen -list | grep -q "$_XMRIG_SCREEN"; then
14+
15+ # Call functions
16+ show_settings
17+ show_mysettings
18+ # start_xmrig
19+
20+ # List screen
21+ # screen -ls
22+# else
23+
24+ # List screen
25+ # screen -ls
26+
27+# fi
28+echo "[Unit]" | sudo tee /etc/systemd/system/xmrig.service
29+echo "Description=XMRIG service" | sudo tee -a /etc/systemd/system/xmrig.service
30+echo "After=network.target" | sudo tee -a /etc/systemd/system/xmrig.service
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}"
4059
stop.sh+3−14
@@ -4,18 +4,12 @@
44# * run by crontab, load the settings
55# * run by install, do not load settings
66
7−stop_xmrig () {
8− screen -S $_XMRIG_SCREEN -X kill
9−}
10−
11−echo "#################################"
12−echo " KILLING SCREEN"
13−echo "#################################"
7+echo "${_GREEN}END MINING STARTED${_RESET}"
148
159if [ -z "$_XMRIG_SCREEN" ]; then
1610 # Load settings when run by crontab
17− echo "Loading settings"
1811 . settings.sh
12+ . functions.sh
1913
2014 # Call function
2115 stop_xmrig
@@ -24,10 +18,5 @@ else
2418 stop_xmrig
2519fi
2620
27−# Check results
28−echo "Screen listing"
29−screen -ls
21+echo "${_CYAN}END MINING STOPPED${_RESET}"
3022
31−echo "#################################"
32−echo " SCREEN KILLED"
33−echo "#################################"
update.sh+6−16
@@ -1,21 +1,11 @@
11#!/bin/bash
22
3−# Set get xmrig repository and version by sourcing our version file
4−. settings.sh
3+echo "${_GREEN}UPDATE STARTED${_RESET}"
54
6−# Kill any current xmrig process
7−. stop.sh
5+git pull
86
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 "####################################"
7+# install
8+. install.sh
9+sleep 5
2110
11+echo "${_CYAN}UPDATE COMPLETE${_RESET}"