#!/bin/sh

if [ `id -u` -ne 0 ];
then
	echo "Please run this script as root"
	exit 1
fi

if [ `/sbin/zfs list -Hp zudi | /usr/bin/cut -f 3` -gt 10000000000 ];
then
        echo "Looks like you've ran this script before?..."
	exit 1
fi

echo "Resizing Polisy filesystems, please do not interrupt. No reboot is required after this script is finished"
echo "Stopping swap file"

/sbin/swapoff -a

if [ $? -ne 0 ];
then
	echo "Could not stop the swap file, please reboot the Polisy and try again"
	exit 1
fi

echo "Resizing..."
/sbin/gpart delete -i 4 ada0
/sbin/gpart resize -i 3 -s 26400M ada0
/sbin/gpart add -t freebsd-swap -l swap0  ada0
/sbin/gpart show

echo "Turning swap back on"
/sbin/swapon -a

echo "Expanding ZFS..."
/sbin/zpool online -e zudi /dev/gpt/disk0

/sbin/zfs list

echo "All done"
exit 0
