123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- #!/bin/bash
- set -e
- version=4.4
- date=03/05/2021
- pixz_i=""
- pigz_i=""
- swap_was="0"
- ftp_i=0
- pv_i=0
- cifs_i=0
- retry_flag=0
- daemon_on=0
- echo -e "\e[97mOkcash Blockchain Restore Backup(FTP) v$version ($date)\e[0m"
- echo -e "wareck : wareck@gmail.com"
- echo -e ""
- bt_version="`curl -s http://wareck.free.fr/crypto/okcash/bootstrap_backup/bootstrap_v.txt | awk 'NR==1 {print$3;exit}'`"
- bt_parts="`curl -s http://wareck.free.fr/crypto/okcash/bootstrap_backup/bootstrap_v.txt | awk 'NR==2 {print$2; exit}'`"
- echo -e "Boostrap.dat file : $bt_version => $bt_parts parts"
- function init {
- if ps -ef | grep -v grep | grep okcashd >/dev/null
- then
- daemon_on=1
- echo -e "\n\e[93mStopping Okcashd :\e[0m"
- okcashd stop 2>/dev/null || true && sudo /etc/init.d/cron stop 2>/dev/null || true
- sleep 1
- if ps -ef | grep -v grep | grep okcashd >/dev/null ; then killall -9 okcashd; fi
- sleep 1
- if [ -f /usr/local/bin/okcashd ];then sudo mv /usr/local/bin/okcashd /usr/local/bin/okcashd_old |true ;fi
- if ps -ef | grep -v grep | grep okcashd >/dev/null ; then killall -9 okcashd; fi
- echo "Done."
- fi
- if [ "`systemctl is-active watchdog.service`" = "active" ]
- then
- echo -e "\n\e[93mStopping watchdog :\e[0m"
- sudo systemctl stop watchdog >/dev/null
- echo "Done."
- fi
- if [ -d /home/$USER/scripts/ledstatus/ ];then sudo python /home/$USER/scripts/ledstatus/led_off.py; fi
- if [ -f /var/swap ]
- then
- echo -e "\n\e[93mStopping Swap :\e[0m"
- sudo dphys-swapfile swapoff /var/swap
- sudo rm /var/swap
- swap_was="1"
- echo "Done."
- fi
- }
- function check_software_ {
- echo -e "\n\e[95mChecking Softwares :\e[0m"
- echo -e -n "Check PIXZ installed : "
- if ! [ -x "$(command -v pixz)" ]; then pixz_i="pixz" && echo -e "[\e[91m NO \e[0m]"; else pixz_i="" && echo -e "[\e[92m YES \e[0m]"; fi
- echo -e -n "Check PIGZ installed : "
- if ! [ -x "$(command -v pigz)" ]; then pigz_i="pigz" && echo -e "[\e[91m NO \e[0m]"; else pigz_i="" && echo -e "[\e[92m YES \e[0m]"; fi
- echo -e -n "Check PV installed : "
- if ! [ -x "$(command -v pv)" ]; then pv_i="pv" && echo -e "[\e[91m NO \e[0m]"; else pv_i="" && echo -e "[\e[92m YES \e[0m]"; fi
- if ! [[ $pixz_i = "" || ! $pv_i = "" || ! $pigz_i = "" ]]
- then
- echo -e "\n\e[95mSoftwares update & install :\e[0m"
- sudo apt-get update
- sudo apt install $pixz_i $ftp_i $pv_i $lrzip_i $pigz_i $cifs_i -y
- check_software_
- fi
- echo -e "Done."
- }
- function freeze_on_ {
- NEW_FAN=5.0
- if [ -f /home/$USER/scripts/run-fan.py ]
- then
- echo -e "\n\e[95mEnable \e[38;5;196mF\e[38;5;202mr\e[38;5;208me\e[38;5;214me\e[38;5;220mz\e[38;5;226mi\e[38;5;227mn\e[38;5;229mg\e[0m \e[95m:\e[0m"
- sudo systemctl stop run-fan.service
- if ! [ -f /home/$USER/freeze.txt ]
- then
- if grep "# Author: Andreas Spiess" /home/$USER/scripts/run-fan.py >/dev/null
- then
- grep -i "desiredTemp = " /home/$USER/scripts/run-fan.py |awk 'NR==1 {print$3;exit}' >/home/$USER/freeze.txt
- else
- grep -i "self.startTemperature = " /home/$USER/scripts/run-fan.py |awk 'NR==1 {print$3;exit}' >/home/$USER/freeze.txt
- fi
- fi
- OLD_FAN=`cat /home/$USER/freeze.txt| awk '{print $1}'`
- echo "Fan PWM value : $OLD_FAN => $NEW_FAN"
- if grep "# Author: Andreas Spiess" ~/scripts/run-fan.py >/dev/null
- then
- sed -i -e "s/desiredTemp = "$OLD_FAN"/desiredTemp = "$NEW_FAN"/g" /home/$USER/scripts/run-fan.py
- else
- sed -i -e "s/self.startTemperature = "$OLD_FAN"/self.startTemperature = "$NEW_FAN"/g" /home/$USER/scripts/run-fan.py
- fi
- sudo systemctl restart run-fan.service
- echo -e "Done."
- sleep 1
- fi
- }
- function freeze_off_ {
- echo -e -n ""
- if [ -f /home/$USER/scripts/run-fan.py ]
- then
- echo -e "\n\e[95mDisable Freezing :\e[0m"
- OLD_FAN=`cat /home/$USER/freeze.txt| awk '{print $1}'`
- if grep "# Author: Andreas Spiess" ~/scripts/run-fan.py >/dev/null
- then
- echo "Fan PWM value : $NEW_FAN => $OLD_FAN"
- else
- echo "Fan value: $NEW_FAN =>$OLD_FAN"
- fi
- sudo systemctl stop run-fan.service
- if grep "# Author: Andreas Spiess" ~/scripts/run-fan.py >/dev/null
- then
- sed -i -e "s/desiredTemp = "$NEW_FAN"/desiredTemp = "$OLD_FAN"/g" /home/$USER/scripts/run-fan.py
- else
- sed -i -e "s/self.startTemperature = "$NEW_FAN"/self.startTemperature = "$OLD_FAN"/g" /home/$USER/scripts/run-fan.py
- fi
- sudo systemctl restart run-fan.service
- if [ -f /home/$USER/freeze.txt ];then rm /home/$USER/freeze.txt;fi
- echo -e "Done."
- fi
- }
- function end_restart {
- if [ -f /usr/local/bin/okcashd_old ]
- then
- sudo mv /usr/local/bin/okcashd_old /usr/local/bin/okcashd | true
- okcashd
- fi
- echo "okcash restart"
- }
- function download_ {
- badsum=0
- sudo dphys-swapfile swapoff &> /dev/null
- if [ -f /var/swap ];then sudo rm /var/swap;fi
- echo -e "\n\e[95mDownload Bootstrap Files $bt_version => $bt_parts :\e[0m"
- folder="bootstrap_backup"
- cd /home/$USER/
- for i in `seq -w 01 $bt_parts`;
- do
- wget -c http://wareck.free.fr/crypto/okcash/$folder/bootstrap.part$i
- done
- for i in `seq -w 01 $bt_parts`;
- do
- wget -c http://wareck.free.fr/crypto/okcash/$folder/bootstrap$i.md5
- done
- echo -e "\n\e[95mBootstrap checksum test:\e[0m"
- for i in `seq -w 01 $bt_parts`;
- do
- echo -e -n "Bootstrap.part$i md5sum Test: " && if md5sum --status -c bootstrap$i.md5; then echo -e "[\e[92m OK \e[0m]"; else echo -e "[\e[91m NO \e[0m]" && badsum=1 ;fi
- if [ $badsum = "1" ]
- then
- echo -e "\e[38;5;166mBootstrap.tar.xz error !\e[0m"
- echo -e "\e[38;5;166mMaybe file damaged or not fully download\e[0m"
- echo -e "\e[38;5;166mRestart build_node to try again !\e[0m"
- exit
- fi
- done
- echo -e "\n\e[95mJoin bootstrap.tar.xz:\e[0m"
- if [ -f bootstrap.tar.xz ] ; then rm bootstrap.tar.xz ;fi
- mv bootstrap.part01 bootstrap.tar.xz
- echo "bootstrap.part01"
- list=$(ls bootstrap.part*)
- for i in ${list[@]}
- do
- cat "$i" >> bootstrap.tar.xz
- echo "$i"
- rm "$i"
- done
- rm bootstrap*.md5
- echo -e "Done."
- if [ -f ~/.okcash/blk0001.dat ]
- then
- echo -e "\n\e[95mClean old data before extract:\e[0m"
- rm -r -f ~/.okcash/blk0001.dat
- rm -r -f ~/.okcash/database
- rm -r -f ~/.okcash/txleveldb
- rm -r -f ~/.okcash/peers.dat
- rm -r -f ~/.okcash/smsg*
- rm -r -f okcashd.pid
- echo "Done."
- fi
- echo -e "\n\e[95mExtract bootstrap.tar.xz:\e[0m"
- tar xvfJ bootstrap.tar.xz
- rm bootstrap.tar.xz
- echo -e "Done."
- sudo dphys-swapfile setup &> /dev/null
- sudo dphys-swapfile swapon &> /dev/null
- }
- if ps -ef | grep -v grep | grep okcashd >/dev/null
- then
- echo -e "\n\e[38;5;166mOKcash daemon is working => shutdown and restart during this process !...\e[0m"
- while true; do
- read -p "Do you want to start processing (y/n) ? " yn
- case $yn in
- [Yy]* ) init ; check_software_; freeze_on ; retry ; packit ; upload ; end_restart ; break;;
- [Nn]* ) exit;;
- * ) echo "Please answer yes or no.";;
- esac
- done
- else
- init
- check_software_
- freeze_on_
- download_
- end_restart
- fi
- if [ swap_was = 1 ]
- then
- echo -e "\n\e[95mRestart Swap:\e[0m"
- sudo dphys-swapfile setup
- sudo dphys-swapfile swapon
- echo "Done."
- fi
- if [ -f /home/$USER/bootstrap_uploadpass ]; then rm /home/$USER/bootstrap_uploadpass;fi
- if [ $daemon_on = 1 ]
- then
- echo -e "\n\e[38;5;166mOKcash daemon is restarting ...\e[0m"
- if [ -f /usr/local/bin/okcashd_old ]
- then
- sudo mv /usr/local/bin/okcashd_old /usr/local/bin/okcashd | true
- fi
- fi
- echo ""
|