#!/usr/bin/perl
# $Id: caddgroup,v 1.1 2001/08/20 19:42:55 jeffb Exp $
# Copyright (c) 1999,2000 Cobalt Networks, Inc. 
# http://www.cobalt.com/
#
use strict;
$0 = "caddgroup";

use lib qw(/usr/sausalito/perl);

require ShellCfg;
require Shell;
use Getopt::Std;

my $opts = {};
getopts('n:r:q:u:vh', $opts);

if ($opts->{h} || !$opts->{n}) {
	usage();
}
my $grpRef = ShellCfg::mapOpts('groupAdd', $opts);

# connect to CCE
my $cce = new Shell;
$cce->connectuds();

# strip out the other stuff
my $diskRef = $grpRef->{Disk} if ($grpRef->{Disk});
$grpRef = ShellCfg::stripRef($grpRef);

if(exists($grpRef->{members})) {
	$grpRef->{members} = $cce->validateUsers($grpRef->{members});
}

# create the user
$cce->create("Workgroup", $grpRef);

# if we get here, we must set other data related to the user
my $oid = $cce->oid();

if ($diskRef) {
	$cce->set($oid, "Disk", $diskRef);
} 

warn "\nGroup ", $grpRef->{name}, " has been created.\n";
$cce->bye("chill till the next episode");
exit 0;

sub usage 
{
print <<EOF;
$0: Copyright (c) 1999,2000,2001 Cobalt Networks, Inc.
usage: $0 [-n group name] [-u users] [-q quota] [-r remarks]

        -n The group name you want to create
        -u list of user names to add to the group, comma delimited
        -q group's disk quota (in MB)
        -r group's remarks
        -h show this help
EOF
    exit 0;
}


