#!/usr/bin/perl

use lib qw(/usr/lib/libDrakX);

use common qw(:common :functional :system :file);
use interactive;
use standalone;
use any;

local $_ = join '', @ARGV;

/-h/ and die "usage: adduserdrake [--beginner] [--expert] [<users...>]\n";

$::beginner = /-beginner/;
$::expert = /-expert/;

my @etc_pass_fields = qw(name pw uid gid realname home shell);
my @shells = grep { -x $_ } map { "/bin/$_" } qw(bash tcsh zsh ash ksh);
my $isMD5 = cat_("/etc/pam.d/passwd") =~ /md5/;
my $isShadow = cat_("/etc/pam.d/passwd") =~ /shadow/;


my $users = []; 
my $in;

if (my @l = grep { ! /^-/ } @ARGV) {
    $users = [ map { { name => $_, realname => $_ } } @l ];
} else {
    $in = interactive->vnew('su');
    any::ask_users('', $in, $users, $ENV{SECURE_LEVEL});
}

system("adduser", $_->{name}) foreach @$users;
any::addUsers('', $users);

any::write_passwd_user('', $_, $isMD5) foreach @$users;
system("pwconv") if $isShadow;

#$in->pkgs_install("autologin") if $o->{autologin};
#any::set_autologin('', $o->{autologin}, $o->{desktop});

$in->exit(0) if $in;