From 00b07362f2bd5a5e78df5bdf37f53415a80fb9a3 Mon Sep 17 00:00:00 2001 From: rootzoll Date: Thu, 2 Aug 2018 18:03:28 +0200 Subject: [PATCH] small fixes and handle more than one sda --- home.admin/10setupBlitz.sh | 2 +- home.admin/30initHDD.sh | 29 ++++++++++++++++++++++++++--- home.admin/40addHDD.sh | 10 +++++----- home.admin/50downloadHDD.sh | 9 +++++---- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/home.admin/10setupBlitz.sh b/home.admin/10setupBlitz.sh index 75815e179..8550fbb75 100755 --- a/home.admin/10setupBlitz.sh +++ b/home.admin/10setupBlitz.sh @@ -51,7 +51,7 @@ if [ ${mountOK} -eq 1 ]; then fi # check if there is a download to continue - downloadProgressExists=$(sudo ls /home/admin/.Download.progress 2>/dev/null | grep ".Download.progress" -c) + downloadProgressExists=$(sudo ls /home/admin/.Download.out 2>/dev/null | grep ".Download.out" -c) if [ ${downloadProgressExists} -eq 1 ]; then echo "found download in progress .." ./50downloadHDD.sh diff --git a/home.admin/30initHDD.sh b/home.admin/30initHDD.sh index 916ff87d9..6d49fbf85 100755 --- a/home.admin/30initHDD.sh +++ b/home.admin/30initHDD.sh @@ -2,9 +2,32 @@ echo "" echo "*** Checking if HDD is connected ***" sleep 5 +device="sda1" existsHDD=$(lsblk | grep -c sda1) if [ ${existsHDD} -eq 1 ]; then - echo "OK - HDD found as sda1" + echo "OK - HDD found at sda1" + + # check if there is s sda2 + existsHDD2=$(lsblk | grep -c sda2) + if [ ${existsHDD2} -eq 1 ]; then + echo "OK - HDD found at sda2 ... determine which is bigger" + + # get both with size + size1=$(lsblk -o NAME,SIZE -b | grep "sda1" | awk '{ print substr( $0, 12, length($0)-2 ) }' | xargs) + echo "sda1(${size1})" + size2=$(lsblk -o NAME,SIZE -b | grep "sda2" | awk '{ print substr( $0, 12, length($0)-2 ) }' | xargs) + echo "sda2(${size2})" + + # chosse to run with the bigger one + if [ ${size2} -gt ${size1} ]; then + echo "sda2 is BIGGER - run with this one" + device="sda2" + else + echo "sda1 is BIGGER - run with this one" + fi + + fi + mountOK=$(df | grep -c /mnt/hdd) if [ ${mountOK} -eq 1 ]; then echo "FAIL - HDD is mounted" @@ -12,10 +35,10 @@ if [ ${existsHDD} -eq 1 ]; then else echo "" echo "*** Formatting the HDD ***" - echo "WARNING ALL DATA ON HDD WILL GET DELETED" + echo "WARNING ALL DATA ON HDD WILL GET DELETED - CAN TAKE SOME TIME" echo "Wait until you get a OK or FAIL" sleep 4 - sudo mkfs.ext4 /dev/sda1 -F -L BLOCKCHAIN + sudo mkfs.ext4 /dev/${device} -F -L BLOCKCHAIN echo "format ext4 done - wait 6 secs" sleep 6 formatExt4OK=$(lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL | grep BLOCKCHAIN | grep -c ext4) diff --git a/home.admin/40addHDD.sh b/home.admin/40addHDD.sh index b07aa6c6b..d0e3ceda8 100755 --- a/home.admin/40addHDD.sh +++ b/home.admin/40addHDD.sh @@ -6,9 +6,9 @@ network=`cat .network` echo "*** Adding HDD to the System ***" sleep 5 -existsHDD=$(lsblk | grep -c sda1) -if [ ${existsHDD} -eq 1 ]; then - echo "OK - HDD found as sda1" +existsHDD=$(lsblk | grep -c sda) +if [ ${existsHDD} -gt 0 ]; then + echo "OK - HDD found as sda" mountOK=$(df | grep -c /mnt/hdd) if [ ${mountOK} -eq 1 ]; then echo "FAIL - HDD is already mounted" @@ -67,6 +67,6 @@ if [ ${existsHDD} -eq 1 ]; then fi fi else - echo "FAIL - no HDD as device sda1 found" - echo "check if HDD is properly connected and has enough power - then try again" + echo "FAIL - no HDD as device sda found" + echo "check if HDD is properly connected and has enough power - then try again with reboot" fi diff --git a/home.admin/50downloadHDD.sh b/home.admin/50downloadHDD.sh index b3801795d..7cc9f6fba 100755 --- a/home.admin/50downloadHDD.sh +++ b/home.admin/50downloadHDD.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash echo "" # *** BITCOIN *** @@ -38,6 +38,7 @@ isRunning=$( screen -S ${name} -ls | grep "${name}" -c ) echo "isRunning(${isRunning})" if [ ${isRunning} -eq 0 ]; then echo "Starting screen session" + sudo mkdir ${targetDir} 2>/dev/null screen -S ${name} -dm ${command} else echo "Continue screen session" @@ -139,8 +140,8 @@ targetPath=$(echo ${url} | cut -d '@' -f2) echo "path to downloaded data is ${targetPath}" # calculate progress and write it to file for LCD to read -finalSize=$( du -s ${targetDir} | head -n1 | awk '{print $1;}' ) -if [ ${#actualSize} -eq 0 ]; then +finalSize=$( du -s ${targetDir} 2>/dev/null | head -n1 | awk '{print $1;}' ) +if [ ${#finalSize} -eq 0 ]; then finalSize=0 fi echo "final size is ${finalSize} of targeted size ${targetSize}" @@ -151,7 +152,7 @@ if [ ${finalSize} -lt ${targetSize} ]; then # Download failed sleep 3 echo -ne '\007' - dialog --title " WARNING " --yesno "The download failed or is not complete. Do you want keep already downloaded data?" 6 57 + dialog --title " WARNING " --yesno "The download failed or is not complete. Maybe try again (later). Do you want keep already downloaded data for next try?" 6 57 response=$? case $response in 1) sudo rm -rf ${targetDir}${targetPath} ;;