reoganise

This commit is contained in:
Sean Wheller 2019-08-10 17:27:01 +02:00
parent 065c2e6138
commit 94d6c657c9
11 changed files with 130 additions and 209 deletions

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 "BUILD COMPLETE"

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 "CONFIG CREATED"

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 "CRONTAB CREATED"

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 "DEPENDENCIES INSTALLED"

View File

@ -1,30 +1,24 @@
#!/usr/bin/env bash
#!/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
}
@ -50,11 +44,9 @@ check_cpu () {
# 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"
}
calc_threads () {
@ -67,27 +59,23 @@ calc_threads () {
_ENV_CPU_THREADS+=("$i")
done
echo "Thread CPU Affinity: ${_ENV_CPU_THREADS[@]}"
_ENV_CPU_THREAD_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
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"
# Set value in current env
sudo sysctl -w vm.nr_hugepages="$_ENV_CORE"
# Add value to sysctl
sudo sysctl -p
# Add value to sysctl
echo "vm.nr_hugepages=$_ENV_CORE" | sudo tee -a /etc/sysctl.conf
fi
}
echo -e "FUNCTIONS LOADED\n\n"

View File

@ -1,7 +1,14 @@
#!/bin/bash
# Set that user passwdless sudo
_DEBUG=true
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,12 @@ else
echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/README
fi
# Load functions
. functions.sh
# Get settings
. settings.sh
sleep 5
sleep 5
# Stop running instance
. stop.sh
@ -43,6 +53,4 @@ SCREEN=""
. start.sh
echo "####################################"
echo "# ALL DONE - INSTALLATION COMPLETE #"
echo "####################################"
echo -e "INSTALLATION COMPLETE\n"

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 "MAINTENANCE COMPLETE"

View File

@ -1,8 +1,4 @@
#!/usr/bin/env bash
echo "#################################"
echo " LOADING SETTINGS "
echo "#################################"
#!/bin/bash
_EMAIL="miners@prepaidmeters.com"
@ -11,67 +7,18 @@ _RECEIVE_WALLET="854sqm2Cm4TB2XgPHWqSPSbnFAe3SMzdEDzZHpukQ8NHBPFropbnkFmEKiZPgwj
_POOL_SERVER_URL="192.168.4.5"
_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"
# Load functions
. functions.sh
_BACKGROUND="false"
# 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"
_COLORS="true"
# call check_cpu
check_cpu
@ -79,6 +26,92 @@ 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 $_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
# Set repository from which to get the source
_XMRIG_REPO="https://github.com/xmrig/xmrig.git"
# Set name of folder to create when cloning from REPO
_XMRIG_CLONE="xmrig-cpu"
# Set clone directory path
_XMRIG_CLONE_LOCATION="$_WORK_DIR/$_XMRIG_CLONE"
# Set branch from which to build
_XMRIG_BRANCH="beta"
# Set build directory
_XMRIG_BUILD="build"
# Set build directory location
_XMRIG_BUILD_LOCATION="$_XMRIG_CLONE_LOCATION/$_XMRIG_BUILD"
# Set where to install binary
_XMRIG_TARGET_LOCATION="/usr/bin/"
# Set the config file name
_XMRIG_CONFIG="config.json"
# Set config location
_XMRIG_CONFIG_LOCATION="$_WORK_DIR/$_XMRIG_CONFIG"
# Set values for crontab
_USER_CRONSTART="18"
_USER_CRONSTOP="6"
_USER_CRONDAYS="1-5"
# Set the name of the screen created by start script
_XMRIG_SCREEN="xmrig-cpu"
# Run apt maintenance
# 1 = yes 0 = no
_APT_MAINETANCE="1"
@ -87,7 +120,5 @@ _APT_MAINETANCE="1"
# 1 = yes 0 = no
_APT_DEPENDS="1"
echo "#################################"
echo " SETTINGS LOADED"
echo "#################################"
echo -e "SETTINGS LOADED\n\n"

View File

@ -1,32 +1,26 @@
#!/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 "####################################"
# Reload settings and functions for when running standalone
. settings.sh
. functions.sh
if ! screen -list | grep -q "$_XMRIG_SCREEN"; then
# Call function
echo "No screen sessionfound. Starting new screen session."
# Call function
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 "MINING STARTED"

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 "MINING STOPPED"
echo "#################################"
echo " SCREEN KILLED"
echo "#################################"

View File

@ -5,3 +5,5 @@ git pull
# install
. install.sh
sleep 5
echo "UPATE COMPLETE"