Last active
August 16, 2021 03:58
-
-
Save Michael-Stoner/9f69e9cd0e1f82dc71aadbc9d5d4ae75 to your computer and use it in GitHub Desktop.
Chia plotting (w/ pools) script using Mad Max, optional ram drive, and harvester
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#***************************************************************************************************************** | |
# | |
# To pass in a directory of disks, use this as the 3rd parameter | |
# $(find /mnt -maxdepth 1 -type d ! -path /mnt ) | |
# | |
# For example: | |
# .monitorandmove.sh /mnt/plot1 /mnt/plot2 $(find /mnt/farms -maxdepth 1 -type d ! -path /mnt/farms ) | |
# | |
# This will result in something like the following being run: | |
# | |
# .monitorandmove.sh /mnt/plot1 /mnt/plot2 /mnt/farms/farm1 /mnt/farms/farm2 /mnt/farms/farm3 | |
# | |
# NOTE: This will grab every mount point in the provided path, therefore you must ensure the path provided | |
# only contains your farms (and not other mounts like your plotter drives, system drive, jump drives, etc. | |
#***************************************************************************************************************** | |
CHIABLOCKCHAINPATH="~/bin/chia-blockchain" #do not include a trailing backslash | |
MADMAXPATH="~/bin/chia-plotter/build" | |
RAMMOUNT="/mnt/ram" #If you aren't using a ram drive, set this to the tmp2 directory for mad max plotter | |
USERAMDRIVE=1 # set this to 0 if you are not using a ram drive | |
FARMKEY="ENTER YOUR KEY HERE" | |
POOLCONTRACTADDRESS="ENTER YOUR POOL CONTRACT HERE" | |
# take care of tilde expansion of non-evaluated variables | |
CHIABLOCKCHAINPATH="${CHIABLOCKCHAINPATH/#\~/$HOME}" | |
MADMAXPATH="${MADMAXPATH/#\~/$HOME}" | |
RAMMOUNT="${RAMMOUNT/#\~/$HOME}" | |
echo | |
echo | |
echo "Temp Plot Directory: $1" | |
echo "Plot Output Dir: $2" | |
echo "Move To Farms: ${@:3}" | |
echo | |
echo "Chia Blockchain: $CHIABLOCKCHAINPATH" | |
echo "Mad Max Build Path: $MADMAXPATH" | |
if (($USERAMDRIVE == 1)) | |
then | |
echo "Ram Drive Mount: $RAMMOUNT" | |
else | |
echo "Temp 2 Path: $RAMMOUNT" | |
fi | |
echo | |
echo "Farm Key: $FARMKEY" | |
echo "Pool Contract Address: $POOLCONTRACTADDRESS" | |
echo | |
echo | |
#Have user verify command line parameters are correct. | |
while true; do | |
read -p "Are these directories/values correct? " yn | |
case $yn in | |
[Yy]* ) break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
#Look at all the destination directories and calculate the total number of plots | |
TOTALSIZE=0 | |
PLOTSIZE=108900000000 | |
for destDir in "${@:3}" | |
do | |
DIRSIZE=$(df --output=avail -B 1 "$destDir" |tail -n 1) | |
USABLESIZE=$(( (DIRSIZE / PLOTSIZE) * PLOTSIZE )) #Make sure the usable space is an increment of a plot size (i.e. don't count left over storage) | |
TOTALSIZE=$((TOTALSIZE + USABLESIZE)) | |
done | |
#total number of plots possible across all destination drives | |
PLOTS=$((TOTALSIZE/PLOTSIZE)) | |
#fix up paths for mad max. MM requires back slashes to function | |
TEMPDIR=${1%/} | |
TEMPDIR="$TEMPDIR/" | |
FINALDIR=${2%/} | |
FINALDIR="$FINALDIR/" | |
RAMMOUNT=${RAMMOUNT%/} | |
RAMMOUNT="$RAMMOUNT/" | |
#Check if plotter is already running. If so, just indicate a plotter won't be started. IF not, start it. | |
SERVICE="chia_plot" | |
if pgrep -x "$SERVICE" >/dev/null | |
then | |
echo | |
echo "*********************************************************************" | |
echo "$SERVICE is already running. A NEW CHIA PLOTTER WILL NOT BE STARTED" | |
echo "*********************************************************************" | |
else | |
cd $MADMAXPATH | |
if (($USERAMDRIVE == 1)) | |
then | |
echo | |
echo "Mounting Ram Drive" | |
sudo mount -t tmpfs -o size=110G tmpfs $RAMMOUNT | |
fi | |
rm $RAMMOUNT/* 2> /dev/null #ignore any error | |
echo | |
echo | |
echo "Starting $PLOTS plots" | |
echo | |
#running chia plot in another terminal so that the outputs aren't mixed on std out and so you can kill the script without killing the plotter | |
#This command is for Ubuntu/Debian based distributions that use the gnome gui. If you are using a different distro, you may need to change this | |
gnome-terminal -- ./chia_plot -n $PLOTS -r 24 -t $TEMPDIR -2 $RAMMOUNT -d $FINALDIR -c $POOLCONTRACTADDRESS -f $FARMKEY ; read line & | |
fi | |
#add all the desintation directories to the harvester | |
echo "Adding farms to harvester" | |
#cd "${CHIABLOCKCHAINPATH}" | |
cd ~/bin/chia-blockchain | |
. ./activate | |
for destDir in "${@:3}" | |
do | |
destDir=${destDir%/} | |
destDir="$destDir/" | |
chia plots add -d "$destDir" | |
done | |
echo | |
echo "Starting Harvester" | |
chia start harvester | |
#Monitor for *.plot files and move them to a farm that has available space | |
echo | |
echo "Starting to monitor $2" | |
inotifywait -m $2 -e moved_to | | |
while read dir action file; do | |
if [ "${file: -5}" == ".plot" ] | |
then | |
echo | |
echo "$file created" | |
echo | |
for destDir in "${@:3}" | |
do | |
destDir=${destDir%/} | |
destDir="$destDir/" | |
FREE=$(df -k --output=avail "$destDir" | tail -n1) | |
PLOTS=$((FREE/($PLOTSIZE/1000))) | |
echo "Checking Farm: $destDir" | |
echo "--Free Space: $FREE" | |
echo "--Plot Space: $PLOTS" | |
if [ $PLOTS -ge 1 ] | |
then | |
echo | |
timestamp=$(date +"%T") | |
echo "$timestamp - Moving to $destDir" | |
mv "$2/$file" "$destDir/${file}.move" | |
mv "$destDir/${file}.move" "$destDir/${file}" | |
timestamp=$(date +"%T") | |
echo "$timestamp - Finished Moving File" | |
echo | |
echo "Continuing Watching For Files..." | |
echo | |
break; | |
else | |
echo "--Not Enough Space" | |
fi | |
echo | |
done | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment