raspiblitz/home.admin/30initHDD.sh

125 lines
4.1 KiB
Bash
Raw Normal View History

2018-12-05 00:07:58 +01:00
#!/bin/bash
2019-02-11 15:04:36 +01:00
2019-02-13 02:33:27 +01:00
## get basic info
source /home/admin/raspiblitz.info 2>/dev/null
2018-07-17 13:12:03 +02:00
echo ""
echo "*** Checking if HDD is connected ***"
sleep 5
device="sda1"
2018-07-17 13:12:03 +02:00
existsHDD=$(lsblk | grep -c sda1)
2019-02-11 15:04:36 +01:00
2018-07-17 13:12:03 +02:00
if [ ${existsHDD} -eq 1 ]; then
echo "OK - HDD found at sda1"
# check if there is s sda2
existsHDD2=$(lsblk | grep -c sda2)
2019-05-07 17:15:57 +01:00
hddSecondDriveExists=$(lsblk | grep -c sdb)
if [ ${existsHDD2} -eq 1 ] || [ ${hddSecondDriveExists} -eq 1 ] ; then
2019-05-08 13:16:00 +01:00
echo "OK - another HDD found at sdb ... 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})"
2019-05-07 17:15:57 +01:00
size3=$(lsblk -o NAME,SIZE -b | grep "sdb" | awk '{ print substr( $0, 8, length($0)-2 ) }' | xargs)
2019-05-08 13:16:00 +01:00
echo "sdb(${size3})"
2019-05-07 17:15:57 +01:00
# choose to run with the bigger one
if [ ${size2} -gt ${size1} ]; then
echo "sda2 is BIGGER - run with this one"
device="sda2"
2019-05-07 17:15:57 +01:00
elif [ ${size3} -gt ${size1} ]; then
echo "sdb is BIGGER - run with this one"
2019-12-25 20:57:21 +01:00
device="sdb"
else
echo "sda1 is BIGGER - run with this one"
fi
fi
2019-02-11 15:04:36 +01:00
# quick basic size check
echo ""
echo "*** HDD Size Check ***"
# bitcoin > 450 GB
2019-02-13 02:27:54 +01:00
minSize=450000000000
2019-02-13 02:20:21 +01:00
# litecoin > 31 GB
2019-02-11 15:04:36 +01:00
if [ "${network}" = "litecoin" ]; then
2019-02-13 02:27:54 +01:00
minSize=31000000000
2019-02-11 15:04:36 +01:00
fi
2019-02-13 02:27:54 +01:00
isSize=$(lsblk -o NAME,SIZE -b | grep "${device}" | awk '$1=$1' | cut -d " " -f 2)
if [ ${isSize} -lt ${minSize} ]; then
if [ ${isSize} -gt 1 ]; then
2019-02-11 15:04:36 +01:00
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "WARNING: HDD might be too small"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
2019-02-13 02:27:54 +01:00
echo "You HDD was detected with the size of ${isSize} bytes"
echo "For ${network} at least ${minSize} bytes is recommended"
echo "If you know the HDD is bigger then detected, please"
2019-12-25 20:57:21 +01:00
echo "change HDD to 1 partition on another computer first,"
2019-02-11 15:04:36 +01:00
echo "If you want to change to a bigger HDD:"
echo "* Unplug power of RaspiBlitz"
echo "* Make a fresh SD card again"
echo "* Start again with bigger HDD"
echo "If you want to try with HDD connected, press ENTER to continue."
read key
else
echo "WARN: Was not able to get size of HDD ... skipping"
sleep 3
fi
else
echo "OK: HDD seems big enough"
fi
echo ""
2018-07-17 13:12:03 +02:00
mountOK=$(df | grep -c /mnt/hdd)
if [ ${mountOK} -eq 1 ]; then
echo "FAIL - HDD is mounted"
echo "If you really want to reinit the HDD, then unmount the HDD first and try again"
2019-12-25 20:57:21 +01:00
else
2019-04-16 19:29:47 +01:00
echo ""
dialog --title "Format HDD" --yes-button "Yes" --no-button "Cancel" --yesno "RaspiBlitz detected a Hard Disk Drive (HDD).
2019-12-25 20:57:21 +01:00
It will get formatted to EXT4 to be useful.
2019-04-16 19:29:47 +01:00
This will DELETE ALL FORMER DATA on the HDD.
Is it OK to delete HDD for fresh RaspiBlitz?
" 10 48
if [ $? -eq 1 ]; then
dialog --title "Replace HDD" --msgbox "OK. RaspiBlitz will shutdown now.
2019-12-25 20:57:21 +01:00
Please disconnect Power then.
2019-04-16 19:29:47 +01:00
Backup HDD data or connect another one.
Then Power up again." 8 39
sudo shutdown now
exit 1
fi
2019-04-26 02:19:48 +02:00
clear
2018-07-17 13:12:03 +02:00
echo ""
echo "*** Formatting the HDD ***"
echo "WARNING ALL DATA ON HDD WILL GET DELETED - CAN TAKE SOME TIME"
2018-07-17 13:12:03 +02:00
echo "Wait until you get a OK or FAIL"
sleep 4
sudo mkfs.ext4 /dev/${device} -F -L BLOCKCHAIN
2018-07-17 13:12:03 +02:00
echo "format ext4 done - wait 6 secs"
sleep 6
2019-12-25 20:57:21 +01:00
formatExt4OK=$(lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL | grep BLOCKCHAIN | grep -c ext4)
2018-07-17 13:12:03 +02:00
if [ ${formatExt4OK} -eq 1 ]; then
echo "OK - HDD is now formatted in ext4"
sleep 1
# set SetupState
2018-12-06 14:36:02 +01:00
sudo sed -i "s/^setupStep=.*/setupStep=30/g" /home/admin/raspiblitz.info
2018-07-17 13:12:03 +02:00
# automatically now add the HDD to the system
./40addHDD.sh
else
echo "FAIL - was not able to format the HDD to ext4 with the name 'BLOCKCHAIN'"
fi
fi
else
echo "FAIL - no HDD as device sda1 found"
echo "lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL"
echo "check if HDD is properly connected and has enough power - then try again"
echo "sometimes a reboot helps: sudo shutdown -r now"
fi