raspiblitz/home.admin/40addHDD.sh
2018-07-17 13:12:03 +02:00

69 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
echo ""
echo "*** Adding HDD to the System ***"
sleep 5
existsHDD=$(lsblk | grep -c sda1)
if [ ${existsHDD} -eq 1 ]; then
echo "OK - HDD found as sda1"
mountOK=$(df | grep -c /mnt/hdd)
if [ ${mountOK} -eq 1 ]; then
echo "FAIL - HDD is already mounted"
echo "If you want to add HDD freshly to the system, then unmount the HDD first and try again"
else
echo ""
echo "*** Check HDD ***"
formatExt4OK=$(lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL | grep BLOCKCHAIN | grep -c ext4)
if [ ${formatExt4OK} -eq 1 ]; then
echo "OK - HDD is formatted with ext4 and is named BLOCKCHAIN"
uuid=$(lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL | grep BLOCKCHAIN)
set -- $uuid
uuid=$1
fstabOK=$(cat /etc/fstab | grep -c ${uuid})
if [ ${fstabOK} -eq 0 ]; then
fstabAdd="UUID=${uuid} /mnt/hdd ext4 noexec,defaults 0 0"
echo "Adding line to /etc/fstab ..."
echo ${fstabAdd}
# adding the new line after line 3 to the /etc/fstab
sudo sed "3 a ${fstabAdd}" -i /etc/fstab
else
echo "UUID is already in /etc/fstab"
fi
fstabOK=$(cat /etc/fstab | grep -c ${uuid})
if [ ${fstabOK} -eq 1 ]; then
echo "OK - HDD is listed in /etc/fstab"
echo ""
echo "*** Mount HDD ***"
sudo mkdir /mnt/hdd
sudo mount -a
mountOK=$(df | grep -c /mnt/hdd)
if [ ${mountOK} -eq 1 ]; then
echo "OK - HDD is mounted"
echo ""
# set SetupState
echo "40" > /home/admin/.setup
echo "*** Analysing HDD Content ***"
if [ -d "/mnt/hdd/bitcoin" ]; then
echo "Looks like the HDD is prepared with the Blockchain."
echo "Continuing with finishing the system setup ..."
./60finishHDD.sh
else
# HDD is empty - let setupBlitz - display next options
./10setupBlitz.sh
fi
else
echo "FAIL - was not able to mount"
fi
else
echo "FAIL - was not able to edit /etc/fstab"
fi
else
echo "FAIL - the HDD is not in ext4 format AND named 'BLOCKCHAIN'"
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"
fi