chia.sh 12 KB

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