#!/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 split_size=850 echo -e "\e[97mOkcash Blockchain Uploader v$version ($date)\e[0m" echo -e "Update for Mega.io." echo -e "wareck : wareck@gmail.com" echo -e "" sleep 2 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 2 if ps -ef | grep -v grep | grep okcashd >/dev/null ; then killall -9 okcashd; fi sleep 2 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 LFTP installed : " if ! [ -x "$(command -v lftp)" ]; then ftp_i="lftp" && echo -e "[\e[91m NO \e[0m]"; else ftp_i="" && echo -e "[\e[92m YES \e[0m]"; fi echo -e -n "Check CIFS installed : " if ! [ -x "$(command -v cifscreds)" ]; then cifs_i="cifs-utils" && echo -e "[\e[91m NO \e[0m]"; else cifs_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 [[ ! $ftp_i = "" || ! $pixz_i = "" || ! $pv_i = "" || ! $pigz_i = "" || ! $cifs_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 packit { echo -e "\n\e[95mPacking & Compressing Files :\e[0m" cd /home/$USER SIZE1=`du -sk /home/$USER/.okcash/blk0001.dat | cut -f 1` SIZE2=`du -sk /home/$USER/.okcash/txleveldb/ | cut -f 1` SIZE=$(($SIZE2+$SIZE1+1)) echo -e "\e[97mTar & PiXz :\e[0m" tar cf - .okcash/txleveldb/* .okcash/blk0001.dat | pv -s ${SIZE}k | pixz > bootstrap.tar.xz sleep 1 echo "Done." echo -e "\n\e[95mSplitting Files (${split_size}M):\e[0m" split --verbose -d -b ${split_size}M bootstrap.tar.xz "bootstrap.part" rm bootstrap.tar.xz sleep 1 echo "Done." echo -e "\n\e[95mRename Files:\e[0m" if [ -f bootstrap.partaa ]; then mv bootstrap.partaa bootstrap.part01 && echo "bootstrap.partaa >> bootstrap.part01" ;fi if [ -f bootstrap.partab ]; then mv bootstrap.partab bootstrap.part02 && echo "bootstrap.partab >> bootstrap.part02" ;fi if [ -f bootstrap.partac ]; then mv bootstrap.partac bootstrap.part03 && echo "bootstrap.partac >> bootstrap.part03" ;fi if [ -f bootstrap.partad ]; then mv bootstrap.partad bootstrap.part04 && echo "bootstrap.partad >> bootstrap.part04" ;fi if [ -f bootstrap.partae ]; then mv bootstrap.partae bootstrap.part05 && echo "bootstrap.partae >> bootstrap.part05" ;fi if [ -f bootstrap.partaf ]; then mv bootstrap.partaf bootstrap.part06 && echo "bootstrap.partaf >> bootstrap.part06" ;fi if [ -f bootstrap.partag ]; then mv bootstrap.partag bootstrap.part07 && echo "bootstrap.partag >> bootstrap.part07" ;fi if [ -f bootstrap.partah ]; then mv bootstrap.partah bootstrap.part08 && echo "bootstrap.partah >> bootstrap.part08" ;fi if [ -f bootstrap.partai ]; then mv bootstrap.partai bootstrap.part09 && echo "bootstrap.partai >> bootstrap.part09" ;fi if [ -f bootstrap.partaj ]; then mv bootstrap.partai bootstrap.part10 && echo "bootstrap.partai >> bootstrap.part10" ;fi echo -e "\n\e[95mMake bootstrap_v.txt:\e[0m" Raw_date="`date +%d.%m.%Y`" YYYY=`ls -l bootstrap*.part* | wc -l` cat <<'EOF'>> bootstrap_v.txt Bootstrap : XXXX Parts: YYYY EOF sed -i -e "s/XXXX/$Raw_date/g" bootstrap_v.txt sed -i -e "s/YYYY/$YYYY/g" bootstrap_v.txt echo "Done." echo -e "\n\e[95mMd5sum Files:\e[0m" if [ -f bootstrap.part01 ]; then echo -e -n "md5sum Bootstrap.part01: " && md5sum bootstrap.part01 > bootstrap01.md5 && echo -e "\e[1mDone.\e[0m"; fi if [ -f bootstrap.part02 ]; then echo -e -n "md5sum Bootstrap.part02: " && md5sum bootstrap.part02 > bootstrap02.md5 && echo -e "\e[1mDone.\e[0m"; fi if [ -f bootstrap.part03 ]; then echo -e -n "md5sum Bootstrap.part03: " && md5sum bootstrap.part03 > bootstrap03.md5 && echo -e "\e[1mDone.\e[0m"; fi if [ -f bootstrap.part04 ]; then echo -e -n "md5sum Bootstrap.part04: " && md5sum bootstrap.part04 > bootstrap04.md5 && echo -e "\e[1mDone.\e[0m"; fi if [ -f bootstrap.part05 ]; then echo -e -n "md5sum Bootstrap.part05: " && md5sum bootstrap.part05 > bootstrap05.md5 && echo -e "\e[1mDone.\e[0m"; fi if [ -f bootstrap.part06 ]; then echo -e -n "md5sum Bootstrap.part06: " && md5sum bootstrap.part06 > bootstrap06.md5 && echo -e "\e[1mDone.\e[0m"; fi if [ -f bootstrap.part07 ]; then echo -e -n "md5sum Bootstrap.part07: " && md5sum bootstrap.part07 > bootstrap07.md5 && echo -e "\e[1mDone.\e[0m"; fi if [ -f bootstrap.part08 ]; then echo -e -n "md5sum Bootstrap.part08: " && md5sum bootstrap.part08 > bootstrap08.md5 && echo -e "\e[1mDone.\e[0m"; fi if [ -f bootstrap.part09 ]; then echo -e -n "md5sum Bootstrap.part09: " && md5sum bootstrap.part09 > bootstrap09.md5 && echo -e "\e[1mDone.\e[0m"; fi if [ -f bootstrap.part10 ]; then echo -e -n "md5sum Bootstrap.part10: " && md5sum bootstrap.part10 > bootstrap10.md5 && echo -e "\e[1mDone.\e[0m"; fi touch /home/$USER/bootstrap_uploadpass } function ftp_check { FTP_SUCCESS_MSG="226 Transfer complete" if fgrep "$FTP_SUCCESS_MSG" $Ftp_LOG ;then echo "ftp transfer : OK" echo "" rm $Ftp_LOG else echo "ftp transfer Error: $ftp_file" rm $Ftp_LOG echo "" ftp_loop fi } function ftp_loop { lftp -u wareck,zorn692611 ftpperso.free.fr </dev/null then sudo umount /tmp/bootstrap/ fi sudo mount -t cifs //mafreebox.freebox.fr/Disque\ dur/ /tmp/bootstrap/ -o user=freebox,password=password,uid=1000,gid=1000,rw,vers=1.0 if ! [ -d /tmp/bootstrap/bootstrap ]; then mkdir /tmp/bootstrap/bootstrap ;fi cp -v bootstrap.part* /tmp/bootstrap/bootstrap/ cp -v bootstrap_v.txt /tmp/bootstrap/bootstrap/ cp -v bootstrap*.md5 /tmp/bootstrap/bootstrap/ sleep 5 sudo umount /tmp/bootstrap freeze_off echo -e "\n\e[92mUpload Done ...\n\e[0m" } 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 } function retry { if [ -f /home/$USER/bootstrap_uploadpass ]; then retry_flag=1 ;fi if [ $retry_flag = "1" ] then echo -e "\n\e[95mRetry Upload to server :\e[0m" echo -e "Old files are still present." echo -e "If you want to force restart build/upload" echo -e "remove files by using this command:" echo -e "" echo -e "rm -r -f /home/$USER/bootstrap.tar.xz /home/$USER/bootstrap_v.txt /home/$USER/bootstrap*.md5 /home/$USER/bootstrap_uploadpass" sleep 5 fi } 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 retry if [ $retry_flag = "1" ] then upload end_restart else packit upload end_restart fi 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 ""