git.iko.soy/xmrig-bash-scripts
on master help sign in
add mysettings
commit9a6ad6d757de974f1f81b6edb28c7b6bc23157e6 authorSean Wheller <sean@prepaidmeters.com> dateSun 11 Aug 2019, 10:27 (7 years ago) parente75e65f
5 files changed+113−14
functions.sh+29−6 input.sh+60 install.sh+5−4 settings.sh+15−1 start.sh+4−3
functions.sh+29−6
@@ -1,6 +1,29 @@
11#!/bin/bash
22
3−build_xmrig () {
3+function prompt_confirm() {
4+ while true; do
5+ read -r -n 1 -p "${1:-Continue?} [y/n]: " REPLY
6+ case $REPLY in
7+ [yY]) echo ; return 0 ;;
8+ [nN]) echo ; return 1 ;;
9+ *) printf " \033[31m %s \n\033[0m" "invalid input [y/n]"
10+ esac
11+ done
12+}
13+
14+function show_mysettings () {
15+ if [ -f $_WORK_DIR/$_MYSETTINGS_FILE ]; then
16+ . $_MYSETTINGS_FILE
17+ echo "${_GREEN}Settings from loaded from mysettings.sh.${_RESET}"
18+ echo "${_GREEN}Pool URL:${_RESET}: $_POOL_SERVER_URL"
19+ echo "${_GREEN}Pool Port:${_RESET}: $_POOL_SERVER_PORT"
20+ echo "${_GREEN}Recieve Wallet:${_RESET}: $_RECEIVE_WALLET"
21+ echo "${_GREEN}Email Address:${_RESET}: $_EMAIL"
22+ echo "${_GREEN}Worker Identity:${_RESET}: $_API_WORKER_ID"
23+ fi
24+}
25+
26+function build_xmrig () {
427 if [ -d $_XMRIG_BUILD_LOCATION ]; then
528 # Remove existing build directory
629 rm -rf $_XMRIG_BUILD_LOCATION
@@ -23,16 +46,16 @@ build_xmrig () {
2346}
2447
2548
26−start_xmrig () {
49+function start_xmrig () {
2750 screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
2851}
2952
3053
31−stop_xmrig () {
54+function stop_xmrig () {
3255 screen -S $_XMRIG_SCREEN -X kill
3356}
3457
35−check_cpu () {
58+function check_cpu () {
3659 # Check if CPU supports AES-NI
3760 cpuid | grep -i aes > hw-aes.txt
3861 if grep -q true "hw-aes.txt"; then
@@ -49,7 +72,7 @@ check_cpu () {
4972 _ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
5073}
5174
52−calc_threads () {
75+function calc_threads () {
5376 # Each thread needs 2048 byte (2 Megabyte)
5477 # Calculate number of threads supported with L3 cache size
5578
@@ -62,7 +85,7 @@ calc_threads () {
6285
6386}
6487
65−calc_hugepages () {
88+function calc_hugepages () {
6689 # Setting according to cpu cores but xmrig will not use all
6790 # change to make value use _ENV_CORE_THREADS
6891 # Check that hugepages set in /etc/sysctl.conf
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+5−4
@@ -8,9 +8,6 @@ else
88 set -x
99fi
1010
11−_GREEN=`tput setaf 2`
12−_RESET=`tput sgr0`
13−
1411# Set that user passwdless sudo
1512if sudo grep -q $USER /etc/sudoers.d/README; then
1613 echo -e "User $USER found in /etc/sudoers.d/README. All good!!\n"
@@ -24,7 +21,11 @@ fi
2421
2522# Get settings
2623. settings.sh
27−sleep 5
24+sleep 5
25+
26+# User input
27+. input.sh
28+sleep 5
2829
2930# Stop running instance
3031. stop.sh
settings.sh+15−1
@@ -4,7 +4,7 @@ _EMAIL="miners@prepaidmeters.com"
44
55_RECEIVE_WALLET="854sqm2Cm4TB2XgPHWqSPSbnFAe3SMzdEDzZHpukQ8NHBPFropbnkFmEKiZPgwjMFC9PTjaFscR2UU6ZwFCqJzGMUiZVbTM"
66
7−_POOL_SERVER_URL="192.168.4.5"
7+_POOL_SERVER_URL="pool.supportxmr.com"
88_POOL_SERVER_PORT="3333"
99
1010#######################################################################
@@ -98,6 +98,12 @@ _XMRIG_BUILD_LOCATION="$_XMRIG_CLONE_LOCATION/$_XMRIG_BUILD"
9898# Set where to install binary
9999_XMRIG_TARGET_LOCATION="/usr/bin/"
100100
101+# Set mysettings file
102+_MYSETTINGS_FILE="mysettings.sh"
103+
104+# Set mysettings file location
105+_MYSETTINGS_FILE_LOCATION="$_WORK_DIR/$_MYSETTINGS_FILE"
106+
101107# Set the config file name
102108_XMRIG_CONFIG="config.json"
103109
@@ -120,5 +126,13 @@ _APT_MAINETANCE="1"
120126# 1 = yes 0 = no
121127_APT_DEPENDS="1"
122128
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+
123137echo -e "${_GREEN}SETTINGS LOADED${_RESET}"
124138
start.sh+4−3
@@ -5,12 +5,13 @@
55# * run by install, do not load settings
66
77# Reload settings and functions for when running standalone
8−. settings.sh
98. functions.sh
9+. settings.sh
1010
1111if ! screen -list | grep -q "$_XMRIG_SCREEN"; then
12−
13− # Call function
12+
13+ # Call functions
14+ show_mysettings
1415 start_xmrig
1516
1617 # List screen