From 4a9342704b86caa4bda585eb3370c21a75d0c093 Mon Sep 17 00:00:00 2001 From: Tomer Levy Date: Sun, 16 Jan 2022 12:13:52 +0200 Subject: [PATCH 1/2] Added Merlin's files --- integrations/hiveos/createmanifest.sh | 42 ++++++++++++++++++++++++++ integrations/hiveos/h-config.sh | 21 +++++++++++++ integrations/hiveos/h-run.sh | 29 ++++++++++++++++++ integrations/hiveos/h-stats.sh | 43 +++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100755 integrations/hiveos/createmanifest.sh create mode 100755 integrations/hiveos/h-config.sh create mode 100755 integrations/hiveos/h-run.sh create mode 100755 integrations/hiveos/h-stats.sh diff --git a/integrations/hiveos/createmanifest.sh b/integrations/hiveos/createmanifest.sh new file mode 100755 index 0000000..fc49fb1 --- /dev/null +++ b/integrations/hiveos/createmanifest.sh @@ -0,0 +1,42 @@ +#################################################################################### +### +### kaspa-miner +### https://github.com/tmrlvi/kaspa-miner/releases +### +### Hive integration: Merlin +### +#################################################################################### + +if [ "$#" -ne "2" ] + then + echo "No arguments supplied. Call using createmanifest.sh " + exit +fi +cat > h-manifest.conf << EOF +#################################################################################### +### +### kaspa-miner +### https://github.com/tmrlvi/kaspa-miner/releases +### +### Hive integration: Merlin +### +#################################################################################### + +# The name of the miner +CUSTOM_NAME=kaspa-miner + +# Optional version of your custom miner package +CUSTOM_VERSION=$1 +CUSTOM_BUILD=0 +CUSTOM_MINERBIN=$2 + +# Full path to miner config file +CUSTOM_CONFIG_FILENAME=/hive/miners/custom/$CUSTOM_NAME/config.ini + +# Full path to log file basename. WITHOUT EXTENSION (don't include .log at the end) +# Used to truncate logs and rotate, +# E.g. /var/log/miner/mysuperminer/somelogname (filename without .log at the end) +CUSTOM_LOG_BASENAME=/var/log/miner/$CUSTOM_NAME + +WEB_PORT=3338 +EOF diff --git a/integrations/hiveos/h-config.sh b/integrations/hiveos/h-config.sh new file mode 100755 index 0000000..381892c --- /dev/null +++ b/integrations/hiveos/h-config.sh @@ -0,0 +1,21 @@ +#################################################################################### +### +### kaspa-miner +### https://github.com/tmrlvi/kaspa-miner/releases +### +### Hive integration: Merlin +### +#################################################################################### + +#!/usr/bin/env bash +[[ -e /hive/custom ]] && . /hive/custom/kaspa-miner/h-manifest.conf +[[ -e /hive/miners/custom ]] && . /hive/miners/custom/kaspa-miner/h-manifest.conf +conf="" +conf+=" --kaspad-address=$CUSTOM_URL --mining-address $CUSTOM_TEMPLATE" + + +[[ ! -z $CUSTOM_USER_CONFIG ]] && conf+=" $CUSTOM_USER_CONFIG" + +echo "$conf" +echo "$conf" > $CUSTOM_CONFIG_FILENAME + diff --git a/integrations/hiveos/h-run.sh b/integrations/hiveos/h-run.sh new file mode 100755 index 0000000..4ca67e0 --- /dev/null +++ b/integrations/hiveos/h-run.sh @@ -0,0 +1,29 @@ +#################################################################################### +### +### kaspa-miner +### https://github.com/tmrlvi/kaspa-miner/releases +### +### Hive integration: Merlin +### +#################################################################################### + +#!/usr/bin/env bash + +cd `dirname $0` + +[ -t 1 ] && . colors + +. h-manifest.conf + +echo $CUSTOM_NAME +echo $CUSTOM_LOG_BASENAME +echo $CUSTOM_CONFIG_FILENAME + +[[ -z $CUSTOM_LOG_BASENAME ]] && echo -e "${RED}No CUSTOM_LOG_BASENAME is set${NOCOLOR}" && exit 1 +[[ -z $CUSTOM_CONFIG_FILENAME ]] && echo -e "${RED}No CUSTOM_CONFIG_FILENAME is set${NOCOLOR}" && exit 1 +[[ ! -f $CUSTOM_CONFIG_FILENAME ]] && echo -e "${RED}Custom config ${YELLOW}$CUSTOM_CONFIG_FILENAME${RED} is not found${NOCOLOR}" && exit 1 + + +./$CUSTOM_MINERBIN $(< $CUSTOM_CONFIG_FILENAME) $@ 2>&1 | tee $CUSTOM_LOG_BASENAME.log + + diff --git a/integrations/hiveos/h-stats.sh b/integrations/hiveos/h-stats.sh new file mode 100755 index 0000000..7279661 --- /dev/null +++ b/integrations/hiveos/h-stats.sh @@ -0,0 +1,43 @@ +#################################################################################### +### +### kaspa-miner +### https://github.com/tmrlvi/kaspa-miner/releases +### +### Hive integration: Merlin +### +#################################################################################### + +#!/usr/bin/env bash + +####################### +# MAIN script body +####################### + +. /hive/miners/custom/kaspa-miner/h-manifest.conf + stats_raw=`cat $CUSTOM_LOG_BASENAME.log | grep -w "hashrate" | tail -n 1 ` + +#Calculate miner log freshness + +maxDelay=120 +time_now=`date +%T | awk -F: '{ print ($1 * 3600) + $2*60 + $3 }'` +time_rep=`echo $stats_raw | awk -FT '{print $2}' | awk -FZ '{print $1}' | awk -F: '{ print (($1+1)*3600) + $2*60 + $3}'` +diffTime=`echo $((time_now-time_rep)) | tr -d '-'` + +if [ "$diffTime" -lt "$maxDelay" ]; then + total_hashrate=`echo $stats_raw | awk '{print $7}' | cut -d "." -f 1,2 --output-delimiter='' | sed 's/$/0/'` + if [[ $stats_raw == *"Ghash"* ]]; then + total_hashrate=$(($total_hashrate*1000)) + fi + stats=$(jq -nc \ + --argjson hs "[$total_hashrate]"\ + --arg ver "$CUSTOM_VERSION" \ + --arg ths "$total_hashrate" \ + '{ hs: $hs, hs_units: "khs", algo : "heavyhash", ver:$ver }') + khs=$total_hashrate +else + khs=0 + stats="null" +fi + +[[ -z $khs ]] && khs=0 +[[ -z $stats ]] && stats="null" From c164c3442aa01130d390879036abe458232580b6 Mon Sep 17 00:00:00 2001 From: Tomer Levy Date: Sun, 16 Jan 2022 20:37:50 +0200 Subject: [PATCH 2/2] Created a build script --- .github/workflows/ci.yaml | 12 ++++++++ .github/workflows/deploy.yaml | 55 ++++++++++++++++++++++++++++++++++- integrations/hiveos/build.sh | 4 +++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 integrations/hiveos/build.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 663557b..bf2981d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -53,6 +53,12 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 + - name: Fix LibOpenCL on Linux + if: runner.os == 'Linux' + run: | + sudo apt update + sudo apt install ocl-icd-opencl-dev -y + - name: Fix CRLF on Windows if: runner.os == 'Windows' run: git config --global core.autocrlf false @@ -126,6 +132,12 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 + - name: Fix LibOpenCL on Linux + if: runner.os == 'Linux' + run: | + sudo apt update + sudo apt install ocl-icd-opencl-dev -y + - name: Fix CRLF on Windows if: runner.os == 'Windows' run: git config --global core.autocrlf false diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 4db84dd..cb24494 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -21,7 +21,7 @@ jobs: if: runner.os == 'Linux' run: | sudo apt update - sudo apt install ocl-icd-opencl-dev + sudo apt install ocl-icd-opencl-dev -y - name: Check out code into the Go module directory uses: actions/checkout@v2 @@ -92,3 +92,56 @@ jobs: asset_path: "./${{ env.archive }}" asset_name: "${{ env.asset_name }}" asset_content_type: application/zip + + intergrations: + runs-on: ubuntu-18.04 + strategy: + fail-fast: false + matrix: + # Build gnu-linux on ubuntu-18.04 and musl on ubuntu latest + itegration: [ hiveos ] + name: Integrating, ${{ matrix.itegration }} + steps: + - name: Fix LibOpenCL on Linux + run: | + sudo apt update + sudo apt install ocl-icd-opencl-dev -y + + - name: Check out code into the module directory + uses: actions/checkout@v2 + + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Install CUDA Linux + if: runner.os == 'Linux' + uses: tmrlvi/cuda-toolkit@master + with: + cuda: '11.2.2' + + - name: Build ${{ matrix.itegration }} Script + run: | + cargo build --target=x86_64-unknown-linux-gnu --release --all + binary_name="kaspa-miner-${{ github.event.release.tag_name }}-linux-gnu-amd64" + asset_name="kaspa-miner-${{ matrix.itegration }}" + strip ./target/x86_64-unknown-linux-gnu/release/kaspa-miner + mkdir ${asset_name} + mv ./target/x86_64-unknown-linux-gnu/release/kaspa-miner ${asset_name}/${binary_name} + mv ./target/x86_64-unknown-linux-gnu/release/libkaspa*.so ${asset_name}/ + bash integrations/${{ matrix.itegration }}/build.sh "${{ github.event.release.tag_name }}" "${binary_name}" "${asset_name}" + echo "archive=${asset_name}.tgz" >> $GITHUB_ENV + echo "asset_name=${asset_name}.tgz" >> $GITHUB_ENV + + - name: Upload release asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: "./${{ env.archive }}" + asset_name: "${{ env.asset_name }}" + asset_content_type: application/zip diff --git a/integrations/hiveos/build.sh b/integrations/hiveos/build.sh new file mode 100644 index 0000000..b671a81 --- /dev/null +++ b/integrations/hiveos/build.sh @@ -0,0 +1,4 @@ +integrations/hiveos/createmanifest.sh $1 $2 +mkdir $3 +cp h-manifest.conf integrations/hiveos/*.sh $2/* $3 +tar czvf $3.tgz $3 \ No newline at end of file