#!/usr/bin/perl

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

use standalone;     #- warning, standalone must be loaded very first, for 'explanations'

use common;
use interactive;
use any;
use bootloader;
use detect_devices;
use fsedit;
use fs;
use c;

my $in = 'interactive'->vnew('su', 'bootloader');

$::lilo_choice = \&lilo_choice;

if ($in->isa('interactive::gtk')) {
    require 'bootlook.pm';
} else {
    lilo_choice();
}

!$::isEmbedded and $in->exit(0);
kill('USR1', $::CCPID);
goto ask;

sub lilo_choice
{
    my $bootloader = bootloader::read(); 
    local ($_) = `detectloader`;
    $bootloader->{methods} = { lilo => 1, grub => !!/grub/i, if_(arch() =~ /ppc/, yaboot => 1) };
    
    my ($all_hds) = fsedit::get_hds();
    my $fstab = [ fsedit::get_all_fstab($all_hds) ];
    fs::merge_info_from_fstab($fstab);
 
    $::expert=1;
    
  ask:
    local $::isEmbedded = 0;
    any::setupBootloader($in, $bootloader, $all_hds, $fstab, $ENV{SECURE_LEVEL}) or return;
    eval { bootloader::install($bootloader, $fstab, $all_hds->{hds}) };

    my $loader = arch() =~ /ppc/ ? "Yaboot" : "LILO";
    if ($@) {
	$in->ask_warn('', 
		      [ N("Installation of %s failed. The following error occured:", $loader),
			grep { !/^Warning:/ } cat_("/tmp/.error") ]);
	unlink "/tmp/.error";
	goto ask;
    }
}