#!/bin/bash
if [ "$USER" != "root" ]; then
echo "You need to run me as root."
exit 1
fi
DEVICE=/dev/sdb
USB=/tmp/usb
SIZE=460
USB_SIZE=`parted --script $DEVICE print | grep "^Disk" | awk '{print $3}' | sed 's/MB//'`
# Removing the existing partitions on the device
echo "Removing the existing partitions (if any)..."
partition_list=`parted --script $DEVICE print | grep "^ [1-9]" | awk '{print $1}'`
for part in $partition_list; do
umount $DEVICE$part
parted --script $DEVICE rm $part
done
# Creating the new ones, the first is fat16, the second ext3 (The rest of the key space)
echo "Creating the partition(s)..."
parted --script $DEVICE mkpartfs primary fat16 0 $SIZE
parted --script $DEVICE mkpartfs primary ext2 $SIZE $USB_SIZE
parted --script $DEVICE set 1 boot on
sleep 5
[ -d $USB ] || mkdir $USB
umount $USB
rm -rf $USB/*
echo "Copying on the USB stick..."
mount -t vfat "$DEVICE"1 $USB
cp -a /cdrom/. $USB/
echo "Making the USB stick bootable..."
syslinux "$DEVICE"1
umount $USB
echo "Done."
exit