Skip to content

Commit

Permalink
Merge pull request #4 from x100111010/dev2
Browse files Browse the repository at this point in the history
Add HiveOS Build and Deployment Workflow to deploy.yaml
  • Loading branch information
0xA001113 authored Jun 27, 2024
2 parents 561addf + 72f7a04 commit 1ec665c
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 12 deletions.
22 changes: 14 additions & 8 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04, ubuntu-latest, windows-latest, macos-latest]
name: Building, ${{ matrix.os }}
name: Building on ${{ matrix.os }}
steps:

- name: Checkout sources
Expand All @@ -32,21 +32,28 @@ jobs:

- name: Build on Linux GNU
if: matrix.os == 'ubuntu-20.04'

# We're using musl to make the binaries statically linked and portable.
run: |
cargo build --target=x86_64-unknown-linux-gnu --release
archive="bin/spectre-miner-${{ github.event.release.tag_name }}-linux-gnu-amd64.zip"
asset_name="spectre-miner-${{ github.event.release.tag_name }}-linux-gnu-amd64"
strip ./target/x86_64-unknown-linux-gnu/release/spectre-miner
mv ./target/x86_64-unknown-linux-gnu/release/spectre-miner ./bin/${asset_name}
zip -r "${archive}" ./bin/${asset_name}
# HiveOS.
hiveos_asset_name="spectre-miner-${{ github.event.release.tag_name }}_hiveos"
hiveos_archive="bin/${hiveos_asset_name}.tar.gz"
cp -r ./hive-os ./bin/spectre-miner
cp ./bin/${asset_name} ./bin/spectre-miner/spectre-miner
sed 's/^ver="custom"/ver="${{ github.event.release.tag_name }}"/g' -i ./bin/spectre-miner/h-stats.sh
tar -czvf "${hiveos_archive}" -C ./bin spectre-miner
# Cleanup.
rm ./bin/${asset_name}
rm -R ./bin/spectre-miner
- name: Build on Linux musl
if: matrix.os == 'ubuntu-latest'

# We're using musl to make the binaries statically linked and portable.
run: |
sudo apt-get install -y musl-tools
rustup target add x86_64-unknown-linux-musl
Expand All @@ -61,8 +68,6 @@ jobs:
- name: Build on Windows
if: matrix.os == 'windows-latest'
shell: bash

