chia.sh 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. #!/bin/bash
  2. set -e
  3. Gui=No #can be Yes No or Only
  4. Version=4.2
  5. MadMax=Yes
  6. GigaHorse=Yes
  7. BladeBit=Yes
  8. ChiaPos=Yes
  9. Service=Yes
  10. function print_centered {
  11. [[ $# == 0 ]] && return 1
  12. declare -i TERM_COLS="$(tput cols)"
  13. declare -i str_len="${#1}"
  14. [[ $str_len -ge $TERM_COLS ]] && {
  15. echo "$1";
  16. return 0;
  17. }
  18. declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
  19. [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
  20. filler=""
  21. for (( i = 0; i < filler_len; i++ )); do
  22. filler="${filler}${ch}"
  23. done
  24. printf "%s%s%s" "$filler" "$1" "$filler"
  25. [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
  26. printf "\n"
  27. return 0
  28. }
  29. function jumpto
  30. {
  31. label=$1
  32. cmd=$(sed -n "/$label:/{:a;n;p;ba};" $0 | grep -v ':$')
  33. eval "$cmd"
  34. exit
  35. }
  36. function simplify_config {
  37. error_flag=0
  38. Gui=${Gui^^}
  39. Service=${Service^^}
  40. MadMax=${MadMax^^}
  41. GigaHorse=${GigaHorse^^}
  42. BladeBit=${BladeBit^^}
  43. ChiaPos=${ChiaPos^^}
  44. if [ $MadMax = "YES" ] || [ $MadMax = "NO" ];then error_flag=0;else error_flag=1;fi
  45. if [ $GigaHorse = "YES" ] || [ $GigaHorse = "NO" ];then error_flag=0;else error_flag=1;fi
  46. if [ $BladeBit = "YES" ] || [ $BladeBit = "NO" ];then error_flag=0;else error_flag=1;fi
  47. if [ $ChiaPos = "YES" ] || [ $ChiaPos = "NO" ];then error_flag=0;else error_flag=1;fi
  48. if [ $Service = "YES" ] || [ $Service = "NO" ];then error_flag=0;else error_flag=1;fi
  49. }
  50. function intro_ {
  51. print_centered "$(tput setaf 10)"
  52. print_centered " ______ __ __ "
  53. print_centered "| | |--.|__|.---.-."
  54. print_centered "| ---| || || _ |"
  55. print_centered "|______|__|__||__||___._|"
  56. echo -n "$(tput sgr0)"
  57. print_centered "Toolkit for Chia v$Version"
  58. if [ $error_flag = 1 ]
  59. then
  60. echo -n "$(tput setaf 1 ;tput blink;tput bold)"
  61. print_centered "Config Error !!!"
  62. echo -n "$(tput sgr0)"
  63. exit 0
  64. fi
  65. case $Gui in
  66. YES)
  67. echo -n "$(tput setaf 11)"
  68. print_centered "Blockchain wallet + Gui"
  69. print_centered "Chia Plotting Tools"
  70. echo -n "$(tput sgr0)"
  71. ;;
  72. NO)
  73. echo -n "$(tput setaf 11)"
  74. print_centered "Chia Plotting Tools"
  75. echo -n "$(tput sgr0)"
  76. ;;
  77. ONLY)
  78. echo -n "$(tput setaf 11)"
  79. print_centered "Blockchain wallet Only"
  80. echo -n "$(tput sgr0)"
  81. ;;
  82. *)
  83. echo -n "$(tput setaf 1 ;tput blink;tput bold)"
  84. print_centered "Config Error !!!"
  85. echo -n "$(tput sgr0)"
  86. exit 0
  87. ;;
  88. esac
  89. if [ $Gui = "NO" ] || [ $Gui = "YES" ]
  90. then
  91. case $Service in
  92. YES)
  93. echo -n "$(tput setaf 11)"
  94. print_centered "Mining service Enabled"
  95. echo -n "$(tput sgr0)"
  96. ;;
  97. esac
  98. fi
  99. sleep 3
  100. if ! [ -d /home/wareck/chia ];then mkdir /home/wareck/chia;fi
  101. }
  102. function update_ {
  103. echo -e "$(tput setaf 10)\nUpdate and install packages:$(tput sgr0)"
  104. sleep 1
  105. #if grep "Drivers=NVIDIA" /home/wareck/Build_Cube/build_cube.sh >/dev/null
  106. #then
  107. extend="libgomp1 ocl-icd-opencl-dev libgmp-dev libnuma-dev"
  108. #else
  109. #extend=""
  110. #fi
  111. sudo apt-get install python3-venv python3-distutils python3-dev libsodium-dev $extend -y
  112. echo -e "\e[97mDone.\e[0m"
  113. }
  114. function chia_plotter {
  115. echo -e "$(tput setaf 10)\nBuild Chia-Plotter (MadMax4ever) :$(tput sgr0)"
  116. sleep 1
  117. cd /home/wareck/chia/
  118. if [ ! -d chia-plotter ]
  119. then
  120. git clone https://github.com/madMAx43v3r/chia-plotter.git
  121. else
  122. cd /home/wareck/chia/chia-plotter
  123. git pull
  124. fi
  125. cd /home/wareck/chia/chia-plotter
  126. git submodule init
  127. git submodule update
  128. ./make_devel.sh
  129. cd build
  130. cat <<'EOF'>> go.sh
  131. #!/bin/bash
  132. ./chia_plot -n 1 -r 4 -u 128 -t /nvme0/plotting/ -2 /nvme0/plotting/ -d /media/Partage/Plots/ \
  133. -p a99e72c49c5ed39bf793caab9e074a80dd61011a859e975842874aab47b783f9ce84282febe2ca275c0930149b67990a \
  134. -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373
  135. EOF
  136. chmod +x go.sh
  137. cat <<'EOF'>> nft.sh
  138. #!/bin/bash
  139. ./chia_plot -n 1 -r 4 -u 128 -t /nvme0/plotting/ -2 /nvme1/plotting/ -d /media/Partage/Plots-nft/ \
  140. -p a99e72c49c5ed39bf793caab9e074a80dd61011a859e975842874aab47b783f9ce84282febe2ca275c0930149b67990a \
  141. -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373
  142. EOF
  143. chmod +x nft.sh
  144. echo -e "\e[97mDone.\e[0m"
  145. }
  146. function bladebit {
  147. echo -e "$(tput setaf 10)\nBuild Bladebit v2 :$(tput sgr0)"
  148. sleep 1
  149. cd /home/wareck/chia
  150. if [ ! -d bladebit ]
  151. then
  152. git clone https://github.com/Chia-Network/bladebit.git
  153. fi
  154. cd /home/wareck/chia/bladebit/
  155. if [ ! -d build ];then mkdir build;fi
  156. cd build
  157. cmake ..
  158. make -j6
  159. cat <<'EOF'>> hpool.sh
  160. #!/bin/bash
  161. ./bladebit_cuda \
  162. -p a99e72c49c5ed39bf793caab9e074a80dd61011a859e975842874aab47b783f9ce84282febe2ca275c0930149b67990a \
  163. -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373 \
  164. diskplot -t1 /nvme0/plotting/ -t2 /nvme1/plotting/ /farm/farm0/Plots/
  165. EOF
  166. cat <<'EOF'>> flex.sh
  167. #!/bin/bash
  168. ./bladebit_cuda \
  169. -c xch10yjksfwm8s66z32qy35x950608hk8l67vmsur4rwpaanpkd6ks3qhfw5nk \
  170. -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373 \
  171. diskplot -t1 /nvme0/plotting/ -t2 /nvme1/plotting/ /farm/farm0/Plots/
  172. EOF
  173. chmod +x hpool.sh
  174. chmod +x flex.sh
  175. echo -e "\e[97mDone.\e[0m"
  176. }
  177. function gigahorse {
  178. echo -e "$(tput setaf 10)\nMadMax4ever GigaHorse:$(tput sgr0)"
  179. sleep 1
  180. if [ -d /home/wareck/chia/chia-gigahorse ]
  181. then
  182. cd /home/wareck/chia/chia-gigahorse
  183. git pull
  184. else
  185. cd /home/wareck/chia/
  186. git clone https://github.com/madMAx43v3r/chia-gigahorse.git
  187. fi
  188. echo "generate bash files..."
  189. sudo cp ~/chia/chia-gigahorse/plot-sink/linux/x86_64/* /usr/local/bin/
  190. sudo cp ~/chia/chia-gigahorse/cpu-plotter/linux/x86_64/* /usr/local/bin/
  191. cd ~
  192. if [ -f distrib_chia.sh ];then sudo rm distrib_chia.sh;fi
  193. if [ -f /usr/local/bin/distrib_chia.sh ];then sudo rm /usr/local/bin/distrib_chia.sh;fi
  194. cat <<'EOF'>> distrib_chia.sh
  195. #!/bin/bash
  196. echo "IP : $(hostname -I)"
  197. chia_plot_sink -p 1447 /farm/farm0/Plots-nft/ /farm/farm1/Plots-nft/ /farm/farm2/Plots-nft/ /farm/farm3/Plots-nft/ /farm/farm4/Plots-nft/ /Partage/Plots-nft/
  198. EOF
  199. chmod +x distrib_chia.sh
  200. sudo mv distrib_chia.sh /usr/local/bin/
  201. cat <<'EOF'>> ~/go.sh
  202. #!/bin/bash
  203. ./chia_plot -G -r 6 -z 1447 -C 8 -n -1 -t /nvme0/plotting/ -2 /nvme1/plotting/ -d @192.168.1.100 \
  204. -c xch10yjksfwm8s66z32qy35x950608hk8l67vmsur4rwpaanpkd6ks3qhfw5nk \
  205. -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373
  206. EOF
  207. chmod +x ~/go.sh
  208. cp ~/go.sh ~/chia/chia-gigahorse/cpu-plotter/linux/x86_64/
  209. rm ~/go.sh
  210. echo -e "\e[97mDone.\e[0m"
  211. }
  212. function chiapos {
  213. echo -e "$(tput setaf 10)\nBuild Chia-Pos:$(tput sgr0)"
  214. sleep 1
  215. cd /home/wareck/chia
  216. if [ ! -d /home/wareck/chia/chia-pos ]
  217. then
  218. git clone https://github.com/Chia-Network/chiapos.git chia-pos
  219. cd /home/wareck/chia/chia-pos
  220. else
  221. cd /home/wareck/chia/chia-pos
  222. git pull
  223. fi
  224. if [ ! -d build ]; then mkdir build;fi
  225. cd build
  226. cmake -DBUILD_PROOF_OF_SPACE_STATICALLY=ON ../
  227. cmake --build . -- -j 6
  228. echo -e "\e[97mDone.\e[0m"
  229. }
  230. function miner {
  231. echo -e "$(tput setaf 10)\nChia-Miner (hpool):$(tput sgr0)"
  232. sleep 1
  233. wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/chia-miner.tar.xz -O /home/wareck/Build_Cube/pack/chia-miner.tar.xz
  234. cp /home/wareck/Build_Cube/pack/chia-miner.tar.xz /home/wareck/miners
  235. cd /home/wareck/miners
  236. tar xvfJ chia-miner.tar.xz
  237. rm chia-miner.tar.xz
  238. echo -e "\e[97mDone.\e[0m"
  239. }
  240. function chia_blockchain {
  241. echo -e "$(tput setaf 10)\nBuild Chia-blockchain & Gui :$(tput sgr0)"
  242. sleep 1
  243. cd /home/wareck/chia
  244. if [ ! -d /home/wareck/chia/chia-blockchain ]
  245. then
  246. git clone https://github.com/Chia-Network/chia-blockchain.git -b latest --recurse-submodules
  247. cd chia-blockchain
  248. else
  249. cd chia-blockchain
  250. git pull
  251. fi
  252. sh install.sh
  253. source ./activate
  254. sh install-gui.sh
  255. echo -e "\e[97mDone.\e[0m"
  256. }
  257. function service_old {
  258. echo -e "$(tput setaf 10)\nInstall chia-miner service (hpool) :$(tput sgr0)"
  259. sleep 1
  260. echo "Generation du fichier /etc/init.d/chia-miner"
  261. cat <<'EOF'>> chia-miner.sh
  262. #!/bin/sh
  263. ### BEGIN INIT INFO
  264. # Provides: chiaminer
  265. # Required-Start: networking
  266. # Default-Start: 3 4 5
  267. # Default-Stop: 0 6
  268. ### END INIT INFO
  269. case "$1" in
  270. start)
  271. if pgrep -x "hpool-miner-chia" > /dev/null
  272. then
  273. sudo killall -9 hpool-miner-chia | true
  274. fi
  275. su wareck -c "screen -dmS chia-miner /home/wareck/miners/chia-miner/hpool-miner-chia -config /home/wareck/miners/chia-miner/config.yaml"
  276. ;;
  277. stop)
  278. if pgrep -x "hpool-miner-chia" > /dev/null
  279. then
  280. sudo killall -9 hpool-miner-chia | true
  281. fi
  282. ;;
  283. restart)
  284. $0 stop
  285. $0 start
  286. ;;
  287. *)
  288. echo "Usage: /etc/init.d/chia-miner {start|restart|stop}"
  289. exit 1
  290. ;;
  291. esac
  292. exit 0
  293. EOF
  294. chmod +x chia-miner.sh
  295. sudo cp chia-miner.sh /etc/init.d/chia-miner
  296. sudo update-rc.d chia-miner defaults
  297. sleep 1
  298. sudo /etc/init.d/chia-miner start
  299. sudo rm chia-miner.sh
  300. echo -e "\e[97mDone.\e[0m"
  301. }
  302. function service_ {
  303. echo -e "$(tput setaf 10)\nInstall chia-miner service (hpool) :$(tput sgr0)"
  304. sleep 1
  305. cat <<'EOF'>> chia-miner.service
  306. [Unit]
  307. Description=HPool miner
  308. After=network.target
  309. StartLimitIntervalSec=500
  310. StartLimitBurst=5
  311. [Service]
  312. #Restart=on-failure
  313. #RestartSec=5s
  314. WorkingDirectory=/home/wareck/miners/chia-miner/
  315. User=wareck
  316. Group=adm
  317. ExecStart=/usr/bin/screen -DmS hpool-miner /home/wareck/miners/chia-miner/hpool-miner-chia -config /home/wareck/miners/chia-miner/config.yaml
  318. ExecStop=/usr/bin/screen -S hpool-miner -X quit
  319. LimitNOFILE=999999
  320. [Install]
  321. WantedBy=multi-user.target
  322. EOF
  323. sudo mv chia-miner.service /etc/systemd/system/hpool-miner.service
  324. sudo systemctl daemon-reload
  325. sudo systemctl start hpool-miner.service
  326. sudo systemctl enable hpool-miner.service
  327. echo -e "\e[97mDone.\e[0m"
  328. }
  329. function cmake_ {
  330. if [ $BladeBit = "YES" ]
  331. then
  332. pids=""
  333. ./tools/_cmake.sh & pids="$pids $!"
  334. wait $pids
  335. fi
  336. }
  337. simplify_config
  338. intro_
  339. update_
  340. cmake_
  341. case $Gui in
  342. NO|YES)
  343. if [ $GigaHorse = "YES" ];then gigahorse;fi
  344. if [ $MadMax = "YES" ];then chia_plotter;fi
  345. if [ $BladeBit = "YES" ];then bladebit;fi
  346. if [ $ChiaPos = "YES" ];then chiapos;fi
  347. if [ $Service = "YES" ];then service_;fi
  348. miner
  349. ;;
  350. esac
  351. case $Gui in
  352. YES|ONLY)
  353. chia_blockchain
  354. ;;
  355. *)
  356. ;;
  357. esac
  358. echo -e "\n\e[97mEnd of process...\e[0m"