Skip to content

Instantly share code, notes, and snippets.

@TimoPtr
Last active July 30, 2021 20:09
Show Gist options
  • Save TimoPtr/684bde624c8923177e67964ca924a8de to your computer and use it in GitHub Desktop.
Save TimoPtr/684bde624c8923177e67964ca924a8de to your computer and use it in GitHub Desktop.
This script is meant to be used to replot chia plot
#!/bin/bash
# https://github.com/anordal/shellharden/blob/master/how_to_do_things_safely_in_bash.md#how-to-begin-a-bash-script
set -e # stop the script if any command has non-zero exit status
set -u # throws an error if a variable is not defined
set -o pipefail # returns an error if any command fails in a pipe
shopt -s nullglob globstar # enables empty glob results and recursive globbing
# list of disk where there are plots to replace
DISK_ROOT_PATHS=("/media/timo/WD1")
# folder in DISK_ROOT_PATHS that contains plots to replace
OG_PLOTS_FOLDER="plots"
# folder where to put the new plots
PORTABLE_PLOTS_FOLDER="portablePlots"
# chia_plot config
CHIA_PLOT_PATH="/home/timo/Perso/chia-plotter/build/chia_plot"
TMP_FOLDER="/media/timo/ST2/tmp/" # tmp folder used by the plotter
TMP2_FOLDER="/mnt/ram/" # should be ram disk
DESTINATION_FOLDER="/media/timo/ST2/buffer/" # folder where to put the final plots before moving them
FARMER_KEY="" # -f
CONTRACT="" # -c
THREAD_MULTIPLIER=4 # -r
THREAD_MULTIPLIER2=2 # -K
BUCKET_1_2=512 # -u
BUCKET_3_4=128 # -v
function plot() {
"${CHIA_PLOT_PATH}" \
-f "${FARMER_KEY}" \
-c "${CONTRACT}" \
-t "${TMP_FOLDER}" \
-2 "${TMP2_FOLDER}" \
-d "${DESTINATION_FOLDER}" \
-r "${THREAD_MULTIPLIER}" \
-K "${THREAD_MULTIPLIER2}" \
-u "${BUCKET_1_2}" \
-v "${BUCKET_3_4}"
}
for index in "${!DISK_ROOT_PATHS[@]}"; do
DISK_ROOT_PATH="${DISK_ROOT_PATHS[index]}"
OG_PLOTS_FOLDER_PATH="${DISK_ROOT_PATH}/${OG_PLOTS_FOLDER}/"
PORTABLE_PLOTS_FOLDER_PATH="${DISK_ROOT_PATH}/${PORTABLE_PLOTS_FOLDER}/"
echo "Re plots k32 from $OG_PLOTS_FOLDER_PATH to $PORTABLE_PLOTS_FOLDER_PATH using nft"
find "${OG_PLOTS_FOLDER_PATH}" -name '*k32*' | while read -r og_plot; do
echo "plot in $DESTINATION_FOLDER"
plot
echo "remove $og_plot"
rm "$og_plot"
echo "move generated plot to ${PORTABLE_PLOTS_FOLDER_PATH}"
rsync --remove-source-files --progress --preallocate "${DESTINATION_FOLDER}"* "${PORTABLE_PLOTS_FOLDER_PATH}"
done
done
@ebeng
Copy link

ebeng commented Jul 30, 2021

I made it a bit different. I can run the same script from multiple sources to replot on different NFS shares like this;
It would be nice also, after the script is done, to check how many disk space there is and to plot the additional free disk space.

#!/bin/bash

# https://github.com/anordal/shellharden/blob/master/how_to_do_things_safely_in_bash.md#how-to-begin-a-bash-script
set -e # stop the script if any command has non-zero exit status
set -u # throws an error if a variable is not defined
set -o pipefail # returns an error if any command fails in a pipe

shopt -s nullglob globstar # enables empty glob results and recursive globbing

# list of disk where there are plots to replace
DISK_ROOT_PATHS=("/mnt/nfs")
# folder in DISK_ROOT_PATHS that contains plots to replace
OG_PLOTS_FOLDER="plots"
# folder where to put the new plots
PORTABLE_PLOTS_FOLDER="NFTplots1"


for index in "${!DISK_ROOT_PATHS[@]}"; do

        DISK_ROOT_PATH="${DISK_ROOT_PATHS[index]}"
        OG_PLOTS_FOLDER_PATH="${DISK_ROOT_PATH}/${OG_PLOTS_FOLDER}/"
        PORTABLE_PLOTS_FOLDER_PATH="${DISK_ROOT_PATH}/${PORTABLE_PLOTS_FOLDER}/"

        echo "== STARTING REPLOTTING from $OG_PLOTS_FOLDER_PATH to $PORTABLE_PLOTS_FOLDER_PATH ======="

        find "${OG_PLOTS_FOLDER_PATH}" -name '*k32*' | while read -r og_plot ; do
                echo "======================================================================"
                chia_plot -n 1 -r 8 -t /mnt/tmp/ -2 /mnt/tmp/ -d /mnt/nfs/NFTplots1/ -c xxxxxxx -f xxxxxxx
                echo "remove $og_plot"
                rm "$og_plot"
        done
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment