HiveOS support

This commit is contained in:
Haifa Bogdan Adnan 2019-08-28 00:56:55 +03:00
parent 2a62844fe8
commit 370cf7487b
5 changed files with 147 additions and 0 deletions

17
hiveos/h-config.sh Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
. $MINER_DIR/$CUSTOM_MINER/h-manifest.conf
[[ -z $CUSTOM_TEMPLATE ]] && echo -e "${YELLOW}CUSTOM_TEMPLATE is empty${NOCOLOR}" && return 1
[[ -z $CUSTOM_URL ]] && echo -e "${YELLOW}CUSTOM_URL is empty${NOCOLOR}" && return 1
conf="-o ${CUSTOM_URL} -u ${CUSTOM_TEMPLATE} -p $WORKER_NAME --api-port ${CUSTOM_API_PORT} ${CUSTOM_USER_CONFIG}"
#replace tpl values in whole file
[[ ! -z $EWAL ]] && conf=$(sed "s/%EWAL%/$EWAL/g" <<< "$conf")
[[ ! -z $DWAL ]] && conf=$(sed "s/%DWAL%/$DWAL/g" <<< "$conf")
[[ ! -z $ZWAL ]] && conf=$(sed "s/%ZWAL%/$ZWAL/g" <<< "$conf")
[[ ! -z $EMAIL ]] && conf=$(sed "s/%EMAIL%/$EMAIL/g" <<< "$conf")
[[ ! -z $WORKER_NAME ]] && conf=$(sed "s/%WORKER_NAME%/$WORKER_NAME/g" <<< "$conf")
echo "$conf" > $MINER_DIR/$CUSTOM_MINER/$CUSTOM_NAME.conf

20
hiveos/h-manifest.conf Normal file
View file

@ -0,0 +1,20 @@
#
# NinjaRig by Haifa Bogdan Adnan
#
# GitHub src: https://github.com/bogdanadnan/ninjarig
#
# HiveOS adaptation by Haifa Bogdan Adnan
#
CUSTOM_NAME=ninjarig
CUSTOM_VERSION=1.0.0
CUSTOM_CONFIG_FILENAME=/hive/miners/custom/${CUSTOM_NAME}/${CUSTOM_NAME}.conf
CUSTOM_LOG_BASENAME=/var/log/miner/$CUSTOM_NAME/$CUSTOM_NAME
CUSTOM_LOG_FOLDER=/var/log/miner/$CUSTOM_NAME
CUSTOM_API_PORT=10000

20
hiveos/h-run.sh Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env bash
. h-manifest.conf
CUSTOM_API_PORT=`./parse-api-port.sh`
#try to release TIME_WAIT sockets
while true; do
for con in `netstat -anp | grep TIME_WAIT | grep ${CUSTOM_API_PORT} | awk '{print $5}'`; do
killcx $con lo
done
netstat -anp | grep TIME_WAIT | grep ${CUSTOM_API_PORT} &&
continue ||
break
done
mkdir -p $CUSTOM_LOG_FOLDER
echo -e "Running ${CYAN}iximiner${NOCOLOR}" | tee ${CUSTOM_LOG_FOLDER}/${CUSTOM_NAME}.log
./ninjarig $(< $CUSTOM_NAME.conf)$@ 2>&1 | tee ${CUSTOM_LOG_FOLDER}/${CUSTOM_NAME}.log

59
hiveos/h-stats.sh Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env bash
. $MINER_DIR/$CUSTOM_MINER/h-manifest.conf
. $MINER_DIR/$CUSTOM_MINER/parse-api-port.sh
json_data=`curl -s http://localhost:${CUSTOM_API_PORT}`
algo=`echo $json_data | jq -c ".algo" | sed 's/"//g'`
hashrates=`echo $json_data | jq -c ".hashers[].hashrate[0]"`
shares=`echo $json_data | jq -c ".results.shares_good"`
totalShares=`echo $json_data | jq -c ".results.shares_total"`
total_hashrate=`echo $json_data | jq -c ".hashrate.total[0]"`
total_hashrate=`echo $total_hashrate/1000 | jq -nf /dev/stdin`
rejects=$((totalShares-shares))
gpu_data=`gpu-stats`
busids_data=`echo $gpu_data | jq -r ".busids[]"`
busids=($busids_data)
temp_data=`echo $gpu_data | jq -r ".temp[]"`
temp_local=($temp_data)
fan_data=`echo $gpu_data | jq -r ".fan[]"`
fan_local=($fan_data)
device_bus_data=`echo $json_data | jq -c ".hashers[].bus_id"`
device_bus=($device_bus_data)
stats_temp=""
stats_fan=""
bus_numbers=""
for i in "${!device_bus[@]}"; do
found=0
for j in "${!busids[@]}"; do
if [ "${device_bus[$i],,}" == "\"${busids[$j],,}\"" ]; then
stats_temp="$stats_temp ${temp_local[$j]}"
stats_fan="$stats_fan ${fan_local[$j]}"
bus_number=$(echo ${busids[$j]} | cut -d ':' -f 1 | awk '{printf("%d\n", "0x"$1)}')
bus_numbers="$bus_numbers $bus_number"
found=1
break
fi
done
if [ $found -eq 0 ]; then
stats_temp="$stats_temp 0"
stats_fan="$stats_fan 0"
bus_numbers="$bus_numbers 0"
fi
done
khs=$total_hashrate
hashrates=$hashrates
stats=$(jq -nc \
--argjson hashrates "`echo "$hashrates" | tr " " "\n" | jq -cs '.'`" \
--argjson hs "`echo "$hashrates" | tr " " "\n" | jq -cs '.'`" \
--arg hs_units "hs" \
--argjson temp "`echo "$stats_temp" | tr " " "\n" | jq -cs '.'`" \
--argjson fan "`echo "$stats_fan" | tr " " "\n" | jq -cs '.'`" \
--arg ac "$shares" --arg rj "$rejects" \
--argjson bus_numbers "`echo "$bus_numbers" | tr " " "\n" | jq -cs '.'`" \
--arg algo $algo \
'{$hashrates, $hs, $hs_units, $temp, $fan, ar: [$ac, $rj], $bus_numbers, $algo}')

31
hiveos/parse-api-port.sh Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env bash
if [ -z "$MINER_DIR" ]
then
. ./h-manifest.conf
args=$(getopt -q -u -l "api-port:" -o "l:" -- `cat ./$CUSTOM_NAME.conf`)
else
. $MINER_DIR/$CUSTOM_MINER/h-manifest.conf
args=$(getopt -q -u -l "api-port:" -o "l:" -- `cat $MINER_DIR/$CUSTOM_MINER/$CUSTOM_NAME.conf`)
fi
eval set -- "$args"
while [ $# -ge 1 ]; do
case "$1" in
--)
shift
break
;;
--api-port)
CUSTOM_API_PORT="$2"
shift
;;
esac
shift
done
if [ -z "$MINER_DIR" ]
then
echo $CUSTOM_API_PORT
fi