#!/usr/athena/bin/perl
use warnings;
use strict;

sub id2list ( $ ) { "bert-spare-$_[0]"; }

my $next_maybe_unused = 0;
sub next_spare () {
  while (1) {
    my $list = id2list $next_maybe_unused;
    ++$next_maybe_unused;
    my $info = `blanche -i "$list" 2>/dev/null`;
    return $list unless $info =~ /\S/;
  }
}

for my $list (@ARGV) {
  my @cmd_line = ( 'blanche', '-v', $list );
  push @cmd_line, '-rename', next_spare unless $list =~ /^bert-spare-/;
  push @cmd_line, '-file', '/dev/null';
  push @cmd_line, ( '-inactive', '-private', '-visible', '-notmail',
		    '-notgroup', '-notnfs', '-desc', 'spare list',
		    '-owner', 'user:bert', '-memacl', 'NONE' );
  print ">> @cmd_line\n";
  system @cmd_line;
}
