#!/bin/bash
set -e
Version=2.0
function print_centered {
     [[ $# == 0 ]] && return 1

     declare -i TERM_COLS="$(tput cols)"
     declare -i str_len="${#1}"
     [[ $str_len -ge $TERM_COLS ]] && {
          echo "$1";
          return 0;
     }

     declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
     [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
     filler=""
     for (( i = 0; i < filler_len; i++ )); do
          filler="${filler}${ch}"
     done

     printf "%s%s%s" "$filler" "$1" "$filler"
     [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
     printf "\n"

     return 0
}

print_centered "$(tput setaf 2)"
print_centered " ______ __     __        "
print_centered "|      |  |--.|__|.---.-."
print_centered "|   ---|     ||  ||  _  |"
print_centered "|______|__|__||__||___._|"
echo -n "$(tput setaf 7)"
print_centered "Toolkit for Chia v$Version"
print_centered "$(tput setaf 7)"
sleep 3
echo -e "$(tput setaf 2)\nUpdate and install packages:$(tput sgr0)"
sudo apt-get install python3-venv python3-distutils python3-dev libsodium-dev -y
echo -e "\e[97mDone.\e[0m"

echo -e "$(tput setaf 2)\nDownload pack:$(tput sgr0)"
./download_pack.sh


echo -e "$(tput setaf 2)\nBuild Chia-Miner:$(tput sgr0)"
cp ../pack/chia-miner.tar.xz /home/wareck/
cd /home/wareck
tar xvfJ chia-miner.tar.xz
rm chia-miner.tar.xz
sudo cp chia-miner/chia-miner /etc/init.d/
sudo update-rc.d chia-miner defaults
sudo rm /home/wareck/chia-miner/chia-miner
echo -e "\e[97mDone.\e[0m"

echo -e "$(tput setaf 2)\nBuild Chia-Plotter (MadMax) :$(tput sgr0)"
cd /home/wareck
git clone https://github.com/madMAx43v3r/chia-plotter.git
cd /home/wareck/chia-plotter
git submodule init
git submodule update
./make_devel.sh
cd build
cat <<'EOF'>> go.sh
#!/bin/bash
./chia_plot -n 1 -r 4 -u 128 -t /Raid/temp/ -2 /Partage/temp/ -d /media/Partage/Plots/ -p a99e72c49c5ed39bf793caab9e074a80dd61011a859e975842874aab47b783f9ce84282febe2ca275c0930149b67990a -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373
EOF
chmod +x go.sh

cat <<'EOF'>> nft.sh
#!/bin/bash
./chia_plot -n 1 -r 4 -u 128 -t /media/nvme/ -2 /media/ssd_ext/ -d /media/Partage/Plots-nft/ -c xch18c2jp56msc47yzww25wcnzz5fk9y268zl3zh357kftsp0n7l6m8scyqg4e -f 8ba5acd276b45fd0f749ce195dcddcf0e63c3bf2e751e9e273faa0125075c36a11f2ee231e7cf74abed2920be97fc373
EOF
chmod +x nft.sh
echo -e "\e[97mDone.\e[0m"

echo -e "$(tput setaf 2)\nBuild Chia-Pos:$(tput sgr0)"
cd /home/wareck/
git clone https://github.com/Chia-Network/chiapos.git chia-pos
cd /home/wareck/chia-pos
mkdir build
cd build
cmake ..
make -j4
echo -e "\e[97mDone.\e[0m"

#echo -e "$(tput setaf 2)\nBuild Chia-Gui :$(tput sgr0)"
#cd /home/wareck
#git clone https://github.com/Chia-Network/chia-blockchain.git -b latest --recurse-submodules
#cd chia-blockchain
#sh install.sh
#source ./activate
#sh install-gui.sh

echo -e "\n\e[97mEnd of process...\e[0m"