flexfarmer.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/bin/bash
  2. set -e
  3. version=2.1
  4. function print_centered {
  5. [[ $# == 0 ]] && return 1
  6. declare -i TERM_COLS="$(tput cols)"
  7. declare -i str_len="${#1}"
  8. [[ $str_len -ge $TERM_COLS ]] && {
  9. echo "$1";
  10. return 0;
  11. }
  12. declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
  13. [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
  14. filler=""
  15. for (( i = 0; i < filler_len; i++ )); do
  16. filler="${filler}${ch}"
  17. done
  18. printf "%s%s%s" "$filler" "$1" "$filler"
  19. [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
  20. printf "\n"
  21. return 0
  22. }
  23. if [ ! -d /home/wareck/chia ]
  24. then
  25. echo "Flexfarmer v$version installer"
  26. echo "Install chia first..."
  27. exit
  28. fi
  29. print_centered "$(tput setaf 10)"
  30. print_centered " _____ _ ___ "
  31. print_centered "| __| |___ _ _| _|___ ___ _____ ___ ___ "
  32. print_centered "| __| | -_|_'_| _| .'| _| | -_| _|"
  33. print_centered "|__| |_|___|_,_|_| |__,|_| |_|_|_|___|_| "
  34. print_centered " "
  35. echo -n "$(tput sgr0)"
  36. print_centered "Flexpool mining software"
  37. function build_service {
  38. cat > $HOME/flexfarmer.service << EOF
  39. # The flexfarmer service (part of systemd)
  40. # file: /etc/systemd/system/flexfarmer.service
  41. [Unit]
  42. Description = FlexFarmer Service
  43. After=network.target
  44. [Service]
  45. Type=simple
  46. User = $USER
  47. WorkingDirectory= $HOME/flexfarmer
  48. ExecStart = $HOME/flexfarmer/flexfarmer -c $HOME/flexfarmer/config.yml
  49. Restart = on-failure
  50. RestartSec=30
  51. LimitNOFILE=99999
  52. StandardOutput=syslog
  53. StandardError=syslog
  54. SyslogIdentifier=flexfarmer
  55. [Install]
  56. WantedBy = multi-user.target
  57. EOF
  58. sudo mv $HOME/flexfarmer.service /etc/systemd/system/flexfarmer.service >/dev/null
  59. sudo chmod 644 /etc/systemd/system/flexfarmer.service
  60. cat <<'EOF'>> flexfarmer.conf
  61. if $programname == 'flexfarmer' then /var/log/flexfarmer.log
  62. & stop
  63. EOF
  64. sudo cp flexfarmer.conf /etc/rsyslog.d/flexfarmer.conf
  65. sudo rm flexfarmer.conf
  66. if [ ! -f /var/log/flexfarmer.log ]
  67. then
  68. sudo touch /var/log/flexfarmer.log
  69. sudo chown syslog:adm /var/log/flexfarmer.log
  70. fi
  71. cat <<'EOF'>> logrot
  72. /var/log/flexfarmer.log {
  73. daily
  74. rotate 7
  75. copytruncate
  76. notifempty
  77. missingok
  78. su root syslog
  79. }
  80. EOF
  81. sudo cp logrot /etc/logrotate.d/flexfarmer
  82. sudo rm logrot
  83. print_centered "Install service : [ OK ]"
  84. }
  85. function install_ {
  86. cd /home/wareck/
  87. wget -c -q http://folivier.homelinux.org/cube/pack/flexfarmer.tar.xz
  88. tar xfJ flexfarmer.tar.xz
  89. rm /home/wareck/flexfarmer.tar.xz
  90. sudo cp /home/wareck/flexfarmer/flexfarmer /usr/local/bin/
  91. print_centered "Install software : [ OK ]"
  92. }
  93. function nft_builder {
  94. if [ -f /home/wareck/chia/chia-plotter/build/flexpool.sh ];then rm /home/wareck/chia/chia-plotter/build/flexpool.sh;fi
  95. if [ ! -d /home/wareck/chia/chia-plotter/build/ ]; then mkdir -p /home/wareck/chia/chia-plotter/build/ ;fi
  96. cat <<'EOF'>> /home/wareck/chia/chia-plotter/build/flexpool.sh
  97. #!/bin/bash
  98. ./chia_plot -n 1 -r 6 -u 128 -t /media/nvme0/plotting/ -2 /media/nvme1/plotting/ -d /Chia/Chia2/Plots-nft/ -c xch10yjksfwm8s66z32qy35x950608hk8l67vmsur4rwpaanpkd6ks3qhfw5nk -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373
  99. EOF
  100. chmod +x /home/wareck/chia/chia-plotter/build/flexpool.sh
  101. print_centered "Install nft script : [ OK ]"
  102. }
  103. echo
  104. install_
  105. build_service
  106. nft_builder
  107. sudo systemctl restart rsyslog >/dev/null 2>&1
  108. sudo systemctl daemon-reload >/dev/null 2>&1
  109. sudo systemctl enable flexfarmer >/dev/null 2>&1
  110. sudo systemctl start flexfarmer >/dev/null 2>&1
  111. #sudo systemctl status flexfarmer
  112. echo