diff --git a/home.admin/XXcopyStation.sh b/home.admin/XXcopyStation.sh index aa8e7bb3f..51ec8c95e 100755 --- a/home.admin/XXcopyStation.sh +++ b/home.admin/XXcopyStation.sh @@ -13,26 +13,9 @@ fi # where to find the BITCOIN data directory (no trailing /) 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 /) 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 ############# # check sudo @@ -62,7 +45,7 @@ if [ -d "$pathBitcoinBlockchain" ]; then echo "# OK found $pathBitcoinBlockchain" else echo "# FAIL path of 'pathBitcoinBlockchain' does not exists: ${pathBitcoinBlockchain}" - echo "error='pathBitcoinBlockchain nit found'" + echo "error='pathBitcoinBlockchain not found'" exit 1 fi @@ -88,6 +71,10 @@ echo "# ******************************" echo "# RASPIBLITZ COPYSTATION SCRIPT" 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" @@ -104,29 +91,10 @@ fi systemctl stop lnd 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) echo "# OK - the following drives detected as the system drive: $datadisk" 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: # 1. get fresh data from bitcoind --> template data # 2. detect HDDs @@ -136,12 +104,17 @@ fi echo echo "*** RUNNING ***" lastBlockchainUpdateTimestamp=1 +firstLoop=1 while : 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 nowTimestamp=$(date +%s) @@ -158,13 +131,12 @@ do # stop blockchains echo "# Stopping Blockchain ..." systemctl stop bitcoind 2>/dev/null - systemctl stop litecoind 2>/dev/null sleep 10 # sync bitcoin 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 if [ ! -d "$pathTemplateHDD/bitcoin" ]; then @@ -176,27 +148,9 @@ do # do the sync to the template folder for 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) echo "# Restarting Blockchain ..." systemctl start bitcoind 2>/dev/null - systemctl start litecoind 2>/dev/null # update timer lastBlockchainUpdateTimestamp=$(date +%s) @@ -209,14 +163,14 @@ do echo "**************************************" echo "SYNCING TEMPLATE -> CONNECTED HDD/SSDs" echo "**************************************" - echo "NOTE: Only use to prepare fresh HDDs" - - sleep 4 - echo "" > ./.syncinfo.tmp + sleep 2 lsblk -o NAME | grep "^[s|v]d" | while read -r detectedDrive ; do isSystemDrive=$(echo "${datadisk}" | grep -c "${detectedDrive}") 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 isNamedBlockchain=$(lsblk -o NAME,FSTYPE,LABEL | grep "${detectedDrive}" | grep -c "BLOCKCHAIN") isFormatExt4=$(lsblk -o NAME,FSTYPE,LABEL | grep "${detectedDrive}" | grep -c "ext4") @@ -224,96 +178,120 @@ do # init a fresh device if [ ${isNamedBlockchain} -eq 0 ] || [ ${isFormatExt4} -eq 0 ]; then - echo "*** NEW EMPTY HDD FOUND ***" - echo "Device: ${detectedDrive}" + echo + echo "**************************************************************" + echo "*** NEW EMPTY HDD FOUND ---> ${detectedDrive}" echo "isNamedBlockchain: ${isNamedBlockchain}" echo "isFormatExt4:" ${isFormatExt4} # check if size is OK size=$(lsblk -o NAME,SIZE -b | grep "^${detectedDrive}" | awk '$1=$1' | cut -d " " -f 2) echo "size: ${size}" - if [ ${size} -lt 250000000000 ]; then - whiptail --title "FAIL" --msgbox " -THE DEVICE IS TOO SMALL <250GB -Please remove device and PRESS ENTER - " 9 46 + if [ ${size} -lt 900000000000 ]; then + echo "!! THE HDD/SSD IS TOO SMALL <900GB - use at least 1TB" + sed -i "s/^message=.*/message='HDD smaller than 1TB: ${detectedDrive}'/g" /home/admin/raspiblitz.info + echo + sleep 10 else - # if config value "nointeraction=1" default to format - if [ "${nointeraction}" != "1" ]; then - 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 + choice=0 + sed -i "s/^message=.*/message='Formatting new HDD: ${detectedDrive}'/g" /home/admin/raspiblitz.info # format the HDD 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 # 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:]") - if [ ${#partition} -gt 0 ]; then + if [ "${firstLoop}" != "1" ] && [ ${#partition} -gt 0 ]; then # temp mount device echo "mounting: ${partition}" mkdir /mnt/hdd2 2>/dev/null - sudo mount -t ext4 /dev/${partition} /mnt/hdd2 + mount -t ext4 /dev/${partition} /mnt/hdd2 # rsync device mountOK=$(lsblk -o NAME,MOUNTPOINT | grep "${detectedDrive}" | grep -c "/mnt/hdd2") 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 - sudo chmod -R 777 /mnt/hdd2 + chmod -R 777 /mnt/hdd2 rm -r /mnt/hdd2/lost+found 2>/dev/null - echo "${partition} " >> ./.syncinfo.tmp + echo "${partition}>OK" >> /var/cache/raspiblitz/copystationHddsInfoString.tmp else echo "# FAIL: was not able to mount --> ${partition}" fi # unmount device - sudo umount -l /mnt/hdd2 - + umount -l /mnt/hdd2 + fi fi 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 - echo "**** SYNC LOOP DONE ****" - 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 "" + if [ "${foundTargets}" == "1" ] && [ "${firstLoop}" == "1" ]; then - 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 echo "starting new sync loop" sleep 5 - -done + +done \ No newline at end of file diff --git a/home.admin/setup.scripts/eventInfoWait.sh b/home.admin/setup.scripts/eventInfoWait.sh index 6b26a609e..e40a834fa 100644 --- a/home.admin/setup.scripts/eventInfoWait.sh +++ b/home.admin/setup.scripts/eventInfoWait.sh @@ -140,11 +140,8 @@ Use your Password A elif [ "${eventID}" == "copystation" ] && [ "${mode}" == "lcd" ]; then - dialog --backtitle "${backtitle}" --cr-wrap --infobox " -Copy-Station Mode -ssh admin@${localip} -Use your Password A -" 7 41 + dialog --backtitle "${backtitle}" --title " Copy-Station Mode " --cr-wrap --infobox " +${contentString}" 7 41 elif [ "${eventID}" == "walletlocked" ] && [ "${mode}" == "lcd" ]; then