#!/usr/bin/perl -w

use strict;
use Sudo;

# This is meant to be suid enabled
# This is the version using sudo. There is an alternative version using ssh.

my $fsc ='/usr/local/bin/fixsrccont';

my $rc = 0;
my %batch;
for (@ARGV) {
  push @{$batch{$1}}, $2 if /^(\w+?):(.*)$/;
}
for my $owner (keys %batch) {
  my @arg = @{$batch{$owner}};
  my $su = Sudo->new({
    sudo => '/usr/bin/sudo',
    username => $owner,
    program => $fsc,
    program_args => join '@@', @arg, # split on whitespace...
  });
  my $res = $su->sudo_run();
  if (!$res->{rc}) {
    $rc = 1;
    print STDERR $res->{stderr}, "\n";
  }
  print STDOUT $res->{stdout}, "\n";
}
exit $rc;
