# 2084onlycopystation (#2664)

This commit is contained in:
/rootzoll 2021-10-25 11:31:12 +02:00 committed by rootzoll
parent db74a04fa6
commit 02544f6b45
2 changed files with 90 additions and 115 deletions

View file

@ -13,26 +13,9 @@ fi
# where to find the BITCOIN data directory (no trailing /) # where to find the BITCOIN data directory (no trailing /)
pathBitcoinBlockchain="/mnt/hdd/bitcoin" pathBitcoinBlockchain="/mnt/hdd/bitcoin"
# where to find the LITECOIN data directory (no trailing /)
pathLitecoinBlockchain="/mnt/hdd/litecoin"
# where to find the RaspiBlitz HDD template directory (no trailing /) # where to find the RaspiBlitz HDD template directory (no trailing /)
pathTemplateHDD="/mnt/hdd/app-storage/templateHDD" pathTemplateHDD="/mnt/hdd/app-storage/templateHDD"
# 0 = ask before formatting/init new HDD
# 1 = auto-formatting every new HDD that needs init
nointeraction=1
# override values if XXcopyStation.conf files exists
# use when you run this outside RaspiBlitz
# - clean Ubuntu install
# - install bitcoind as systemd service
# - disable automount: https://askubuntu.com/questions/89244/how-to-disable-automount-in-nautiluss-preferences#102601
# - clone the github to get script (or download)
# - set your pathes bitcoin/template in conf file
source ./XXcopyStation.conf 2>/dev/null
# -- start script with parameter "-foreground"
####### SCRIPT ############# ####### SCRIPT #############
# check sudo # check sudo
@ -62,7 +45,7 @@ if [ -d "$pathBitcoinBlockchain" ]; then
echo "# OK found $pathBitcoinBlockchain" echo "# OK found $pathBitcoinBlockchain"
else else
echo "# FAIL path of 'pathBitcoinBlockchain' does not exists: ${pathBitcoinBlockchain}" echo "# FAIL path of 'pathBitcoinBlockchain' does not exists: ${pathBitcoinBlockchain}"
echo "error='pathBitcoinBlockchain nit found'" echo "error='pathBitcoinBlockchain not found'"
exit 1 exit 1
fi fi
@ -88,6 +71,10 @@ echo "# ******************************"
echo "# RASPIBLITZ COPYSTATION SCRIPT" echo "# RASPIBLITZ COPYSTATION SCRIPT"
echo "# ******************************" echo "# ******************************"
echo echo
echo "Make sure that no target HDD/SSDs are not connected yet .."
echo
sudo sed -i "s/^state=.*/state=copystation/g" /home/admin/raspiblitz.info 2>/dev/null
sleep 10
echo "*** CHECKING CONFIG" echo "*** CHECKING CONFIG"
@ -104,29 +91,10 @@ fi
systemctl stop lnd 2>/dev/null systemctl stop lnd 2>/dev/null
systemctl stop background 2>/dev/null systemctl stop background 2>/dev/null
#if [ "${nointeraction}" == "1" ]; then
# echo "setting RaspiBlitz LCD info"
# sudo sed -i "s/^state=.*/state=copystation/g" /home/admin/raspiblitz.info 2>/dev/null
# sudo sed -i "s/^message=.*/message='Disconnect target HDDs!'/g" /home/admin/raspiblitz.info 2>/dev/null
# echo "Disconnect target HDDs! .. 30sec until continue."
# sleep 30
#else
# echo
# echo "*** INIT HDD SCAN"
# echo "Please make sure that no HDDs that you want to sync later to are not connected now."
# echo "PRESS ENTER when ready."
# read key
#fi
# finding system drives (the drives that should not be synced to) # finding system drives (the drives that should not be synced to)
echo "# OK - the following drives detected as the system drive: $datadisk" echo "# OK - the following drives detected as the system drive: $datadisk"
echo echo
if [ "${nointeraction}" == "1" ]; then
sudo sed -i "s/^message=.*/message='Connect target HDDs ..'/g" /home/admin/raspiblitz.info 2>/dev/null
sleep 5
fi
# BASIC IDEA: # BASIC IDEA:
# 1. get fresh data from bitcoind --> template data # 1. get fresh data from bitcoind --> template data
# 2. detect HDDs # 2. detect HDDs
@ -136,12 +104,17 @@ fi
echo echo
echo "*** RUNNING ***" echo "*** RUNNING ***"
lastBlockchainUpdateTimestamp=1 lastBlockchainUpdateTimestamp=1
firstLoop=1
while : while :
do do
# reset external data stores (needed because local vars dont work in deeper while loops)
echo "" > /var/cache/raspiblitz/copystationHddsInfoString.tmp
rm /var/cache/raspiblitz/copystationFoundTargets.flag
################################################ ################################################
# 1. get fresh data from bitcoind for template data # 1. get fresh data from bitcoind for template data (skip on first loop)
# only execute every 30min # only execute every 30min
nowTimestamp=$(date +%s) nowTimestamp=$(date +%s)
@ -158,13 +131,12 @@ do
# stop blockchains # stop blockchains
echo "# Stopping Blockchain ..." echo "# Stopping Blockchain ..."
systemctl stop bitcoind 2>/dev/null systemctl stop bitcoind 2>/dev/null
systemctl stop litecoind 2>/dev/null
sleep 10 sleep 10
# sync bitcoin # sync bitcoin
echo "# Syncing Bitcoin to template folder ..." echo "# Syncing Bitcoin to template folder ..."
sudo sed -i "s/^message=.*/message='Updating Template: Bitcoin'/g" /home/admin/raspiblitz.info 2>/dev/null sed -i "s/^message=.*/message='Updating Template: Bitcoin'/g" /home/admin/raspiblitz.info
# make sure the bitcoin directory in template folder exists # make sure the bitcoin directory in template folder exists
if [ ! -d "$pathTemplateHDD/bitcoin" ]; then if [ ! -d "$pathTemplateHDD/bitcoin" ]; then
@ -176,27 +148,9 @@ do
# do the sync to the template folder for BITCOIN # do the sync to the template folder for BITCOIN
rsync -a --info=progress2 --delete ${pathBitcoinBlockchain}/chainstate ${pathBitcoinBlockchain}/blocks ${pathTemplateHDD}/bitcoin rsync -a --info=progress2 --delete ${pathBitcoinBlockchain}/chainstate ${pathBitcoinBlockchain}/blocks ${pathTemplateHDD}/bitcoin
litecoindirsize=$(sudo du -s -b /mnt/hdd/litecoin | awk '$1=$1' | cut -d " " -f1)
if [ -d "${pathLitecoinBlockchain}" ] && [ ${litecoindirsize} -gt 1000000000 ]; then
# sync litecoin
echo "# Syncing Litecoin ..."
echo "# creating the litecoin subfolder in the template folder"
mkdir ${pathTemplateHDD}/litecoin 2>/dev/null
chmod 777 ${pathTemplateHDD}/litecoin 2>/dev/null
sudo sed -i "s/^message=.*/message='Updating Template: Litecoin'/g" /home/admin/raspiblitz.info 2>/dev/null
# do the sync to the template folder for LITECOIN
rsync -a --info=progress2 --delete ${pathLitecoinBlockchain}/chainstate ${pathLitecoinBlockchain}/blocks ${pathTemplateHDD}/litecoin
fi
# restart bitcoind (to let further setup while syncing HDDs) # restart bitcoind (to let further setup while syncing HDDs)
echo "# Restarting Blockchain ..." echo "# Restarting Blockchain ..."
systemctl start bitcoind 2>/dev/null systemctl start bitcoind 2>/dev/null
systemctl start litecoind 2>/dev/null
# update timer # update timer
lastBlockchainUpdateTimestamp=$(date +%s) lastBlockchainUpdateTimestamp=$(date +%s)
@ -209,14 +163,14 @@ do
echo "**************************************" echo "**************************************"
echo "SYNCING TEMPLATE -> CONNECTED HDD/SSDs" echo "SYNCING TEMPLATE -> CONNECTED HDD/SSDs"
echo "**************************************" echo "**************************************"
echo "NOTE: Only use to prepare fresh HDDs" sleep 2
sleep 4
echo "" > ./.syncinfo.tmp
lsblk -o NAME | grep "^[s|v]d" | while read -r detectedDrive ; do lsblk -o NAME | grep "^[s|v]d" | while read -r detectedDrive ; do
isSystemDrive=$(echo "${datadisk}" | grep -c "${detectedDrive}") isSystemDrive=$(echo "${datadisk}" | grep -c "${detectedDrive}")
if [ ${isSystemDrive} -eq 0 ]; then if [ ${isSystemDrive} -eq 0 ]; then
# remember that disks were found
touch /var/cache/raspiblitz/copystationFoundTargets.flag
# check if drives 1st partition is named BLOCKCHAIN & in EXT4 format # check if drives 1st partition is named BLOCKCHAIN & in EXT4 format
isNamedBlockchain=$(lsblk -o NAME,FSTYPE,LABEL | grep "${detectedDrive}" | grep -c "BLOCKCHAIN") isNamedBlockchain=$(lsblk -o NAME,FSTYPE,LABEL | grep "${detectedDrive}" | grep -c "BLOCKCHAIN")
isFormatExt4=$(lsblk -o NAME,FSTYPE,LABEL | grep "${detectedDrive}" | grep -c "ext4") isFormatExt4=$(lsblk -o NAME,FSTYPE,LABEL | grep "${detectedDrive}" | grep -c "ext4")
@ -224,96 +178,120 @@ do
# init a fresh device # init a fresh device
if [ ${isNamedBlockchain} -eq 0 ] || [ ${isFormatExt4} -eq 0 ]; then if [ ${isNamedBlockchain} -eq 0 ] || [ ${isFormatExt4} -eq 0 ]; then
echo "*** NEW EMPTY HDD FOUND ***" echo
echo "Device: ${detectedDrive}" echo "**************************************************************"
echo "*** NEW EMPTY HDD FOUND ---> ${detectedDrive}"
echo "isNamedBlockchain: ${isNamedBlockchain}" echo "isNamedBlockchain: ${isNamedBlockchain}"
echo "isFormatExt4:" ${isFormatExt4} echo "isFormatExt4:" ${isFormatExt4}
# check if size is OK # check if size is OK
size=$(lsblk -o NAME,SIZE -b | grep "^${detectedDrive}" | awk '$1=$1' | cut -d " " -f 2) size=$(lsblk -o NAME,SIZE -b | grep "^${detectedDrive}" | awk '$1=$1' | cut -d " " -f 2)
echo "size: ${size}" echo "size: ${size}"
if [ ${size} -lt 250000000000 ]; then if [ ${size} -lt 900000000000 ]; then
whiptail --title "FAIL" --msgbox " echo "!! THE HDD/SSD IS TOO SMALL <900GB - use at least 1TB"
THE DEVICE IS TOO SMALL <250GB sed -i "s/^message=.*/message='HDD smaller than 1TB: ${detectedDrive}'/g" /home/admin/raspiblitz.info
Please remove device and PRESS ENTER echo
" 9 46 sleep 10
else else
# if config value "nointeraction=1" default to format choice=0
if [ "${nointeraction}" != "1" ]; then sed -i "s/^message=.*/message='Formatting new HDD: ${detectedDrive}'/g" /home/admin/raspiblitz.info
whiptail --title "Format HDD" --yes-button "Format" --no-button "Cancel" --yesno "
Found new HDD. Do you want to FORMAT now?
Label of device with: ${detectedDrive}
" 10 54
choice=$?
else
choice=0
sudo sed -i "s/^message=.*/message='Formatting new HDD: ${formatPartition}'/g" /home/admin/raspiblitz.info 2>/dev/null
fi
# on cancel
if [ "${choice}" != "0" ]; then
whiptail --title "Format HDD" --msgbox "
OK NO FORMAT - Please remove device now.
" 8 46
exit 1
fi
# format the HDD # format the HDD
echo "Starting Formatting of device ${detectedDrive} ..." echo "Starting Formatting of device ${detectedDrive} ..."
sudo /home/admin/config.scripts/blitz.datadrive.sh format ext4 ${detectedDrive} /home/admin/config.scripts/blitz.datadrive.sh format ext4 ${detectedDrive}
sleep 4
fi fi
fi # end init new HDD else
echo
echo "*** ALREADY ACTIVE HDD FOUND ---> ${detectedDrive}"
sleep 1
fi
################################################ ################################################
# 3. sync HDD with template data # 3. sync HDD with template data (skip on first loop)
partition=$(lsblk -o NAME,FSTYPE,LABEL | grep "${detectedDrive}" | grep "BLOCKCHAIN" | cut -d ' ' -f 1 | tr -cd "[:alnum:]") partition=$(lsblk -o NAME,FSTYPE,LABEL | grep "${detectedDrive}" | grep "BLOCKCHAIN" | cut -d ' ' -f 1 | tr -cd "[:alnum:]")
if [ ${#partition} -gt 0 ]; then if [ "${firstLoop}" != "1" ] && [ ${#partition} -gt 0 ]; then
# temp mount device # temp mount device
echo "mounting: ${partition}" echo "mounting: ${partition}"
mkdir /mnt/hdd2 2>/dev/null mkdir /mnt/hdd2 2>/dev/null
sudo mount -t ext4 /dev/${partition} /mnt/hdd2 mount -t ext4 /dev/${partition} /mnt/hdd2
# rsync device # rsync device
mountOK=$(lsblk -o NAME,MOUNTPOINT | grep "${detectedDrive}" | grep -c "/mnt/hdd2") mountOK=$(lsblk -o NAME,MOUNTPOINT | grep "${detectedDrive}" | grep -c "/mnt/hdd2")
if [ ${mountOK} -eq 1 ]; then if [ ${mountOK} -eq 1 ]; then
sudo sed -i "s/^message=.*/message='Syncing Template -> ${partition}'/g" /home/admin/raspiblitz.info 2>/dev/null hddsInfoString=$(cat /var/cache/raspiblitz/copystationHddsInfoString.tmp | tr '\n' ' ')
sed -i "s/^message=.*/message='${hddsInfoString} ${partition}>SYNC'/g" /home/admin/raspiblitz.info
rsync -a --info=progress2 --delete ${pathTemplateHDD}/* /mnt/hdd2 rsync -a --info=progress2 --delete ${pathTemplateHDD}/* /mnt/hdd2
sudo chmod -R 777 /mnt/hdd2 chmod -R 777 /mnt/hdd2
rm -r /mnt/hdd2/lost+found 2>/dev/null rm -r /mnt/hdd2/lost+found 2>/dev/null
echo "${partition} " >> ./.syncinfo.tmp echo "${partition}>OK" >> /var/cache/raspiblitz/copystationHddsInfoString.tmp
else else
echo "# FAIL: was not able to mount --> ${partition}" echo "# FAIL: was not able to mount --> ${partition}"
fi fi
# unmount device # unmount device
sudo umount -l /mnt/hdd2 umount -l /mnt/hdd2
fi fi
fi fi
done done
# check for flag
foundTargets=$(ls /var/cache/raspiblitz/copystationFoundTargets.flag 2>/dev/null | grep -c "copystationFoundTargets.flag")
hddsInfoString=$(cat /var/cache/raspiblitz/copystationHddsInfoString.tmp | tr '\n' ' ')
clear clear
echo "**** SYNC LOOP DONE ****" if [ "${foundTargets}" == "1" ] && [ "${firstLoop}" == "1" ]; then
synced=$(cat ./.syncinfo.tmp | tr '\r\n' ' ')
echo "HDDs ready synced: ${synced}"
echo "*************************"
echo "Its safe to disconnect/remove HDDs now."
echo "Or connect a new HDD/SSD for syncing."
echo "To stop copystation script: CTRL+c"
echo ""
sudo sed -i "s/^message=.*/message='Ready HDDs: ${synced}'/g" /home/admin/raspiblitz.info 2>/dev/null # after script found discs and did formatting ... go into full loop
echo "OK first loop done ..."
firstLoop=0
sleep 1
sleep 25 elif [ "${foundTargets}" == "0" ]; then
echo "**** NO TARGET HDD/SSDs CONNECTED ****"
echo
echo "Best way to start a new batch:"
echo "- Disconnect powered USB-Hub (best unplug USB cable at USB-Hub)"
echo "- Connect all HDD/SSDs to the disconnected USB-Hub"
echo "- Connect powered USB-Hub to Blitz (plug USB cable in)"
echo "- During formatting remember names of physical HDD/SSDs"
echo "- As soon as you see an OK for that HDD/SSD name you can remove it"
echo
echo "Next round starts in 30 seconds ..."
echo "To stop copystation script: CTRL+c and then 'restart'"
echo "You can close SSH terminal and script will run in background can can be re-entered."
sed -i "s/^message=.*/message='No target HDDs connected - connect USB Hub'/g" /home/admin/raspiblitz.info
firstLoop=1
sleep 30
else
echo "**** SYNC LOOP DONE ****"
echo "HDDs ready synced:"
cat /var/cache/raspiblitz/copystationHddsInfoString.tmp
echo
echo "*************************"
echo
echo "Next round starts in 25 seconds ..."
echo "To stop copystation script: CTRL+c and then 'restart'"
echo "You can close SSH terminal and script will run in background can can be re-entered."
sed -i "s/^message=.*/message='Ready HDDs: ${hddsInfoString}'/g" /home/admin/raspiblitz.info
sleep 25
fi
clear clear
echo "starting new sync loop" echo "starting new sync loop"
sleep 5 sleep 5
done done

View file

@ -140,11 +140,8 @@ Use your Password A
elif [ "${eventID}" == "copystation" ] && [ "${mode}" == "lcd" ]; then elif [ "${eventID}" == "copystation" ] && [ "${mode}" == "lcd" ]; then
dialog --backtitle "${backtitle}" --cr-wrap --infobox " dialog --backtitle "${backtitle}" --title " Copy-Station Mode " --cr-wrap --infobox "
Copy-Station Mode ${contentString}" 7 41
ssh admin@${localip}
Use your Password A
" 7 41
elif [ "${eventID}" == "walletlocked" ] && [ "${mode}" == "lcd" ]; then elif [ "${eventID}" == "walletlocked" ] && [ "${mode}" == "lcd" ]; then