chia.sh 13 KB

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