chia.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. #!/bin/bash
  2. set -e
  3. Gui=No #can be Yes No or Only
  4. Version=4.3
  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. ./chia_plot -n 1 -r 4 -u 128 -t /nvme0/plotting/ -2 /nvme0/plotting/ -d /media/Partage/Plots/ \
  136. -p a99e72c49c5ed39bf793caab9e074a80dd61011a859e975842874aab47b783f9ce84282febe2ca275c0930149b67990a \
  137. -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373
  138. EOF
  139. chmod +x go.sh
  140. cat <<'EOF'>> nft.sh
  141. #!/bin/bash
  142. ./chia_plot -n 1 -r 4 -u 128 -t /nvme0/plotting/ -2 /nvme1/plotting/ -d /media/Partage/Plots-nft/ \
  143. -p a99e72c49c5ed39bf793caab9e074a80dd61011a859e975842874aab47b783f9ce84282febe2ca275c0930149b67990a \
  144. -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373
  145. EOF
  146. chmod +x nft.sh
  147. echo -e "\e[97mDone.\e[0m"
  148. }
  149. function bladebit {
  150. echo -e "$(tput setaf 10)\nBuild Bladebit v2 :$(tput sgr0)"
  151. sleep 1
  152. cd /home/wareck/chia
  153. if [ ! -d bladebit ]
  154. then
  155. git clone https://github.com/Chia-Network/bladebit.git
  156. fi
  157. cd /home/wareck/chia/bladebit/
  158. if [ ! -d build ];then mkdir build;fi
  159. cd build
  160. cmake ..
  161. make -j6
  162. cat <<'EOF'>> hpool.sh
  163. #!/bin/bash
  164. ./bladebit_cuda \
  165. -p a99e72c49c5ed39bf793caab9e074a80dd61011a859e975842874aab47b783f9ce84282febe2ca275c0930149b67990a \
  166. -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373 \
  167. diskplot -t1 /nvme0/plotting/ -t2 /nvme1/plotting/ /farm/farm0/Plots/
  168. EOF
  169. cat <<'EOF'>> flex.sh
  170. #!/bin/bash
  171. ./bladebit_cuda \
  172. -c xch10yjksfwm8s66z32qy35x950608hk8l67vmsur4rwpaanpkd6ks3qhfw5nk \
  173. -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373 \
  174. diskplot -t1 /nvme0/plotting/ -t2 /nvme1/plotting/ /farm/farm0/Plots/
  175. EOF
  176. chmod +x hpool.sh
  177. chmod +x flex.sh
  178. echo -e "\e[97mDone.\e[0m"
  179. }
  180. function gigahorse {
  181. echo -e "$(tput setaf 10)\nMadMax4ever GigaHorse:$(tput sgr0)"
  182. sleep 1
  183. if [ -d /home/wareck/chia/chia-gigahorse ]
  184. then
  185. cd /home/wareck/chia/chia-gigahorse
  186. git pull
  187. else
  188. cd /home/wareck/chia/
  189. git clone https://github.com/madMAx43v3r/chia-gigahorse.git
  190. fi
  191. echo "generate bash files..."
  192. sudo cp ~/chia/chia-gigahorse/plot-sink/linux/x86_64/* /usr/local/bin/
  193. sudo cp ~/chia/chia-gigahorse/cpu-plotter/linux/x86_64/* /usr/local/bin/
  194. cd ~
  195. if [ -f distrib_chia.sh ];then sudo rm distrib_chia.sh;fi
  196. if [ -f /usr/local/bin/distrib_chia.sh ];then sudo rm /usr/local/bin/distrib_chia.sh;fi
  197. cat <<'EOF'>> distrib_chia.sh
  198. #!/bin/bash
  199. echo "IP : $(hostname -I)"
  200. 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/
  201. EOF
  202. chmod +x distrib_chia.sh
  203. sudo mv distrib_chia.sh /usr/local/bin/
  204. cat <<'EOF'>> ~/go.sh
  205. #!/bin/bash
  206. ./chia_plot -G -r 6 -z 1447 -C 8 -n -1 -t /nvme0/plotting/ -2 /nvme1/plotting/ -d @192.168.1.100 \
  207. -c xch10yjksfwm8s66z32qy35x950608hk8l67vmsur4rwpaanpkd6ks3qhfw5nk \
  208. -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373
  209. EOF
  210. chmod +x ~/go.sh
  211. cp ~/go.sh ~/chia/chia-gigahorse/cpu-plotter/linux/x86_64/
  212. rm ~/go.sh
  213. echo -e "\e[97mDone.\e[0m"
  214. }
  215. function chiapos {
  216. echo -e "$(tput setaf 10)\nBuild Chia-Pos:$(tput sgr0)"
  217. sleep 1
  218. cd /home/wareck/chia
  219. if [ ! -d /home/wareck/chia/chia-pos ]
  220. then
  221. git clone https://github.com/Chia-Network/chiapos.git chia-pos
  222. cd /home/wareck/chia/chia-pos
  223. else
  224. cd /home/wareck/chia/chia-pos
  225. git pull
  226. fi
  227. if [ ! -d build ]; then mkdir build;fi
  228. cd build
  229. cmake ..
  230. cmake --build . -- -j 6
  231. echo -e "\e[97mDone.\e[0m"
  232. }
  233. function miner_ {
  234. echo -e "$(tput setaf 10)\nChia-Miner (hpool):$(tput sgr0)"
  235. sleep 1
  236. 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
  237. cp /home/wareck/Build_Cube/pack/chia-miner.tar.xz /home/wareck/miners
  238. cd /home/wareck/miners
  239. tar xvfJ chia-miner.tar.xz
  240. rm chia-miner.tar.xz
  241. echo -e "\e[97mDone.\e[0m"
  242. }
  243. function chia_blockchain {
  244. echo -e "$(tput setaf 10)\nBuild Chia-blockchain & Gui :$(tput sgr0)"
  245. sleep 1
  246. cd /home/wareck/chia
  247. if [ ! -d /home/wareck/chia/chia-blockchain ]
  248. then
  249. git clone https://github.com/Chia-Network/chia-blockchain.git -b latest --recurse-submodules
  250. cd chia-blockchain
  251. else
  252. cd chia-blockchain
  253. git pull
  254. fi
  255. sh install.sh
  256. source ./activate
  257. sh install-gui.sh
  258. echo -e "\e[97mDone.\e[0m"
  259. }
  260. function service_old {
  261. echo -e "$(tput setaf 10)\nInstall chia-miner service (hpool) :$(tput sgr0)"
  262. sleep 1
  263. echo "Generation du fichier /etc/init.d/chia-miner"
  264. cat <<'EOF'>> chia-miner.sh
  265. #!/bin/sh
  266. ### BEGIN INIT INFO
  267. # Provides: chiaminer
  268. # Required-Start: networking
  269. # Default-Start: 3 4 5
  270. # Default-Stop: 0 6
  271. ### END INIT INFO
  272. case "$1" in
  273. start)
  274. if pgrep -x "hpool-miner-chia" > /dev/null
  275. then
  276. sudo killall -9 hpool-miner-chia | true
  277. fi
  278. su wareck -c "screen -dmS chia-miner /home/wareck/miners/chia-miner/hpool-miner-chia -config /home/wareck/miners/chia-miner/config.yaml"
  279. ;;
  280. stop)
  281. if pgrep -x "hpool-miner-chia" > /dev/null
  282. then
  283. sudo killall -9 hpool-miner-chia | true
  284. fi
  285. ;;
  286. restart)
  287. $0 stop
  288. $0 start
  289. ;;
  290. *)
  291. echo "Usage: /etc/init.d/chia-miner {start|restart|stop}"
  292. exit 1
  293. ;;
  294. esac
  295. exit 0
  296. EOF
  297. chmod +x chia-miner.sh
  298. sudo cp chia-miner.sh /etc/init.d/chia-miner
  299. sudo update-rc.d chia-miner defaults
  300. sleep 1
  301. sudo /etc/init.d/chia-miner start
  302. sudo rm chia-miner.sh
  303. echo -e "\e[97mDone.\e[0m"
  304. }
  305. function service_ {
  306. echo -e "$(tput setaf 10)\nInstall chia-miner service (hpool) :$(tput sgr0)"
  307. sleep 1
  308. cat <<'EOF'>> chia-miner.service
  309. [Unit]
  310. Description=HPool miner
  311. After=network.target
  312. StartLimitIntervalSec=500
  313. StartLimitBurst=5
  314. [Service]
  315. #Restart=on-failure
  316. #RestartSec=5s
  317. WorkingDirectory=/home/wareck/miners/chia-miner/
  318. User=wareck
  319. Group=adm
  320. ExecStart=/usr/bin/screen -DmS hpool-miner /home/wareck/miners/chia-miner/hpool-miner-chia -config /home/wareck/miners/chia-miner/config.yaml
  321. ExecStop=/usr/bin/screen -S hpool-miner -X quit
  322. LimitNOFILE=999999
  323. [Install]
  324. WantedBy=multi-user.target
  325. EOF
  326. sudo mv chia-miner.service /etc/systemd/system/hpool-miner.service
  327. sudo systemctl daemon-reload
  328. sudo systemctl start hpool-miner.service
  329. sudo systemctl enable hpool-miner.service
  330. echo -e "\e[97mDone.\e[0m"
  331. }
  332. function cmake_ {
  333. if [ $BladeBit = "YES" ]
  334. then
  335. pids=""
  336. /home/wareck/Build_Cube/options/tools/_cmake.sh & pids="$pids $!"
  337. wait $pids
  338. fi
  339. }
  340. simplify_config
  341. intro_
  342. update_
  343. cmake_
  344. case $Gui in
  345. NO|YES)
  346. if [ $GigaHorse = "YES" ];then gigahorse;fi
  347. if [ $MadMax = "YES" ];then chia_plotter;fi
  348. if [ $BladeBit = "YES" ];then bladebit;fi
  349. if [ $ChiaPos = "YES" ];then chiapos;fi
  350. if [ $Service = "YES" ];then service_;fi
  351. if [ $Miner = "YES" ];then miner_;fi
  352. ;;
  353. esac
  354. case $Gui in
  355. YES|ONLY)
  356. chia_blockchain
  357. ;;
  358. *)
  359. ;;
  360. esac
  361. echo -e "\n\e[97mEnd of process...\e[0m"