Skip to content

Instantly share code, notes, and snippets.

@silicontrip
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save silicontrip/9800116 to your computer and use it in GitHub Desktop.

Select an option

Save silicontrip/9800116 to your computer and use it in GitHub Desktop.
#/bin/bash
while true
do
homeuuid=$(grep '/home' /etc/fstab | awk '{print $1}' | cut -d = -f 2)
ssd=$(lsblk -o KNAME,MODEL | grep SSD | cut -d ' ' -f 1)
mounted=$(mount | grep /home | cut -d ' ' -f 1 )
ssduuid=$(ls -la /dev/disk/by-uuid | grep bcache0 | awk '{print $9}')
formatted=$( ls /dev/bcache0 )
homedev=$(ls -la /dev/disk/by-uuid/${homeuuid} | cut -d / -f 7 )
if [ -z "$ssd" ]
then
echo "Cannot find SSD."
exit
fi
if [ -r /dev/${ssd}1 ]
then
echo "SSD has partitions. Wipe and reboot"
# should I wipe it myself?
# dd if=/dev/zero of=/dev/${ssd} count=32
exit
fi
if [ ! -z "${mounted}" ]
then
if [ "$mounted" == "/dev/bcache0" ]
then
echo "Mounted and Enabled"
exit
else
echo "Mounted and not Enabled"
umount /home
fi
else
if [ ! -z "$ssduuid" ]
then
if [ "$ssduuid" == "$homeuuid" ]
then
echo "unmounted, bcache formatted and fstab edited"
mount /home
else
echo "unmounted, bcache formatted and fstab not edited"
cp /etc/fstab /etc/fstab~
sed s/${homeuuid}/${ssduuid}/ /etc/fstab~ > /etc/fstab
fi
else
if [ -z "$formatted" ]
then
echo "unmounted not formatted"
make-bcache -C /dev/${ssd}
make-bcache -B /dev/${homedev}
# appears to take a while before appearing.
while [ ! -r /dev/bcache0 ]
do
echo "Waiting for bcache device..."
sleep 1
done
else
echo "/dev/bcache0 exists but is not /home partition"
mke2fs -t ext4 /dev/bcache0
fi
fi
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment