@@ -1,44 +1,80 @@
1−#!/usr/bin/env bash
1+#!/bin/bash
3+echo -e "${_GREEN}LOADING FUNCTIONS${_RESET}"
5+function prompt_confirm() {
7+ read -r -n 1 -p "${1:-Continue?} [y/n]: " REPLY
9+ [yY]) echo ; return 0 ;;
10+ [nN]) echo ; return 1 ;;
11+ *) printf " \033[31m %s \n\033[0m" "invalid input [y/n]"
16+function show_settings () {
17+ echo "${_CYAN}Settings from loaded environment:${_RESET}"
18+ echo "${_GREEN}Pool URL:${_RESET}: $_POOLS_URL"
19+ echo "${_GREEN}Recieve Wallet:${_RESET}: $_POOLS_USER"
20+ echo "${_GREEN}Email Address:${_RESET}: $_POOLS_PASS"
23+function show_mysettings () {
24+ if [ -f $_WORK_DIR/$_MYSETTINGS_FILE ]; then
26+ echo "${_CYAN}Settings from mysettings.sh:${_RESET}"
27+ echo "${_GREEN}Pool URL:${_RESET}: $_POOLS_URL"
28+ echo "${_GREEN}Recieve Wallet:${_RESET}: $_POOLS_USER"
29+ echo "${_GREEN}Email Address:${_RESET}: $_POOLS_PASS"
33+function load_mysettings () {
34+ if [ -f $_WORK_DIR/$_MYSETTINGS_FILE ]; then
39+function my_config_json () {
41+ _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) opencl=$(jo enabled=$_OPENCL_ENABLED cache=$_OPENCL_CACHE loader=$_OPENCL_LOADER platform=$_OPENCL_PLATFORM) 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) log-file=$_LOG_FILE 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)
3−build_xmrig () {
45+function build_xmrig () {
4 if [ -d $_XMRIG_BUILD_LOCATION ]; then
46 if [ -d $_XMRIG_BUILD_LOCATION ]; then
5 # Remove existing build directory
47 # Remove existing build directory
6− echo "Found old build directory. Removing"
7 rm -rf $_XMRIG_BUILD_LOCATION
48 rm -rf $_XMRIG_BUILD_LOCATION
9 # Make new build directory
50 # Make new build directory
10− echo "Creating a build directory"
11 mkdir $_XMRIG_BUILD_LOCATION
51 mkdir $_XMRIG_BUILD_LOCATION
13 # Make new build directory
53 # Make new build directory
14− echo "Creating a build directory"
15 mkdir $_XMRIG_BUILD_LOCATION
54 mkdir $_XMRIG_BUILD_LOCATION
18 # Change to build directory
57 # Change to build directory
19− echo "Changing to build directory"
20 cd $_XMRIG_BUILD_LOCATION
58 cd $_XMRIG_BUILD_LOCATION
22 # Configure cmake scafolding
60 # Configure cmake scafolding
23− echo "Configuring cmake scafolding"
61+ cmake ..
24− cmake .. -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7
26 # Compile the software
63 # Compile the software
27− echo "Starting build"
32−start_xmrig () {
68+function start_xmrig () {
33 screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
69 screen -dmS $_XMRIG_SCREEN xmrig --config=$_XMRIG_CONFIG_LOCATION
37−stop_xmrig () {
73+function stop_xmrig () {
38 screen -S $_XMRIG_SCREEN -X kill
74 screen -S $_XMRIG_SCREEN -X kill
41−check_cpu () {
77+function check_cpu () {
42 # Check if CPU supports AES-NI
78 # Check if CPU supports AES-NI
43 cpuid | grep -i aes > hw-aes.txt
79 cpuid | grep -i aes > hw-aes.txt
44 if grep -q true "hw-aes.txt"; then
80 if grep -q true "hw-aes.txt"; then
@@ -50,44 +86,40 @@ check_cpu () {
51 # Get number of available CPU Cores
87 # Get number of available CPU Cores
52 _ENV_CORE=$(nproc --all)
88 _ENV_CORE=$(nproc --all)
53− echo -e "CPU Cores: $_ENV_CORE\n"
55 # Get CPU L3 cache value
90 # Get CPU L3 cache value
56 _ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
91 _ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
57− echo -e "L3 Cache in byte: $_ENV_CORE_L3\n"
60−calc_threads () {
94+function calc_threads () {
61−
95+ # Each thread needs 2048 byte (2 Megabyte)
62− # Affine number of threads for _CPU_CN
96+ # Calculate number of threads supported with L3 cache size
63− _COUNTER="$(($_ENV_CORE_THREADS - 1))"
66− for i in `seq 0 $_COUNTER`; do
98+ _ENV_THREAD_QTY=$(( ($_ENV_CORE_L3/2048)/1000 ))
67− _ENV_CPU_THREADS+=("$i")
70− echo "Thread CPU Affinity: ${_ENV_CPU_THREADS[@]}"
100+ # Affine number of threads for _CPU_CN
71− _ENV_CPU_THREAD_AFFINITY="${_ENV_CPU_THREADS[@]}"
101+ _COUNTER="$(( $_ENV_THREAD_QTY-1 ))"
73− # Setting according to cpu cores but xmrig will not use all
103+ _ENV_CPU_THREAD_AFFINITY="$(seq -s " " 0 $_COUNTER)"
74− # change to make value use _ENV_CORE_THREADS
75− # Check that hugepages set in /etc/sysctl.conf
76− _ENV_CHECK="nr_hugepages"
78− if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
105+}
79− echo "Found nr_hugepages in /etc/sysctl.conf. All good!!"
80− echo -e "Refreshing sysctl configuration just to be sure.\n"
83− # Set value in current env
84− echo -e "Did not find nr_hugepages in /etc/sysctl.conf. Fixing that!!\n"
85− sudo sysctl -w vm.nr_hugepages="$_ENV_CORE"
88− # Add value to sysctl
107+function calc_hugepages () {
89− echo "vm.nr_hugepages=$_ENV_CORE" | sudo tee -a /etc/sysctl.conf
108+ # Setting according to cpu cores but xmrig will not use all
109+ # change to make value use _ENV_CORE_THREADS
110+ # Check that hugepages set in /etc/sysctl.conf
112+ _ENV_CHECK="nr_hugepages"
114+ if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
117+ # Set value in current env
118+ sudo sysctl -w vm.nr_hugepages="$_ENV_THREAD_QTY"
119+ # Add value to sysctl
125+echo -e "${_CYAN}FUNCTIONS LOADED${_RESET}"