system('/usr/bin/ssh', '-l', $owner, $host, $binct, @op, @lbtype);
####
$< = $>;
####
#!/vobs/cello/cade_struct/bin/perl -w
use strict;
use Sys::Hostname;
use File::Basename;
use Getopt::Long;
use ClearCase::Argv;
use vars qw($help $unlock $vob @op @nusers @lbtype);
my $me = basename($0);
my $host = hostname;
my $ssh = '/usr/bin/ssh';
my $binct = '/opt/rational/clearcase/bin/cleartool';
my $account = getlogin || getpwuid($<) or die "Couldn't get the uid: $!\n";
my $eaccount = getpwuid($>) or die "Couldn't get the euid: $!\n";
my $log = "/home/$eaccount/RANOS_autobuild/builds/logs/lbunlock.log";
$ENV{PATH} = '';
ClearCase::Argv->ipc(1);
my $ct = ClearCase::Argv->new({autochomp=>1});
sub usage() {
print "Usage: ${me} [[--unlock [| --nusers accounts]] --vob \n"
. " --lbtype | [--help]]\n"
. " By default, lock; use --unlock explicitely.\n"
. " Only one vob is accepted, and it is mandatory.\n"
. " Multiple label types are possible, either with separate options"
. "\n or as one comma separated list.\n"
. " All the types must exist in the vob.\n";
exit 1;
}
my $res = GetOptions("help" => \$help, "unlock" => \$unlock, "vob=s" => \$vob,
"nusers=s" => \@nusers, "lbtype=s" => \@lbtype);
usage if $help or !($res and $vob and @lbtype) or ($unlock and @nusers);
@lbtype = split(/,/, join(',', @lbtype));
my $vob = $ct->argv(qw(des -s), "vob:$vob")->qx;
die "Couldn't find the vob $vob\n" unless $vob;
my $pwnam = (getpwuid($<))[6];
$pwnam =~ s/^ *(.*[^ ]) *$/$1/;
if ($unlock) {
my @t = localtime;
my $t = sprintf"%4d%02d%02d.%02d:%02d:%02d",
(1900+$t[5]),1+$t[4],$t[3],$t[2],$t[1],$t[0];
open LOG, ">>", "$log" or die "Failed to open the $log log: $!\n";
print LOG "$t $account $vob @lbtype\n";
close LOG;
@op = ('unlock');
} else {
@op = ('lock', '-c', "'Actual lock author: $account \($pwnam\)'");
push(@op, '-nusers', join(',', @nusers)) if @nusers;
}
my ($owner) = grep s%^.*/(.*)$%$1%,
$ct->argv(qw(des -fmt "%[owner]p"), "vob:$vob")->qx;
map { $_ = "lbtype:$_\@$vob" } @lbtype;
foreach my $t (@lbtype) {
$ct->argv(qw(des -s), $t)->stdout(0)->system
and die "Label type $t not found in $vob\n";
}
$< = $>;
system('/usr/bin/ssh', '-l', $owner, $host, $binct, @op, @lbtype);