# We're using 'bin/' instead of './bin/' as otherwise 7z won't add the directory.
run: |
cargo build --target=x86_64-pc-windows-msvc --release
archive="bin/spectre-miner-${{ github.event.release.tag_name }}-win64-amd64.zip"
Expand Down Expand Up @@ -96,4 +101,5 @@ jobs:
uses: softprops/action-gh-release@v2
with:
files: |
bin/*
bin/*.zip
bin/*.tar.gz
30 changes: 30 additions & 0 deletions hive-os/h-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -x

# Extract the dynamic part (assuming 'nproc' command is your dynamic part)
DYNAMIC_PART=$(echo "$CUSTOM_USER_CONFIG" | grep -oP '\$\((nproc.*)\)')

if [ ! -z "$DYNAMIC_PART" ]; then
EVALUATED_DYNAMIC_PART=$(eval echo "$DYNAMIC_PART")
eval echo "$DYNAMIC_PART" > /dev/null 2>&1

if [ $? -eq 0 ]; then
SAFE_DYNAMIC_PART=$(printf '%s\n' "$DYNAMIC_PART" | sed 's:[][\/.^$*]:\\&:g')
MODIFIED_CONFIG=$(echo "$CUSTOM_USER_CONFIG" | sed "s/$SAFE_DYNAMIC_PART/$EVALUATED_DYNAMIC_PART/")
conf="$MODIFIED_CONFIG"
echo "Modified config after removing executed command: $conf"
else
echo "Error in executing dynamic part. No modifications made."
conf="$CUSTOM_USER_CONFIG"
fi
else
echo "No dynamic part found. No modifications made."
conf="$CUSTOM_USER_CONFIG"
fi

echo "$conf"
echo "$conf" > "$CUSTOM_CONFIG_FILENAME"

echo "Wrote config to $CUSTOM_CONFIG_FILENAME"
echo "The contents of the config file are:"
cat "$CUSTOM_CONFIG_FILENAME"
5 changes: 5 additions & 0 deletions hive-os/h-manifest.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MINER_NAME=spectre-miner
MINER_LOG_BASENAME=/var/log/miner/$MINER_NAME/$MINER_NAME
CUSTOM_LOG_BASENAME=/var/log/miner/custom/custom
CUSTOM_CONFIG_BASENAME=/hive/miners/custom/$MINER_NAME
CUSTOM_CONFIG_FILENAME=$CUSTOM_CONFIG_BASENAME/config.conf
34 changes: 34 additions & 0 deletions hive-os/h-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

# Source the configuration file
source h-manifest.conf

# Define the custom log directory
LOG_DIR=$(dirname "$CUSTOM_LOG_BASENAME")
mkdir -p "$LOG_DIR"

# Check if the custom config filename is defined
if [[ -z ${CUSTOM_CONFIG_FILENAME:-} ]]; then
echo "The config file is not defined"
exit 1
fi

# Set the library path
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/hive/lib

# Read the custom user configuration
CUSTOM_USER_CONFIG=$(< "$CUSTOM_CONFIG_FILENAME")

# Display the arguments
echo "args: $CUSTOM_USER_CONFIG"

MINER=spectre-miner

# Remove the -arch argument and its value
CLEAN=$(echo "$CUSTOM_USER_CONFIG" | sed -E 's/-arch [^ ]+ //')
echo "args are now: $CLEAN"
echo "We are using miner: $MINER"

echo $(date +%s) > "/tmp/miner_start_time"
/hive/miners/custom/$MINER/$MINER $CLEAN 2>&1 | tee -a ${CUSTOM_LOG_BASENAME}.log
echo "Miner has exited"
67 changes: 67 additions & 0 deletions hive-os/h-stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
source /hive/miners/custom/spectre-miner/h-manifest.conf

# Reading log file content
log_file="/var/log/miner/custom/custom.log"

# Read the log file content
log=$(<"$log_file")

get_cpu_temps () {
local t_core=$(cpu-temp)
local l_num_cores=$1
local l_temp=
for (( i=0; i < l_num_cores; i++ )); do
l_temp+="$t_core "
done
echo $l_temp | tr " " "\n" | jq -cs '.'
}

get_cpu_fans () {
local t_fan=0
local l_num_cores=$1
local l_fan=
for (( i=0; i < l_num_cores; i++ )); do
l_fan+="$t_fan "
done
echo $l_fan | tr " " "\n" | jq -cs '.'
}

get_uptime(){
local start_time=$(cat "/tmp/miner_start_time")
local current_time=$(date +%s)
let uptime=current_time-start_time
echo $uptime
}

uptime=$(get_uptime)

# Extract the most recent total khs value from the log
total_khs=$(grep -oP "hashrate is: \K\d+.\d+" <<< "$log" | tail -n1)

# Count the number of blocks submitted successfully
ac=$(grep -coP "Block submitted successfully!" <<< "$log")

rj=0
ver="custom"
algo="spectrex"
cpu_temp=$(/hive/sbin/cpu-temp)
hs_units="hs"

# Construct JSON stats
stats=$(jq -nc \
--arg total_khs "$total_khs" \
--arg khs "$total_khs" \
--arg hs_units "$hs_units" \
--arg hs "[$total_khs]" \
--arg temp "[$cpu_temp]" \
--arg uptime "$uptime" \
--arg ver "$ver" \
--argjson ac "$ac" \
--argjson rj "$rj" \
--arg algo "$algo" \
'{$total_khs, $khs, $hs_units, $hs, $temp, $uptime, $ver, ar: [$ac, $rj], $algo }')

echo "khs: $hs"
echo "stats: $stats"
echo "----------"
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ async fn main() -> Result<(), Error> {

// Display system information
println!("=> System Information:");
println!("System name: {}", System::name().unwrap_or_else(|| "Unknown".to_string()));
println!("System kernel version: {}", System::kernel_version().unwrap_or_else(|| "Unknown".to_string()));
println!("System OS version: {}", System::os_version().unwrap_or_else(|| "Unknown".to_string()));
println!("System host name: {}", System::host_name().unwrap_or_else(|| "Unknown".to_string()));
println!("System name: {}", System::name().unwrap_or("Unknown".to_string()));
println!("System kernel version: {}", System::kernel_version().unwrap_or("Unknown".to_string()));
println!("System OS version: {}", System::os_version().unwrap_or("Unknown".to_string()));
println!("System host name: {}", System::host_name().unwrap_or("Unknown".to_string()));

// Display CPU brand and frequency information only if there is a change
let mut last_cpu_brand = String::new();
Expand Down

0 comments on commit 1ec665c

Please sign in to comment.