#!/usr/bin/perl
# Author: Alex Efros <powerman-asdf@yandex.ru>, 2008,2010
# License: Public Domain
#
# runas: run command as another user in "after login"-like environment

our $VERSION = 1.01;

die "Usage:"
  . "\trunas username command args ...\n"
  . "\trunas username 'command1 args; command2 args; ...'\n"
    if @ARGV < 2;
my $user = shift;
my $cmd = @ARGV==1 ? shift : join ' ', map {s{(['\\])}{\\$1}g; "\$'$_'"} @ARGV;
exec('su', '-c', "exec bash -l -i -c \Q$cmd\E", '-l', $user);
