#!/s/std/bin/perl -w

print STDERR "Verifying that wsbackup can dump local disks\n";

chomp ($arch = `uname`);

if ($arch eq "Linux") {
  $group = "disk";
} elsif ($arch eq "SunOS") {
  $group = "sys";
} elsif ($arch eq "OSF1") {
  $group = "operator";
} else {
  die "Don't know what group to fix on arch *$arch*!";
}

# Read the group file and add wsbackup to the appropriate group

chdir "/etc";

open (GROUP, '<group') or die "Can't open the group file";
open (NEWGRP, '>newgrp') or die "Can't open the proto group file";
while (<GROUP>) {
  chomp;
  @words = split (':', $_);
  if ($words[0] eq $group) {
    print STDERR "Checking group $_\n";
    if ($words[3] !~ /wsbackup/) {
      print STDERR "Adding wsbackup to group $words[0]\n";
      $words[3] .= ",wsbackup";
      print NEWGRP join (":", @words) . "\n";
    } else {
      print NEWGRP $_ . "\n";
    }
  } else {
    print NEWGRP $_ . "\n";
  }
}

unlink('group.old');
link('group', 'group.old') || print STDERR "link group group.old failed\n";
rename('newgrp', 'group') || die "Can't install new group file: $!\n";

exit 0;

