#!/usr/bin/perl

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

use common;
use interactive;
use any;
use authentication;
use network::network;
use network::netconnect;
use security::level;

$ENV{SHARE_PATH} ||= "/usr/share";
my $authentication = authentication::get();
my $security = security::level::get();
my $net = {};
network::network::read_net_conf($net);

$::isWizard = 1;
my $in = 'interactive'->vnew;

sub ask_language() {
    require lang;
    my $locale = lang::read();
    any::selectLanguage_and_more_standalone($in, $locale);
    lang::write($locale);
    lang::set($locale);
    Gtk2->set_locale;
}

sub ask_network() {
    my $modules_conf = modules::any_conf->read;
    require network::netconnect;
    network::netconnect::real_main($net, $in, $modules_conf);
}

sub ask_authentication() {
    my $meta_class = { getVarsFromSh("/etc/sysconfig/system") }->{META_CLASS};

    my $superuser = {};
    authentication::ask_root_password_and_authentication($in, $net, $superuser, $authentication, $meta_class, $security);
    authentication::set_root_passwd($superuser, $authentication);

    eval { 
	authentication::set($in, $net, $authentication);
	network::network::write_network_conf($net);
    };
    if (my $err = $@) {
	$in->ask_warn(N("Error"), formatError($err));
	goto &ask_authentication;
    }
}

sub ask_users() {
    my $users = []; 
    any::ask_users($in, $users, $security, []);
    any::add_users($users, $authentication);
}

sub call {
    my ($f_name) = @_;
    log::l("calling $f_name");
    my $f = $::{$f_name} or internal_error "bad function $f_name";
    eval { $f->() };
    log::l("$f_name failed: $@") if $@;
}

call('ask_language');
call('ask_network');
$::WizardWindow->destroy; undef $::WizardWindow;
$::Wizard_pix_up = 'redhat-config-users';
call('ask_authentication');
call('ask_users');
setVarsInSh('/etc/sysconfig/finish-install', { FINISH_INSTALL => 'no' });

$in->exit(0);