#!/bin/sh

echo "Creating root FS."
mkdir /tmp/target
newfs -J -U -O 2 -L $3 /dev/$1
mount /dev/$1 /tmp/target
cd /tmp/target

echo "Copying base."
cp /usr/freebsd-dist/base.txz /tmp/target/
echo "Extracting base."
tar -Jxvf base.txz 2>/dev/null
rm base.txz

echo "Copying doc."
cp /usr/freebsd-dist/doc.txz /tmp/target/
echo "Extracting doc."
tar -Jxvf doc.txz 2>/dev/null
rm doc.txz

echo "Copying kernel."
cp /usr/freebsd-dist/kernel.txz /tmp/target/
echo "Extracting kernel."
tar -Jxvf kernel.txz 2>/dev/null
rm kernel.txz

echo "Copying lib32."
cp /usr/freebsd-dist/lib32.txz /tmp/target/
echo "Extracting lib32."
tar -Jxvf lib32.txz 2>/dev/null
rm lib32.txz

echo "Copying ports."
cp /usr/freebsd-dist/ports.txz /tmp/target/
echo "Extracting ports."
tar -Jxvf ports.txz 2>/dev/null
rm ports.txz

echo "Copying src."
cp /usr/freebsd-dist/src.txz /tmp/target/
echo "Extracting src."
tar -Jxvf src.txz 2>/dev/null
rm src.txz

echo "Creating /etc/fstab and /etc/hostname."
echo "/dev/$1	     /		     ufs     rw		     1	     1" >> etc/fstab
echo "/dev/$2	     none	     swap    sw		     0	     0" >> etc/fstab
echo "/dev/cd0	     /cdrom	     cd9660  ro,noauto	     0	     0" >> etc/fstab
echo "hostname=\"$3\"" > etc/rc.conf
