diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 8cd3dbb..e10fa3d 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -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 @@ -32,8 +32,6 @@ 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" @@ -41,12 +39,21 @@ jobs: 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 @@ -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" @@ -96,4 +101,5 @@ jobs: uses: softprops/action-gh-release@v2 with: files: | - bin/* + bin/*.zip + bin/*.tar.gz diff --git a/hive-os/h-config.sh b/hive-os/h-config.sh new file mode 100755 index 0000000..cbd01c2 --- /dev/null +++ b/hive-os/h-config.sh @@ -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" \ No newline at end of file diff --git a/hive-os/h-manifest.conf b/hive-os/h-manifest.conf new file mode 100755 index 0000000..7a76cc4 --- /dev/null +++ b/hive-os/h-manifest.conf @@ -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 diff --git a/hive-os/h-run.sh b/hive-os/h-run.sh new file mode 100755 index 0000000..b686361 --- /dev/null +++ b/hive-os/h-run.sh @@ -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" \ No newline at end of file diff --git a/hive-os/h-stats.sh b/hive-os/h-stats.sh new file mode 100755 index 0000000..c675294 --- /dev/null +++ b/hive-os/h-stats.sh @@ -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 "----------" diff --git a/src/main.rs b/src/main.rs index 6253815..4b884f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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();