xmrig-bash-scripts/functions.sh

107 lines
2.8 KiB
Bash
Raw Normal View History

2019-08-10 18:27:01 +03:00
#!/bin/bash
2019-08-05 22:49:49 +03:00
2019-08-11 11:27:39 +03:00
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
2019-08-11 11:45:15 +03:00
echo "${_CYAN}Settings from loaded from mysettings.sh.${_RESET}"
2019-08-11 11:27:39 +03:00
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 () {
2019-07-27 13:00:13 +03:00
if [ -d $_XMRIG_BUILD_LOCATION ]; then
# Remove existing build directory
rm -rf $_XMRIG_BUILD_LOCATION
# Make new build directory
mkdir $_XMRIG_BUILD_LOCATION
else
# Make new build directory
mkdir $_XMRIG_BUILD_LOCATION
fi
# Change to build directory
cd $_XMRIG_BUILD_LOCATION
# Configure cmake scafolding
cmake .. -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7
# Compile the software
make
}
2019-08-11 11:27:39 +03:00
function start_xmrig () {
2019-07-27 13:00:13 +03:00
screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
}
2019-08-11 11:27:39 +03:00
function stop_xmrig () {
2019-07-27 13:00:13 +03:00
screen -S $_XMRIG_SCREEN -X kill
}
2019-08-10 10:36:48 +03:00
2019-08-11 11:27:39 +03:00
function check_cpu () {
2019-08-10 10:36:48 +03:00
# 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)
}
2019-08-11 11:27:39 +03:00
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 ))
2019-08-10 10:36:48 +03:00
# Affine number of threads for _CPU_CN
_COUNTER="$(( $_ENV_THREAD_QTY-1 ))"
2019-08-10 10:36:48 +03:00
2019-08-10 19:25:10 +03:00
_ENV_CPU_THREAD_AFFINITY="$(seq -s " " 0 $_COUNTER)"
2019-08-10 10:36:48 +03:00
2019-08-10 19:25:10 +03:00
}
2019-08-10 10:36:48 +03:00
2019-08-11 11:27:39 +03:00
function calc_hugepages () {
2019-08-10 19:25:10 +03:00
# 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"
2019-08-10 19:25:10 +03:00
# Add value to sysctl
sudo sysctl -p
fi
2019-08-10 10:36:48 +03:00
}
2019-08-10 20:43:18 +03:00
echo -e "${_GREEN}FUNCTIONS LOADED${_RESET}"