#!/bin/bash

if [ ! -n "$1" ]; then
  echo 'Please input device name for script, eg. /dev/sda'
  exit 0
fi

DEV_NODE=$1

BOOT_ROM_SIZE=10
KERNEL_SIZE=2048

## Partition
## Erase partition table
dd if=/dev/zero of=${DEV_NODE} bs=1024 count=1

sfdisk --force -uM ${DEV_NODE} << EOF
,${KERNEL_SIZE},0c,*
,,83
EOF

## Format
mkfs.vfat -F 32 ${DEV_NODE}1
until [ "$?" == 0 ]; do
	sleep 8
done
mkfs.ext4 ${DEV_NODE}2
until [ "$?" == 0 ]; do
        sleep 8
done

echo "Finished!"
exit 0
