#! /bin/bash
usage()
{
cat <<EOF
Usage: quota-image.sh OPERATION NAME
Supported OPERATION types:
create Create and mount IMAGE
destroy Unmount and destroy IMAGE
EOF
}
if [ $ usage
exit 1;
fi
OPERATION="$1"
IMAGE="$2"
case $IMAGE in
*.dmg) ;;
*) IMAGE="$IMAGE.dmg" ;;
esac
VOLNAME=$(echo $IMAGE | sed '-es/.dmg//' | tr 'a-z' 'A-Z')
SIZE=${SIZE:-20m}
ASROOT=sudo
ME=$(whoami)
make_disk_image()
{
echo creating disk image
hdiutil create -size $SIZE -fs HFSJ -volname $VOLNAME $IMAGE
}
mount_disk_image()
{
echo mounting disk image
hdiutil attach $IMAGE -readwrite -mount required -owners on
$ASROOT mount -u -o owners,perm /Volumes/$VOLNAME
$ASROOT mdutil -v -i off /Volumes/$VOLNAME
}
enable_quotas()
{
echo enabling user and group quotas
$ASROOT touch /Volumes/$VOLNAME/.quota.ops.user
$ASROOT touch /Volumes/$VOLNAME/.quota.ops.group
$ASROOT quotacheck -ug /Volumes/$VOLNAME
$ASROOT quotaon -ugv /Volumes/$VOLNAME
}
cleanup()
{
echo destroying disk image
$ASROOT quotaoff -ugv /Volumes/$VOLNAME
hdiutil detach /Volumes/$VOLNAME
rm -f $IMAGE
}
case $OPERATION in
create)
trap cleanup 1 2 3 15
make_disk_image && mount_disk_image && enable_quotas
df -h /Volumes/$VOLNAME
$ASROOT chmod 777 /Volumes/$VOLNAME
$ASROOT repquota -u -v /Volumes/$VOLNAME
exit 0
;;
destroy)
cleanup
;;
*)
usage
exit 1
;;
esac