#!/bin/bash
# FreeLnx Mover Script
# MOves installer to new HDD.

$GRUB=/mnt/boot/grub

clear
echo "This will copy your FreeLnx to another disk."
echo
while true
echo -n "Continue (y or n)? "
read
do
	case $REPLY in
		y|Y) break;;
		n|N) exit 0;;
		*) echo "Please enter only y or n.";;
	esac
done

clear

while true
echo -n "Enter destination drive (eg. sdb): "
read DISK
do
	case $DISK in
		sda) echo "WARNING - sda is the source disk!";;
		*) break;;
	esac
done

dd if=/dev/sda of=/dev/$DISK count=64
fdisk /dev/$DISK << EOF
w

EOF
mkfs -t vfat /dev/"$DISK"1
mkswap /dev/"$DISK"2
mkfs -t ext4 /dev/"$DISK"3
mkfs -t ext4 /dev/"$DISK"4
dd if=/dev/sda1 of=/dev/"$DISK"1
sync
mount /dev/"$DISK"3 /mnt

clear
echo "WARNING!!!
echo "Do not turn off your system."
echo "This may take a while."
echo "Press any key to continue."
read

cp -av /boot /mnt
cp $GRUB/grub.cfg $GRUB/grub.tmp
cat $GRUB/grub.tmp | sed 's,default="0",default="1",' > $GRUB/grub.cfg
rm $GRUB/grub.tmp
sync
umount /mnt
clear
echo "Follow these steps next:"
echo
echo "1. Shutdown the system."
echo "2. Remove original drive (sda)."
echo "3. Boot with new drive."
echo
echo "Perform recovery on new drive from the boot menu."
echo
