#!/usr/athena/bin/perl -w
use strict;
use vars qw( @wrapper );

NEWPAG: {
  # speed up things that don't start a new screen session
  exists $ENV{'STY'}
    and last NEWPAG;
  @ARGV == 1 and ($ARGV[0] eq '-ls' or $ARGV[0] eq '-list')
    and last NEWPAG;

  @ARGV = qw[ -A -R ] unless @ARGV;

  # might be starting a new session; start inside a new PAG so tokens live on
  my $newpag = '/usr/athena/bin/newpag';
  -x $newpag or $newpag = undef;
  if (defined $newpag) {
    @wrapper = ( $newpag );
    if (-x "$0-auth-helper") {
      push @wrapper, "$0-auth-helper";
    } else {
      warn "scr: $0-auth-helper not found!\n";
    }
  }
}

my @cmdline = ( @wrapper, 'screen', @ARGV );
exec @cmdline;
