#!/usr/bin/perl

$username = @ARGV[0];
$public_key_url = @ARGV[1];
system '/usr/sbin/adduser', $username;
if( system( 'wget', $public_key_url ) == 0 ) {
  mkdir "/home/$username/.ssh";
  ( $public_key_filename ) = ( $public_key_url =~ /.+\/(.+?)$/ );
  system 'mv', $public_key_filename, "/home/$username/.ssh/authorized_keys";
  system 'chmod', '-R', 'g-w', "/home/$username/.ssh"; 
  system 'chown', '-R', "$username:$username", "/home/$username/.ssh";
} else {
  print "unable to download public key !";
}

