Merge branch 'master' into develop

This commit is contained in:
Sean Wheller 2019-07-27 02:20:57 +02:00
commit 3cfa2d1cc7
9 changed files with 431 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
xmrig-cpu/
*.swp
crontab

80
build.sh Executable file
View File

@ -0,0 +1,80 @@
#!/bin/bash
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
}
echo "#################################"
echo " BUILD STARTING"
echo "#################################"
# Update system
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean
# Install the software requirements
sudo apt install -y screen software-properties-common git build-essential cmake libuv1-dev libssl-dev libmicrohttpd-dev gcc g++
# Clone source
if [ -d "$_XMRIG_CLONE_LOCATION" ]; then
echo "Clone already exists"
# Change to clone directory
cd $_XMRIG_CLONE
# Pull changes from source
git pull
# Call function
build_xmrig
else
# Clone the source
echo "Cloning source to $_WORK_DIR/$_XMRIG_CLONE"
git clone $_XMRIG_REPO $_XMRIG_CLONE
# Change to clone directory
cd $_XMRIG_CLONE
# Fetch list of branches in origin
git branch -a
# Checkout required branch
git checkout $_XMRIG_BRANCH
# Call function
build_xmrig
fi
# Copy binary to directory in env path
sudo cp $_XMRIG_BUILD_LOCATION/xmrig $_XMRIG_TARGET_LOCATION
cd $_WORK_DIR
echo "#################################"
echo " BUILD COMPLETE"
echo "#################################"

105
config.json Executable file
View File

@ -0,0 +1,105 @@
{
"api": {
"id": null,
"worker-id": "sean-wks"
},
"autosave": true,
"background": false,
"colors": true,
"cpu": {
"enabled": true,
"huge-pages": true,
"hw-aes": null,
"priority": null,
"asm": true,
"cn": [
-1,
-1,
-1,
-1
],
"cn-heavy": [
-1,
-1
],
"cn-lite": [
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
],
"cn-pico": [
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
],
"cn/gpu": [
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
],
"rx": [
-1,
-1,
-1,
-1
],
"rx/wow": [
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
],
"cn/0": false,
"cn-lite/0": false
},
"donate-level": 5,
"donate-over-proxy": 1,
"http": {
"enabled": false,
"host": "127.0.0.1",
"port": 0,
"access-token": null,
"restricted": true
},
"log-file": null,
"pools": [
{
"algo": null,
"url": "192.168.4.5:3333",
"user": "854sqm2Cm4TB2XgPHWqSPSbnFAe3SMzdEDzZHpukQ8NHBPFropbnkFmEKiZPgwjMFC9PTjaFscR2UU6ZwFCqJzGMUiZVbTM",
"pass": "sean-wks:miners@prepaidmeters.com",
"rig-id": "sean-wks",
"nicehash": true,
"keepalive": true,
"enabled": true,
"tls": false,
"tls-fingerprint": null,
"daemon": false
}
],
"print-time": 30,
"retries": 5,
"retry-pause": 5,
"syslog": false,
"user-agent": null,
"watch": true
}

29
crontab.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
# 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
crontab -l | { cat; echo "#Start at $_USER_TIMESTART on days $_USER_CRONDAYS
0 $_USER_CRONSTART * * $_USER_CRONDAYS $_WORK_DIR/start.sh"; } | crontab -
crontab -l | { cat; echo "#Stop at $_USER_TIMESTOP on days $_USER_CRONDAYS
0 $_USER_CRONSTOP * * $_USER_CRONDAYS $_WORK_DIR/stop.sh"; } | crontab -
crontab -l
echo "#################################"
echo " CRONTAB UPDATED"
echo "#################################"

27
install.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
# Get settings
. settings.sh
sleep 5
# Stop running instance
. stop.sh
# Get source and build by sourcing our build file
. build.sh
sleep 5
# Setup crontab for user
. crontab.sh
sleep 5
# Unset REPO variable so start script will execute program
SCREEN=""
# Start mining
. start.sh
echo "####################################"
echo "# ALL DONE - INSTALLATION COMPLETE #"
echo "####################################"

93
settings.sh Executable file
View File

@ -0,0 +1,93 @@
#!/bin/bash
echo "#################################"
echo " LOADING SETTINGS "
echo "#################################"
# 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 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"
# Get number of available CPU Cores
_ENV_CORE=$(nproc --all)
echo -e "CPU Cores: $_ENV_CORE\n"
# Set that user passwdless sudo
#sudo grep $USER /etc/sudoers.d/README
if sudo grep -q $USER /etc/sudoers.d/README; then
echo -e "User $USER found in /etc/sudoers.d/README. All good!!\n"
else
echo -e "$USER does not have passwdles sudo. Fixing that!!\n"
echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/README
fi
# 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"
# Add value to sysctl
echo "vm.nr_hugepages=$_ENV_CORE" | sudo tee -a /etc/sysctl.conf
fi
echo "#################################"
echo " SETTINGS LOADED"
echo "#################################"

40
start.sh Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
# When this script is:
# * run by crontab, load the settings
# * run by install, do not load settings
start_xmrig () {
screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
}
echo "####################################"
echo " STARTING "
echo "####################################"
if [ -z "$_XMRIG_SCREEN" ]; then
# Load settings when run by crontab
# Also ensures vm.nr_hugepages is set
. settings.sh
# Check another instance is not already running
if ! screen -list | grep -q "$_XMRIG_SCREEN"; then
# Call function
start_xmrig
fi
else
# Call function
start_xmrig
# Unset _XMRIG_SCREEN variable.
# The start script will have to load settings on next start
$_XMRIG_SCREEN=""
fi
# List screen
screen -ls
echo "####################################"
echo " STARTED - use screen -r to view "
echo "####################################"

33
stop.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# When this script is:
# * run by crontab, load the settings
# * run by install, do not load settings
stop_xmrig () {
screen -S $_XMRIG_SCREEN -X kill
}
echo "#################################"
echo " KILLING SCREEN"
echo "#################################"
if [ -z "$_XMRIG_SCREEN" ]; then
# Load settings when run by crontab
echo "Loading settings"
. settings.sh
# Call function
stop_xmrig
else
# Call function
stop_xmrig
fi
# Check results
echo "Screen listing"
screen -ls
echo "#################################"
echo " SCREEN KILLED"
echo "#################################"

21
update.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
# Set get xmrig repository and version by sourcing our version file
. settings.sh
# Kill any current xmrig process
. stop.sh
# Get source and build by sourcing our build file
. build.sh
# Clean users contab
crontab -r $USER
# Source our start script to start process again in a screen
. start.sh
echo "####################################"
echo "# ALL DONE - UPDATE COMPLETE #"
echo "####################################"