chia.sh 13 KB

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