All pastes #390276 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-03-11 09:48 UTC
rendered paste body
#!/bin/bash
  
if [ "$USER" != "root" ]; then
	echo "You need to run me as root."
	exit 1
fi

for i in syslinux mtool; do
	if ! [ `dpkg -l | grep "^ii" | awk '{print $2}' | grep $i` ]; then
		install="yes"
	fi
do

if [ $install = "1" ]; then
	echo "Installing the missing packages..."
	apt-get install -y --force-yes syslinux mtool
fi

DEVICE=/dev/sdb
USB=/tmp/usb
SIZE=460
USB_SIZE=`parted --script $DEVICE print | grep "^Disk" | awk '{print $3}' | sed 's/MB//'`

if [ ! -f $DEVICE ]; then
	echo "No USB stick found. Please plug it in and restart me."
	exit 1
fi

# 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 0