Merge branch 'release/v1.0.6'

This commit is contained in:
Sean Wheller 2019-08-11 10:28:47 +02:00
commit fb5f3cc6ac
16 changed files with 286 additions and 242 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@ xmrig-cpu/
*.swp
crontab
config.json
myconfig.json
mysettings.sh

View File

@ -19,11 +19,11 @@ At the start the expectation is that you have:
Some knowledge of:
* Linux Command Line Interface
* Unix shell `bash`
* Linux shell `bash`
There is more to install but the install script will install the rest.
### Installion
### Installation
1. Change to your user home directory.
`cd ~`
@ -43,34 +43,40 @@ There is more to install but the install script will install the rest.
6. Run the install script
`./install.sh`
7. Attach to the screen session created during the installation.
7. After install is complete. Attach to the screen session created during the installation.
`screen -r`
### Operation
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.
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.
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.
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.
This should work out the box, if you edit only the top section of `settings.sh`.
This should work out the box, if you edit only the top section of `settings.sh` and followed the steps here.
Once you have a running xmrig then you can start playing around and tweaking to suite requirements.
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.
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.
* build.sh - clones xmrig to ``~/xmrig-bash-scripts`/xmrig-cpu`, configures, builds and copies xmrig to `/usr/bin/`
* config.sh - contains variables that aid in defining the values for the attributes found in config.json.
* crontab.sh - installs a cron to start and a cron to stop at specific times (Can be commented out of install if desired).
* crontab-off - removed the users crontab created during install.
* crontab-on.sh - redefines the users crontab as created during install.
* depends.sh - installs dependancies required by xmrig and these scripts.
* functions.sh - a collection of functions used in various of the scripts.
* install.sh - the main entry point when first installing.
* maintenance.sh - performs apt update and upgrade.
* maintenance.sh - performs apt update, upgrade, autoremove and autoclean operations.
* settings.sh - contains variables used by these scripts.
* start.sh - starts xmrig in a screen session.
* stop.sh - stops xmrig screen session.
### Viewing the log
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:
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:
`screen -r xmrig-cpu`
### Updating
@ -79,11 +85,14 @@ A simple `git update` in `~/xmrig-bash-scripts` will update these scripts.
The install script can be run at any time to update the xmrig source found `~/xmrig-bash-scripts/xmrig-cpu`.
The branch checkout is taken from the `_XMRIG_BRANCH` variable in `settings.sh`.
A script named update.sh is provided to perform both these steps in a single command.
## Reporting issues
[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.
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:
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:
* xmrig, the Monero (XMR) CPU miner, over at [xmrig issues tracker](https://github.com/xmrig/xmrig/issues)
* xmrig-bash-scripts, these conveniece scripts, over at [xmrig-bash-scripts](https://github.com/seanwhe/xmrig-bash-scripts/issues)

View File

@ -1,12 +1,7 @@
#!/bin/bash
echo "#################################"
echo " BUILD STARTING"
echo "#################################"
# Clone source
if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
echo "Clone already exists"
# Change to clone directory
cd $_XMRIG_CLONE
@ -20,7 +15,6 @@ if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
else
# Switch to required branch
echo "Require: $_XMRIG_BRANCH Switching !!!"
git checkout $_XMRIG_BRANCH
# Pull changes from source
@ -31,7 +25,6 @@ if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
fi
else
# Clone the source
echo "Cloning source to $_WORK_DIR/$_XMRIG_CLONE"
git clone $_XMRIG_REPO $_XMRIG_CLONE
# Change to clone directory
@ -52,7 +45,5 @@ sudo cp $_XMRIG_BUILD_LOCATION/xmrig $_XMRIG_TARGET_LOCATION
cd $_WORK_DIR
echo "#################################"
echo " BUILD COMPLETE"
echo "#################################"
echo "${_GREEN}BUILD COMPLETE${_RESET}"

View File

@ -1,62 +1,6 @@
#!/bin/bash
_API_ID="null"
_API_WORKER_ID="$HOSTNAME"
_AUTOSAVE="true"
_BACKGROUND="false"
_COLORS="true"
_CPU_ENABLED="true"
_CPU_HUGE_PAGES="true"
_CPU_HW_AES="$_AES_NI"
_CPU_PRIORITY="null"
_CPU_ASM="true"
_CPU_CN="$_ENV_CPU_THREAD_AFFINITY"
_CPU_CN_0="false"
_CPU_CN_LITE_0="false"
_DONATE_LEVEL="5"
_DONATE_OVER_PROXY="1"
_HTTP_ENABLED="true"
_HTTP_HOST=$(hostname --all-ip-addresses | awk '{print $1}')
_HTTP_PORT="8080"
_HTTP_ACCESS_TOKEN="null"
_HTTP_RESTRICTED="false"
_LOG_FILE="null"
_POOLS_ALGO="cn/r"
_POOLS_URL="$_POOL_SERVER_URL:$_POOL_SERVER_PORT"
_POOLS_USER="$_RECEIVE_WALLET"
_POOLS_PASS="$HOSTNAME:$_EMAIL"
_POOLS_RIG_ID="$HOSTNAME"
_POOLS_NICEHASH="true"
_POOLS_KEEPALIVE="true"
_POOLS_ENABLED="true"
_POOLS_TLS="null"
_POOLS_TLS_FINDERPRINT="null"
_POOLS_DAEMON="false"
_PRINT_TIME="30"
_RETRIES="5"
_RETRIES_PAUSE="5"
_SYSLOG="false"
_USER_AGENT="null"
_WATCH="true"
_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)
echo "$_CONFIG_JSON" | tee config.json
echo "${_GREEN}CONFIG CREATED${_RESET}"

View File

@ -1,9 +1,9 @@
#!/bin/bash
echo "#################################"
echo "# DISABLING CRONTAB #"
echo "#################################"
# Removes a user crontab
# Used in conjunction with crontab-on.sh to toggle user crontab between states:
# on - start/stop xmrig at specified times
# off - do not start/stop xmrig
# Remove existing crontab
echo "Backup existing crontab"
@ -12,7 +12,5 @@ crontab -l > crontab
echo "Removing exiting crontab"
crontab -r
echo "#################################"
echo "# CRONTAB DISABLED #"
echo "#################################"
echo "${_GREEN}CRONTAB DISABLED${_RESET}"

View File

@ -1,8 +1,9 @@
#!/bin/bash
echo "####################################"
echo "# ENABLING CRONTAB #"
echo "####################################"
# Defines a user crontab with schedules as defined in settings.sh
# Used in conjunction with crontab-off.sh to toggle user crontab between states:
# on - start/stop xmrig at specified times
# off - do not start/stop xmrig
# Get settings
. settings.sh
@ -13,7 +14,5 @@ sleep 5
. crontab.sh
sleep 5
echo "####################################"
echo "# CRONTAB ENABLED #"
echo "####################################"
echo "${_GREEN}CRONTAB ENABLED${_RESET}"

View File

@ -2,20 +2,12 @@
# Set values in settings script
echo "#################################"
echo " UPDATING CRONTAB"
echo "#################################"
# Remove existing crontab
echo "Backup existing crontab"
crontab -l > crontab
echo "Removing exiting crontab"
crontab -r
# Setup users contab
echo "Creating new crontab"
crontab -l | { cat; echo "#Start at $_USER_TIMESTART on days $_USER_CRONDAYS
0 $_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
crontab -l | { cat; echo "#Stop at $_USER_TIMESTOP on days $_USER_CRONDAYS
0 $_USER_CRONSTOP * * $_USER_CRONDAYS screen -S $_XMRIG_SCREEN -X kill"; } | crontab -
echo "#################################"
echo " CRONTAB UPDATED"
echo "#################################"
echo "${_GREEN}CRONTAB CREATED${_RESET}"

View File

@ -1,7 +1,4 @@
#!/bin/bash
echo "#################################"
echo " INSTALLING DEPENDENCIES "
echo "#################################"
# Install the software requirements
@ -12,12 +9,7 @@ if [ $_APT_DEPENDS = 1 ]; then
# Install xmrig-bash-scripts depends
sudo apt install -y jo cpuid screen
else
echo "Depend install is set to NO ($_APT_DEPENDS) Skipping"
fi
echo "#################################"
echo " DEPENDENCIES INSTALLED "
echo "#################################"
echo "${_GREEN}DEPENDENCIES INSTALLED${_RESET}"

View File

@ -1,39 +1,106 @@
#!/usr/bin/env bash
#!/bin/bash
build_xmrig () {
function prompt_confirm() {
while true; do
read -r -n 1 -p "${1:-Continue?} [y/n]: " REPLY
case $REPLY in
[yY]) echo ; return 0 ;;
[nN]) echo ; return 1 ;;
*) printf " \033[31m %s \n\033[0m" "invalid input [y/n]"
esac
done
}
function show_mysettings () {
if [ -f $_WORK_DIR/$_MYSETTINGS_FILE ]; then
. $_MYSETTINGS_FILE
echo "${_GREEN}Settings from loaded from mysettings.sh.${_RESET}"
echo "${_GREEN}Pool URL:${_RESET}: $_POOL_SERVER_URL"
echo "${_GREEN}Pool Port:${_RESET}: $_POOL_SERVER_PORT"
echo "${_GREEN}Recieve Wallet:${_RESET}: $_RECEIVE_WALLET"
echo "${_GREEN}Email Address:${_RESET}: $_EMAIL"
echo "${_GREEN}Worker Identity:${_RESET}: $_API_WORKER_ID"
fi
}
function build_xmrig () {
if [ -d $_XMRIG_BUILD_LOCATION ]; then
# Remove existing build directory
echo "Found old build directory. Removing"
rm -rf $_XMRIG_BUILD_LOCATION
# Make new build directory
echo "Creating a build directory"
mkdir $_XMRIG_BUILD_LOCATION
else
# Make new build directory
echo "Creating a build directory"
mkdir $_XMRIG_BUILD_LOCATION
fi
# Change to build directory
echo "Changing to build directory"
cd $_XMRIG_BUILD_LOCATION
# Configure cmake scafolding
echo "Configuring cmake scafolding"
cmake .. -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7
# Compile the software
echo "Starting build"
make
}
start_xmrig () {
function start_xmrig () {
screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
}
stop_xmrig () {
function stop_xmrig () {
screen -S $_XMRIG_SCREEN -X kill
}
function check_cpu () {
# Check if CPU supports AES-NI
cpuid | grep -i aes > hw-aes.txt
if grep -q true "hw-aes.txt"; then
_AES_NI=true
else
_AES_NI=false
fi
rm hw-aes.txt
# Get number of available CPU Cores
_ENV_CORE=$(nproc --all)
# Get CPU L3 cache value
_ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
}
function calc_threads () {
# Each thread needs 2048 byte (2 Megabyte)
# Calculate number of threads supported with L3 cache size
_ENV_THREAD_QTY=$(( ($_ENV_CORE_L3/2048)/1000 ))
# Affine number of threads for _CPU_CN
_COUNTER="$(( $_ENV_THREAD_QTY-1 ))"
_ENV_CPU_THREAD_AFFINITY="$(seq -s " " 0 $_COUNTER)"
}
function calc_hugepages () {
# Setting according to cpu cores but xmrig will not use all
# change to make value use _ENV_CORE_THREADS
# Check that hugepages set in /etc/sysctl.conf
_ENV_CHECK="nr_hugepages"
if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
sudo sysctl -p
else
# Set value in current env
sudo sysctl -w vm.nr_hugepages="$_ENV_THREAD_QTY"
# Add value to sysctl
sudo sysctl -p
fi
}
echo -e "${_GREEN}FUNCTIONS LOADED${_RESET}"

60
input.sh Executable file
View File

@ -0,0 +1,60 @@
#!/bin/bash
# Ask user questions
# Capture input
. functions.sh
. settings.sh
echo -e "${_YELLOW}Choose to use default settings or enter your own.\n"
echo -e "Use defaults and values will be taken from 'settings.sh'."
echo -e "Enter your own and settings will persist to 'mysettings.sh'.\n"
echo -e "Preference is given to settings in 'mysettings.sh'."
echo -e "When starting from 'start.sh' and 'mysettings.sh' exists it will be loaded instead of 'settings.sh'.${_RESET}\n"
if [ -f $_WORK_DIR/$_MYSETTINGS_FILE ]; then
# Call function
show_mysettings
else
prompt_confirm "Enter your own settings?"
if [ "$?" -eq 0 ]; then
# Create a file
touch $_MYSETTINGS_FILE_LOCATION
chmod +x $_MYSETTINGS_FILE_LOCATION
echo "#!/bin/bash" > $_MYSETTINGS_FILE_LOCATION
# Prompt user input
echo "Current pool URL: $_POOL_SERVER_URL"
read -p "Enter new pool URL: " _POOL_SERVER_URL
echo "Current pool TCP Port: $_POOL_SERVER_PORT"
read -p "Enter new pool TCP Port: " _POOL_SERVER_PORT
echo "Current Receive Wallet address: $_RECEIVE_WALLET"
read -p "Enter new Receive Wallet address: " _RECEIVE_WALLET
echo "Current email address: $_EMAIL"
read -p "Enter new email address: " _EMAIL
echo "Current Miner Identifier: $_API_WORKER_ID"
read -p "Enter Miner Identifier: " _API_WORKER_ID
# Write user input to file
echo "_POOL_SERVER_URL=\"$_POOL_SERVER_URL\"" >> $_MYSETTINGS_FILE_LOCATION
echo "_POOL_SERVER_PORT=\"$_POOL_SERVER_PORT\"" >> $_MYSETTINGS_FILE_LOCATION
echo "_RECEIVE_WALLET=\"$_RECEIVE_WALLET\"" >> $_MYSETTINGS_FILE_LOCATION
echo "_EMAIL=\"$_EMAIL\"" >> $_MYSETTINGS_FILE_LOCATION
echo "_API_WORKER_ID=\"$_API_WORKER_ID\"" >> $_MYSETTINGS_FILE_LOCATION
fi
fi

View File

@ -1,7 +1,14 @@
#!/bin/bash
# Set that user passwdless sudo
_DEBUG=$1
if $_DEBUG; then
set +x
else
set -x
fi
# Set that user passwdless sudo
if sudo grep -q $USER /etc/sudoers.d/README; then
echo -e "User $USER found in /etc/sudoers.d/README. All good!!\n"
else
@ -9,9 +16,15 @@ else
echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/README
fi
# Load functions
. functions.sh
# Get settings
. settings.sh
. functions.sh
sleep 5
# User input
. input.sh
sleep 5
# Stop running instance
@ -44,6 +57,4 @@ SCREEN=""
. start.sh
echo "####################################"
echo "# ALL DONE - INSTALLATION COMPLETE #"
echo "####################################"
echo -e "${_GREEN}INSTALLATION COMPLETE${_RESET}"

View File

@ -1,18 +1,10 @@
#!/bin/bash
echo "####################################"
echo "# STARTING SYSTEM MAINTENANCE #"
echo "####################################"
if [ $_APT_MAINETANCE = 1 ]; then
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean
else
echo "Apt maintenance is set to NO ($_APT_MAINETANCE) Skipping"
fi
echo "####################################"
echo "# SYSTEM MAINTENANCE COMPLETE #"
echo "####################################"
echo "${_GREEN}MAINTENANCE COMPLETE${_RESET}"

View File

@ -1,132 +1,122 @@
#!/usr/bin/env bash
echo "#################################"
echo " LOADING SETTINGS "
echo "#################################"
#!/bin/bash
_EMAIL="miners@prepaidmeters.com"
_RECEIVE_WALLET="854sqm2Cm4TB2XgPHWqSPSbnFAe3SMzdEDzZHpukQ8NHBPFropbnkFmEKiZPgwjMFC9PTjaFscR2UU6ZwFCqJzGMUiZVbTM"
_POOL_SERVER_URL="192.168.4.5"
_POOL_SERVER_URL="pool.supportxmr.com"
_POOL_SERVER_PORT="3333"
#####################################################################
#######################################################################
# DO NOT CHANGE AFTER THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING #
#######################################################################
# DO NOT CHANGE AFTER THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING
_API_ID="null"
_API_WORKER_ID="$HOSTNAME"
#####################################################################
_AUTOSAVE="true"
_BACKGROUND="false"
_COLORS="true"
# call check_cpu
check_cpu
# call calc_threads
calc_threads
_CPU_ENABLED="true"
_CPU_HUGE_PAGES="true"
_CPU_HW_AES="$_AES_NI"
_CPU_PRIORITY="null"
_CPU_ASM="true"
_CPU_CN="$_ENV_CPU_THREAD_AFFINITY"
_CPU_CN_0="false"
_CPU_CN_LITE_0="false"
_DONATE_LEVEL="5"
_DONATE_OVER_PROXY="1"
_HTTP_ENABLED="true"
_HTTP_HOST=$(hostname --all-ip-addresses | awk '{print $1}')
_HTTP_PORT="8080"
_HTTP_ACCESS_TOKEN="null"
_HTTP_RESTRICTED="false"
_LOG_FILE="null"
_POOLS_ALGO="cn/r"
_POOLS_URL="$_POOL_SERVER_URL:$_POOL_SERVER_PORT"
_POOLS_USER="$_RECEIVE_WALLET"
_POOLS_PASS="$HOSTNAME:$_EMAIL"
_POOLS_RIG_ID="$HOSTNAME"
_POOLS_NICEHASH="true"
_POOLS_KEEPALIVE="true"
_POOLS_ENABLED="true"
_POOLS_TLS="null"
_POOLS_TLS_FINDERPRINT="null"
_POOLS_DAEMON="false"
_PRINT_TIME="30"
_RETRIES="5"
_RETRIES_PAUSE="5"
_SYSLOG="false"
_USER_AGENT="null"
_WATCH="true"
_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)
# Set working directory
_WORK_DIR="$(pwd)"
cd $_WORK_DIR
echo -e "Working directory: $_WORK_DIR\n"
# Set repository from which to get the source
_XMRIG_REPO="https://github.com/xmrig/xmrig.git"
echo -e "Git source repo: $_XMRIG_REPO\n"
# Set name of folder to create when cloning from REPO
_XMRIG_CLONE="xmrig-cpu"
echo -e "Source folder name: $_XMRIG_CLONE\n"
# Set clone directory path
_XMRIG_CLONE_LOCATION="$_WORK_DIR/$_XMRIG_CLONE"
echo -e "Source folder location: $_XMRIG_CLONE_LOCATION\n"
# Set branch from which to build
_XMRIG_BRANCH="beta"
echo -e "Build branch: $_XMRIG_BRANCH\n"
# Set build directory
_XMRIG_BUILD="build"
echo -e "Build directory: $_XMRIG_BUILD\n"
# Set build directory location
_XMRIG_BUILD_LOCATION="$_XMRIG_CLONE_LOCATION/$_XMRIG_BUILD"
echo -e "Build directory location: $_XMRIG_BUILD_LOCATION\n"
# Set where to install binary
_XMRIG_TARGET_LOCATION="/usr/bin/"
echo -e "Install path: $_XMRIG_TARGET_LOCATION\n"
# Set mysettings file
_MYSETTINGS_FILE="mysettings.sh"
# Set mysettings file location
_MYSETTINGS_FILE_LOCATION="$_WORK_DIR/$_MYSETTINGS_FILE"
# Set the config file name
_XMRIG_CONFIG="config.json"
echo -e "Config file: $_XMRIG_CONFIG\n"
# Set config location
_XMRIG_CONFIG_LOCATION="$_WORK_DIR/$_XMRIG_CONFIG"
echo -e "Config file location: $_XMRIG_CONFIG_LOCATION\n"
# Set values for crontab
_USER_CRONSTART="18"
_USER_CRONSTOP="6"
_USER_CRONDAYS="1-5"
echo -e "Cron job start: $_USER_CRONSTART\n"
echo -e "Cron job stop: $_USER_CRONSTOP\n"
echo -e "Cron on days: $_USER_CRONDAYS\n"
# Set the name of the screen created by start script
_XMRIG_SCREEN="xmrig-cpu"
echo -e "Screen session name: $_XMRIG_SCREEN\n"
# Check if CPU supports AES-NI
cpuid | grep -i aes > hw-aes.txt
if grep -q true "hw-aes.txt"; then
_AES_NI=true
else
_AES_NI=false
fi
rm hw-aes.txt
# Get number of available CPU Cores
_ENV_CORE=$(nproc --all)
echo -e "CPU Cores: $_ENV_CORE\n"
# Get CPU L3 cache value
_ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
echo -e "L3 Cache in byte: $_ENV_CORE_L3\n"
# Determine number of threads possible
_ENV_CORE_L3_MB="$(($_ENV_CORE_L3 / 1000000))"
echo -e "L3 cache in Megabyte: $_ENV_CORE_L3_MB\n"
# Determine number of threads possible
_ENV_CORE_THREADS="$(($_ENV_CORE_L3_MB / 2))"
echo "Each thread requires 2 MB of cache"
echo -e "Number of threads possible is: $_ENV_CORE_THREADS\n"
# Affine number of threads for _CPU_CN
_COUNTER="$(($_ENV_CORE_THREADS - 1))"
_ENV_CPU_THREADS=()
for i in `seq 0 $_COUNTER`; do
_ENV_CPU_THREADS+=("$i")
done
echo "Thread CPU Affinity: ${_ENV_CPU_THREADS[@]}"
_ENV_CPU_THREAD_AFFINITY="${_ENV_CPU_THREADS[@]}"
# Setting according to cpu cores but xmrig will not use all
# change to make value use _ENV_CORE_THREADS
# Check that hugepages set in /etc/sysctl.conf
_ENV_CHECK="nr_hugepages"
if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
echo "Found nr_hugepages in /etc/sysctl.conf. All good!!"
echo -e "Refreshing sysctl configuration just to be sure.\n"
sudo sysctl -p
else
# Set value in current env
echo -e "Did not find nr_hugepages in /etc/sysctl.conf. Fixing that!!\n"
sudo sysctl -w vm.nr_hugepages="$_ENV_CORE"
sudo sysctl -p
# Add value to sysctl
echo "vm.nr_hugepages=$_ENV_CORE" | sudo tee -a /etc/sysctl.conf
fi
# Run apt maintenance
# 1 = yes 0 = no
@ -136,7 +126,13 @@ _APT_MAINETANCE="1"
# 1 = yes 0 = no
_APT_DEPENDS="1"
echo "#################################"
echo " SETTINGS LOADED"
echo "#################################"
# Colors
_GREEN=`tput setaf 2`
_YELLOW=`tput setaf 3`
_BLUE=`tput setaf 4`
_MAGENTA=`tput setaf 5`
_CYAN=`tput setaf 6`
_RESET=`tput sgr0`
echo -e "${_GREEN}SETTINGS LOADED${_RESET}"

View File

@ -1,32 +1,27 @@
#!/usr/bin/env bash
#!/bin/bash
# When this script is:
# * run by crontab, load the settings
# * run by install, do not load settings
echo "####################################"
echo " STARTING "
echo "####################################"
. settings.sh
# Reload settings and functions for when running standalone
. functions.sh
. settings.sh
if ! screen -list | grep -q "$_XMRIG_SCREEN"; then
# Call function
echo "No screen sessionfound. Starting new screen session."
# Call functions
show_mysettings
start_xmrig
# List screen
screen -ls
else
# Call function
echo "Found existing screen session. Leaving."
# List screen
screen -ls
fi
echo "####################################"
echo " STARTED - use screen -r to view "
echo "####################################"
echo "${_GREEN}MINING STARTED${_RESET}"

12
stop.sh
View File

@ -4,13 +4,8 @@
# * run by crontab, load the settings
# * run by install, do not load settings
echo "#################################"
echo " KILLING SCREEN"
echo "#################################"
if [ -z "$_XMRIG_SCREEN" ]; then
# Load settings when run by crontab
echo "Loading settings and functions"
. settings.sh
. functions.sh
@ -21,10 +16,5 @@ else
stop_xmrig
fi
# Check results
echo "Screen listing"
screen -ls
echo "${_GREEN}MINING STOPPED${_RESET}"
echo "#################################"
echo " SCREEN KILLED"
echo "#################################"

9
update.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
git pull
# install
. install.sh
sleep 5
echo "${_GREEN}UPDATE COMPLETE${_RESET}"