-
Notifications
You must be signed in to change notification settings - Fork 2
/
SETUP-CHIA-PLOTTER.sh
171 lines (147 loc) · 6.92 KB
/
SETUP-CHIA-PLOTTER.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
# Chia Swar Plotter Setup
# By Rahim Khoja ([email protected])
# https://www.linkedin.com/in/rahim-khoja-879944139/
echo
echo -e "\033[0;31m░░░░░░░░▀▀▀██████▄▄▄"
echo "░░░░░░▄▄▄▄▄░░█████████▄ "
echo "░░░░░▀▀▀▀█████▌░▀▐▄░▀▐█ "
echo "░░░▀▀█████▄▄░▀██████▄██ "
echo "░░░▀▄▄▄▄▄░░▀▀█▄▀█════█▀"
echo "░░░░░░░░▀▀▀▄░░▀▀███░▀░░░░░░▄▄"
echo "░░░░░▄███▀▀██▄████████▄░▄▀▀▀██▌"
echo "░░░██▀▄▄▄██▀▄███▀▀▀▀████░░░░░▀█▄"
echo "▄▀▀▀▄██▄▀▀▌█████████████░░░░▌▄▄▀"
echo "▌░░░░▐▀████▐███████████▌"
echo "▀▄░░▄▀░░░▀▀██████████▀"
echo "░░▀▀░░░░░░▀▀█████████▀"
echo "░░░░░░░░▄▄██▀██████▀█"
echo "░░░░░░▄██▀░░░░░▀▀▀░░█"
echo "░░░░░▄█░░░░░░░░░░░░░▐▌"
echo "░▄▄▄▄█▌░░░░░░░░░░░░░░▀█▄▄▄▄▀▀▄"
echo -e "▌░░░░░▐░░░░░░░░░░░░░░░░▀▀▄▄▄▀\033[0m"
echo "---The Chia Swar Plotter Setup Script---"
echo "---By: Rahim Khoja ([email protected])---"
echo
# Requirements: Ubuntu 20.04 LTS (Desktop Minimal)
# User 'plotter' added to system
# Internet Access
# An NVME Drive for Plotting (Must not be boot disk)
# A SSD Boot Disk (Chia seems to need this) [It May be fine with 7200RPM+ Disk]
# The Main Wallet's CA (Shared by NFS is best)
# The Plot Storage Location (NFS to Remote Storage is best)
# Stop on Error
set -eE # same as: `set -o errexit -o errtrace`
# Failure Function
function failure() {
local lineno=$1
local msg=$2
echo ""
echo -e "\033[0;31mError at Line Number $lineno: '$msg'\033[0m"
echo ""
}
# Failure Function Trap
trap 'failure ${LINENO} "$BASH_COMMAND"' ERR
# Check the bash shell script is being run by root/sudo
if [[ $EUID -ne 0 ]];
then
echo "This script must be run with sudo" 1>&2
exit 1
fi
# Update and Upgrade System
apt -y update
apt -y upgrade
apt -y install git
apt -y install python3
apt -y install python3-pip
# Setup NVME as Plotting Disk
wipefs /dev/nvme0n1
(
echo o # Create a new empty DOS partition table
echo n # Add a new partition
echo p # Primary partition
echo 1 # Partition number
echo # First sector (Accept default: 1)
echo # Last sector (Accept default: varies)
echo w # Write changes
) | sudo fdisk /dev/nvme0n1
mkfs.ext4 -F /dev/nvme0n1p1
mkdir /mnt/plot || true
echo "/dev/nvme0n1p1 /mnt/plot ext4 defaults 0 0" >> /etc/fstab
mount -a
chmod -R 777 /mnt/plot
# Install Chia as Plotter User
cd /usr/share
git clone https://github.com/Chia-Network/chia-blockchain.git -b latest --recurse-submodules
chmod -R 777 /usr/share/chia-blockchain
sudo -u plotter -- sh -c "cd /usr/share/chia-blockchain; sh install.sh"
# Install Chia Gui as Plotter User
sudo -u plotter -- sh -c "cd /usr/share/chia-blockchain; . ./activate; sh install-gui.sh"
# Install SWAR Plot Manager as Plotter User
cd /usr/share
git clone https://github.com/swar/Swar-Chia-Plot-Manager.git
chmod -R 777 /usr/share/Swar-Chia-Plot-Manager
sudo -u plotter -- sh -c "cd /usr/share/Swar-Chia-Plot-Manager; /usr/bin/pip3 install -r requirements.txt"
cp /usr/share/Swar-Chia-Plot-Manager/config.yaml.default /usr/share/Swar-Chia-Plot-Manager/config.yaml
# Crate CHIA & Swar Log Dir
mkdir /var/log/chia || true
mkdir /var/log/swar || true
chmod -R 777 /var/log/chia
chmod -R 777 /var/log/swar
# Stop Chia Daemon
sudo -u plotter -- sh -c "/usr/share/chia-blockchain/venv/bin/chia stop all -d" || true
# Get System Info
# Get CPU (Threads)
num_cpus=$(nproc)
echo "Total Threads: ${num_cpus}"
max_parallel_cpu_plots=$(((${num_cpus}-1)/2))
echo "Max Possible parallel CPU Plots: ${max_parallel_cpu_plots}"
# Get Total Memory
mem_kb=$(grep MemTotal /proc/meminfo | awk {'print $2'})
mem_mb=$((${mem_kb}/1024))
max_parallel_memory_plots=$(((${mem_mb}-1024)/3500))
echo "Memory in KB: ${mem_kb}"
echo "Memory in MB: ${mem_mb}"
echo "Max Possible parallel Memory Plots: ${max_parallel_memory_plots}"
# Get NVME Size
nvme_b=$(lsblk -b -no SIZE /dev/nvme0n1p1)
nvme_kb=$((${nvme_b}/1024))
nvme_mb=$((${nvme_kb}/1024))
nvme_gb=$((${nvme_mb}/1024))
echo "Total NVME Space in GB: ${nvme_gb}"
max_parallel_nvme_plots=$((${nvme_gb}/380))
echo "Max Possible parallel NVME Plots: ${max_parallel_nvme_plots}"
# Check NVME for Max Plot Restriction
if [[ ( "${max_parallel_nvme_plots}" -lt "${max_parallel_memory_plots}" && "${max_parallel_nvme_plots}" -lt ${max_parallel_cpu_plots} ) ]]; then
max_plots="${max_parallel_nvme_plots}"
fi
# Check Memory for Max Plot Restriction
if [[ ( "${max_parallel_memory_plots}" -lt "${max_parallel_nvme_plots}" && "${max_parallel_memory_plots}" -lt ${max_parallel_cpu_plots} ) ]]; then
max_plots="${max_parallel_memory_plots}"
fi
if [[ ( "${max_parallel_cpu_plots}" -lt "${max_parallel_memory_plots}" && "${max_parallel_cpu_plots}" -lt ${max_parallel_nvme_plots} ) ]]; then
max_plots="${max_parallel_cpu_plots}"
fi
echo
echo "Max Parallel Plots on System: ${max_plots}"
echo
echo "Setting Up Defauls in Swar Config File (You still need to update it)"
sed -i '/^chia_location:/c\chia_location: /usr/share/chia-blockchain/venv/bin/chia' /usr/share/Swar-Chia-Plot-Manager/config.yaml
sed -i '/^ folder_path:/c\ folder_path: /var/log/swar' /usr/share/Swar-Chia-Plot-Manager/config.yaml
sed -i "/^ max_concurrent:/c\ max_concurrent: ${max_plots}" /usr/share/Swar-Chia-Plot-Manager/config.yaml
echo
echo "The Chia Plotters Need a Farm/Ploter Key in the config File"
echo "The Chia Blockchain needs Access to the Main Wallet's CA/SSL/TLS directory"
echo
echo "Chia Config File: /home/plotter/.chia/mainnet/config/config.yaml (Only Appears After 'chia init' Command is Run)"
echo "Swar Config File: /usr/share/Swar-Chia-Plot-Manager/config.yaml"
echo "Chia Bin File: /usr/share/chia-blockchain/venv/bin/chia"
echo "Chia Bin Directory: /usr/share/chia-blockchain/venv/bin"
echo
echo
echo "Follow Guide Here Before Running SWAR: https://github.com/Chia-Network/chia-blockchain/wiki/Farming-on-many-machines"
echo
echo "Make sure all Config files and CA files are readable by the \`plotter\` user"
echo "Command to Start The Harvestor: /usr/share/chia-blockchain/venv/bin/chia start harvester -r"
echo
echo "Update Chia Logging Directory in \`/home/plotter/.chia/mainnet/config/config.yaml\` with this location \`/var/log/chia/chia.log\`"