chia.sh 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. #!/bin/bash
  2. set -e
  3. Gui=No #can be Yes No or Only
  4. Service=Yes
  5. Version=4.1
  6. MadMax=Yes
  7. GigaHorse=Yes
  8. BladeBit=Yes
  9. ChiaPos=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. echo -e "\e[97mDone.\e[0m"
  160. }
  161. function gigahorse {
  162. echo -e "$(tput setaf 10)\nMadMax4ever GigaHorse:$(tput sgr0)"
  163. sleep 1
  164. if [ -d /home/wareck/chia/chia-gigahorse ]
  165. then
  166. cd /home/wareck/chia/chia-gigahorse
  167. git pull
  168. else
  169. cd /home/wareck/chia/
  170. git clone https://github.com/madMAx43v3r/chia-gigahorse.git
  171. fi
  172. echo "generate bash files..."
  173. sudo cp ~/chia/chia-gigahorse/plot-sink/linux/x86_64/* /usr/local/bin/
  174. sudo cp ~/chia/chia-gigahorse/cpu-plotter/linux/x86_64/* /usr/local/bin/
  175. cd ~
  176. if [ -f distrib_chia.sh ];then sudo rm distrib_chia.sh;fi
  177. if [ -f /usr/local/bin/distrib_chia.sh ];then sudo rm /usr/local/bin/distrib_chia.sh;fi
  178. cat <<'EOF'>> distrib_chia.sh
  179. #!/bin/bash
  180. echo "IP : $(hostname -I)"
  181. 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/
  182. EOF
  183. chmod +x distrib_chia.sh
  184. sudo mv distrib_chia.sh /usr/local/bin/
  185. cat <<'EOF'>> ~/go.sh
  186. #!/bin/bash
  187. ./chia_plot -G -r 6 -z 1447 -C 8 -n -1 -t /nvme0/plotting/ -2 /nvme1/plotting/ -d @192.168.1.100 \
  188. -c xch10yjksfwm8s66z32qy35x950608hk8l67vmsur4rwpaanpkd6ks3qhfw5nk \
  189. -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373
  190. EOF
  191. chmod +x ~/go.sh
  192. cp ~/go.sh ~/chia/chia-gigahorse/cpu-plotter/linux/x86_64/
  193. rm ~/go.sh
  194. echo -e "\e[97mDone.\e[0m"
  195. }
  196. function chiapos {
  197. echo -e "$(tput setaf 10)\nBuild Chia-Pos:$(tput sgr0)"
  198. sleep 1
  199. cd /home/wareck/chia
  200. if [ ! -d /home/wareck/chia/chia-pos ]
  201. then
  202. git clone https://github.com/Chia-Network/chiapos.git chia-pos
  203. cd /home/wareck/chia/chia-pos
  204. else
  205. cd /home/wareck/chia/chia-pos
  206. git pull
  207. fi
  208. if [ ! -d build ]; then mkdir build;fi
  209. cd build
  210. cmake -DBUILD_PROOF_OF_SPACE_STATICALLY=ON ../
  211. cmake --build . -- -j 6
  212. echo -e "\e[97mDone.\e[0m"
  213. }
  214. function miner {
  215. echo -e "$(tput setaf 10)\nChia-Miner (hpool):$(tput sgr0)"
  216. sleep 1
  217. 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
  218. cp /home/wareck/Build_Cube/pack/chia-miner.tar.xz /home/wareck/miners
  219. cd /home/wareck/miners
  220. tar xvfJ chia-miner.tar.xz
  221. rm chia-miner.tar.xz
  222. echo -e "\e[97mDone.\e[0m"
  223. }
  224. function chia_blockchain {
  225. echo -e "$(tput setaf 10)\nBuild Chia-blockchain & Gui :$(tput sgr0)"
  226. sleep 1
  227. cd /home/wareck/chia
  228. if [ ! -d /home/wareck/chia/chia-blockchain ]
  229. then
  230. git clone https://github.com/Chia-Network/chia-blockchain.git -b latest --recurse-submodules
  231. cd chia-blockchain
  232. else
  233. cd chia-blockchain
  234. git pull
  235. fi
  236. sh install.sh
  237. source ./activate
  238. sh install-gui.sh
  239. echo -e "\e[97mDone.\e[0m"
  240. }
  241. function service_ {
  242. echo -e "$(tput setaf 10)\nInstall chia-miner service (hpool) :$(tput sgr0)"
  243. sleep 1
  244. echo "Generation du fichier /etc/init.d/chia-miner"
  245. cat <<'EOF'>> chia-miner.sh
  246. #!/bin/sh
  247. ### BEGIN INIT INFO
  248. # Provides: chiaminer
  249. # Required-Start: networking
  250. # Default-Start: 3 4 5
  251. # Default-Stop: 0 6
  252. ### END INIT INFO
  253. case "$1" in
  254. start)
  255. if pgrep -x "hpool-miner-chia" > /dev/null
  256. then
  257. sudo killall -9 hpool-miner-chia | true
  258. fi
  259. su wareck -c "screen -dmS chia-miner /home/wareck/miners/chia-miner/hpool-miner-chia -config /home/wareck/miners/chia-miner/config.yaml"
  260. ;;
  261. stop)
  262. if pgrep -x "hpool-miner-chia" > /dev/null
  263. then
  264. sudo killall -9 hpool-miner-chia | true
  265. fi
  266. ;;
  267. restart)
  268. $0 stop
  269. $0 start
  270. ;;
  271. *)
  272. echo "Usage: /etc/init.d/chia-miner {start|restart|stop}"
  273. exit 1
  274. ;;
  275. esac
  276. exit 0
  277. EOF
  278. chmod +x chia-miner.sh
  279. sudo cp chia-miner.sh /etc/init.d/chia-miner
  280. sudo update-rc.d chia-miner defaults
  281. sudo /etc/init.d/chia-miner start
  282. sudo rm chia-miner.sh
  283. echo -e "\e[97mDone.\e[0m"
  284. }
  285. function cmake_ {
  286. if [ $BladeBit = "YES" ]
  287. then
  288. pids=""
  289. ./tools/_cmake.sh & pids="$pids $!"
  290. wait $pids
  291. fi
  292. }
  293. simplify_config
  294. intro_
  295. update_
  296. cmake_
  297. case $Gui in
  298. NO|YES)
  299. if [ $GigaHorse = "YES" ];then gigahorse;fi
  300. if [ $MadMax = "YES" ];then chia_plotter;fi
  301. if [ $BladeBit = "YES" ];then bladebit;fi
  302. if [ $ChiaPos = "YES" ];then chiapos;fi
  303. if [ $Service = "YES" ];then service_;fi
  304. miner
  305. ;;
  306. esac
  307. case $Gui in
  308. YES|ONLY)
  309. chia_blockchain
  310. ;;
  311. *)
  312. ;;
  313. esac
  314. echo -e "\n\e[97mEnd of process...\e[0m"