# This simple BASH script should be placed along with
# BitCrack-master project folder (https://github.com/brichard19/BitCrack)
# and "task_file.txt" generated by "BTC32_Brute_GenTask"
# part of this project (or composed by hands).
#
# It will go through all tasks (BTC addresses / Private
# keys intervals) given in "task_file" bruting each
# of them through BitCrack-master. In case of a
# succesfull brute - it will store the result in 
# appropriate unique *output* file, all the debug
# BitCrack info would be stored aside in *status* file
# (unique for each BTC address/PrivatKey interval).
# Information about processed pair of BTC address and
# Private Key interval would be stored in status_all
# file showing the processing time - it is a common
# solution to watch the content of the status_all file
# in order to monitor the process state.

#!/bin/bash

    # Create unique directory to store the output
out_dir=$(mktemp -u -t 'output_XXXXXX' -p `pwd`)
mkdir $out_dir

    # Loop through each <BTC address/Private keys
    # interval> pair
for task_line in $(cat task_file.txt); do
            # Pars fields in "task_file.txt" lines
        bits=`echo $task_line | cut -d ',' -f1`
       alpha=`echo $task_line | cut -d ',' -f2`
    interval=`echo $task_line | cut -d ',' -f3`
     address=`echo $task_line | cut -d ',' -f4`
      
            # Run the CUDA version of the BitCrack
            # with given <BTC address / PK interval>
            # calculating its completion time
###### IMPORTANT ( to adjust this script to work with
######     CL or other version of the BitCrack just
######     modify "./BitCrack-master/bin/cuBitCrack" the
######     path to program - for example: ./BitCrack-master/bin/clBitCrack)
exec_time=$( { time `./BitCrack-master/bin/cuBitCrack  -o "$out_dir/output_$bits-$alpha.txt" --keyspace "$interval" "$address" > "$out_dir/status_$bits-$alpha.txt" 2>&1`; } 2>&1)

exec_time=`echo $exec_time | grep real`

          # Make a note in "status_all.txt" file about current
          # <BTC add/PK interval> completion specifing the
          # compleition time
      echo "$bits $alpha $interval $address DONE $exec_time" >> "$out_dir/status_all.txt"   

done
