You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.8 KiB

6 years ago
#!/bin/bash
7 years ago
echo ""
## get basic info
source /home/admin/raspiblitz.info
7 years ago
echo "*** Adding HDD to the System ***"
echo "started from state(${state})"
7 years ago
sleep 5
existsHDD=$(lsblk | grep -c sda)
if [ ${existsHDD} -gt 0 ]; then
echo "OK - HDD found as sda"
7 years ago
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
7 years ago
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
7 years ago
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 ""
7 years ago
# init the RASPIBLITZ Config
configFile="/mnt/hdd/raspiblitz.conf"
6 years ago
configExists=$(sudo ls ${configFile} | grep -c 'raspiblitz.conf')
if [ ${configExists} -eq 0 ]; then
source /home/admin/_version.info
6 years ago
sudo touch $configFile
sudo chmod 777 ${configFile}
echo "# RASPIBLITZ CONFIG FILE" > $configFile
echo "raspiBlitzVersion='${codeVersion}'" >> $configFile
echo "network=${network}" >> $configFile
echo "chain=${chain}" >> $configFile
echo "hostname=${hostname}" >> $configFile
fi
# move SSH pub keys to HDD so that they survive an update
echo "moving SSH pub keys to HDD"
sudo cp -r /etc/ssh /mnt/hdd/ssh
sudo rm -rf /etc/ssh
sudo ln -s /mnt/hdd/ssh /etc/ssh
echo "OK"
echo ""
# set SetupState
sudo sed -i "s/^setupStep=.*/setupStep=40/g" /home/admin/raspiblitz.info
7 years ago
echo "*** Analysing HDD Content ***"
if [ -d "/mnt/hdd/${network}" ]; then
sudo chown -R bitcoin:bitcoin /mnt/hdd/bitcoin 2>/dev/null
sudo chown -R bitcoin:bitcoin /mnt/hdd/litecoin 2>/dev/null
echo "Looks like the HDD is prepared with the Blockchain."
if [ "${state}" = "recovering" ]; then
# when HDD got added on update/provisioning
echo "OK HDD got added ... returning to provisioning"
exit 1
else
# when normal setup
echo "Continuing with finishing the system setup ..."
./60finishHDD.sh
fi
else
# HDD is empty - let setupBlitz - display next options
echo "HDD empty --> go setup"
./10setupBlitz.sh
fi # END Analysing HDD Content
else
7 years ago
echo "FAIL - was not able to mount"
fi # END Mount check
7 years ago
else
echo "FAIL - was not able to edit /etc/fstab"
fi
7 years ago
else
echo "FAIL - the HDD is not in ext4 format AND named 'BLOCKCHAIN'"
fi
7 years ago
fi
else
echo "FAIL - no HDD as device sda found"
echo "check if HDD is properly connected and has enough power - then try again with reboot"
7 years ago
fi