forked from shanhaicoder/XENGPUMiner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
miner.sh
108 lines (101 loc) · 2.94 KB
/
miner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
echo "Error: Windows is not supported yet."
read
exit -1
fi
dev_fee_on=false
logging_on=false
opencl=false
silence=false
gpus=0
cpu=false
function display_help() {
echo "Usage: $0 [OPTIONS]"
echo
echo "Options:"
echo " -g, --gpus <num> Set the number of GPUs to use (Default: 1)"
echo " -c, --cpu <num> Running 1 miner in CPU mode (Default: off)"
echo " -d, --devfee, --dev-fee-on Enable dev fee (Default: off)"
echo " -o, --opencl Enable OpenCL computation (Default: off)"
echo " -s, --silence Run in silence/background mode (Default: off)"
echo " -l, --logging-on Record verified blocks into payload.log file (Default: off)"
echo " -h, --help Display this help message and exit"
echo
echo "Note: Script exits if both GPU and CPU modes are off."
exit 0
}
# Process long options
for arg in "$@"; do
shift
case "$arg" in
"--help") set -- "$@" "-h" ;;
"--opencl") set -- "$@" "-o" ;;
"--dev-fee-on") set -- "$@" "-d" ;;
"--devfee") set -- "$@" "-d" ;;
"--silence") set -- "$@" "-s" ;;
"--gpus") set -- "$@" "-g" ;;
"--cpu") set -- "$@" "-c" ;;
"--logging-on") set -- "$@" "-l" ;;
*) set -- "$@" "$arg"
esac
done
# Now, process short options with getopts
while getopts "g:c:ldosh" opt; do
case "$opt" in
g) gpus="$OPTARG" ;;
c) cpu="$OPTARG" ;;
d) dev_fee_on=true ;;
o) opencl=true ;;
s) silence=true ;;
l) logging_on=true ;;
h) display_help ;;
*) echo "Invalid option: -$OPTARG" >&2; exit 1 ;;
esac
done
# cpu mode
if [ $cpu -gt 0 ]; then
echo "Running $cpu miner in CPU mode..."
command="./xengpuminer -m cpu"
for ((i = 0; i < $cpu; i++)); do
if [ $i -eq 0 ]; then
screen -S "cpuminer" -dm bash -c "$command"
else
screen -S "cpuminer" -X screen bash -c "$command"
fi
done
fi
# gpu mode
if [[ $gpus -lt 1 && $cpu -lt 1 ]]; then
echo "Error: Neither gpu nor cpu mode is selected."
exit -1
fi
for ((i = 0; i < $gpus; i++)); do
command="./xengpuminer -d $i"
if $opencl; then
command+=" -m opencl"
fi
if [ $i -eq 0 ]; then
screen -S "gpuminer" -dm bash -c "$command"
else
screen -S "gpuminer" -X screen bash -c "$command"
fi
done
if [ $gpus -gt 0 ]; then
echo "Running $gpus miners in GPU mode..."
fi
command="python3 miner.py"
if $dev_fee_on; then
command+=" --dev-fee-on"
fi
if $logging_on; then
command+=" --logging-on"
fi
if $silence; then
screen -S submitminer -dm bash -c "$command"
echo "If you want to stop, run: pkill xengpuminer && pkill -f submitminer. or simply use pkill -f miner"
else
bash -c "$command"
pkill -f "submitminer"
pkill gpuminer
fi