#!/usr/bin/env perl

use strict;
use warnings FATAL => 'all';

my %alias = ('mk-log-parser' => 'mk-query-digest');

my $input = shift;
if ( $input ) {

   if ( $alias{$input} ) {
      print "Status: 302 Moved\nLocation: http://www.maatkit.org/trunk/$alias{$input}\n\n";
      exit(0);
   }

   # Get a list of the Maatkit scripts, and try to find one that matches the
   # input.
   my %scripts = map { (my $s = $_) =~ s!^.*/!!; $s => $_;  } <trunk/mk-*/mk-*>;
   my ($script) = grep { m/$input/ } keys %scripts;
   if ( $script ) {
      print "Status: 302 Moved\nLocation: http://maatkit.googlecode.com/svn/trunk/$script/$script\n\n";
      exit(0);
   }
}

print "Status: 404 Not Found\n";
print "Content-type: text/plain\n\n";
print "No such script found\n";
exit(0);
