chia.sh 11 KB

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