#!/usr/bin/perl -w

# contributed by Dominic Rivera

$idisk_volume = '/usr';

my $output = `df $idisk_volume`;
$output = (split('\n',$output))[1];
my ( $total_disk_size, $used_bytes ) = (split(' ',$output))[1,2];

$total_disk_size *= 1024;
$used_bytes *= 1024;

print <<EOCONF
Content-type: text/plain

{
    payload = {
        guestReadEnabled = Y;
        guestWriteEnabled = N;
        hasGeneralPassword = N;
        iDiskQuotaInBytes = $total_disk_size;
        iDiskUsedBytes = $used_bytes;
        relativePath = Public;
    };
    statusCode = success;
}
EOCONF
;

__END__

# a newer version for per-user disk images

#!/usr/bin/perl -w

my $username;

# Grab the username from the input data.
while(<STDIN>){
 if ( /username\s+=\s+(.*?)\;/ ){
   $username = $1;;
 }
}

# Find the total size and the used size of the volume /idisk/{username}
my $output = `df /idisk/$username`;
$output = (split('\n',$output))[1];
my ( $total_disk_size, $used_bytes ) = (split(' ',$output))[1,2];

$total_disk_size *= 1024;
$used_bytes *= 1024;

print "Content-type: text/plain\n";
print "\n";
print "{\n";
print "    payload = {\n";
print "        guestReadEnabled = Y;\n";
print "        guestWriteEnabled = N;\n";
print "        hasGeneralPassword = N;\n";
print "        iDiskQuotaInBytes = $total_disk_size;\n";
print "        iDiskUsedBytes = $used_bytes;\n";
print "        relativePath = Public;\n";
print "    };\n";
print "    statusCode = success;\n";
print "}\n";

