summaryrefslogtreecommitdiffstats
path: root/perl-install/install_interactive.pm
blob: 627305e8de06925005c32301ca33b3f27970a51a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package install_interactive; # $Id$

use diagnostics;
use strict;

use common;
use partition_table qw(:types);
use partition_table::raw;
use detect_devices;
use install_steps;
use devices;
use fsedit;
use log;
use fs;


sub tellAboutProprietaryModules {
    my ($o) = @_;
    my @l = grep { $_ } map { $_->{driver} =~ /^Bad:(.*)/ && $1 } detect_devices::probeall();
    $o->ask_warn('', formatAlaTeX(
N("Some hardware on your computer needs ``proprietary'' drivers to work.
You can find some information about them at: %s", join(", ", @l)))) if @l;
}

#- unit of $mb is mega bytes, min and max are in sectors, this
#- function is used to convert back to sectors count the size of
#- a partition ($mb) given from the interface (on Resize or Create).
#- modified to take into account a true bounding with min and max.
sub from_Mb {
    my ($mb, $min, $max) = @_;
    $mb <= $min >> 11 and return $min;
    $mb >= $max >> 11 and return $max;
    $mb * 2048;
}

sub partition_with_diskdrake {
    my ($o, $all_hds, $nowizard) = @_;
    my $ok; 

    $o->set_help('partition_with_diskdrake');
    do {
	$ok = 1;
	require diskdrake::interactive;
	{
	    local $::expert = $::expert;
	    diskdrake::interactive::main($o, $all_hds, $nowizard);
	}
	if (delete $o->{wizard}) {
	    partitionWizard($o, 'nodiskdrake') or redo;
	    return 1;
	}
	my @fstab = fsedit::get_all_fstab($all_hds);
	
	unless (fsedit::get_root_(\@fstab)) {
	    $ok = 0;
	    $o->ask_okcancel('', N("You must have a root partition.
For this, create a partition (or click on an existing one).
Then choose action ``Mount point'' and set it to `/'"), 1) or return;
	}
	if (!grep { isSwap($_) } @fstab) {
	    $o->ask_warn('', N("You must have a swap partition")), $ok = 0 if !$::expert;
	    $ok &&= $o->ask_okcancel('', N("You don't have a swap partition.\n\nContinue anyway?"));
	}
	if (arch() =~ /ia64/ && !fsedit::has_mntpoint("/boot/efi", $all_hds)) {
	    $o->ask_warn('', N("You must have a FAT partition mounted in /boot/efi"));
	    $ok = '';
	}
    } until $ok;
    1;
}

sub partitionWizardSolutions {
    my ($o, $all_hds) = @_;
    my $hds = $all_hds->{hds};
    my $fstab = [ fsedit::get_all_fstab($all_hds) ];
    my @wizlog;
    my (@solutions, %solutions);

    my $min_linux = 400 << 11;
    my $max_linux = 3000 << 11;
    my $min_swap = 50 << 11;
    my $max_swap = 300 << 11;
    my $min_freewin = 100 << 11;

    # each solution is a [ score, text, function ], where the function retunrs true if succeeded

    my @hds_rw = grep { !$_->{readonly} } @$hds;
    my @hds_can_add = grep { $_->can_raw_add } @hds_rw;
    if (fsedit::free_space(@hds_can_add) > $min_linux) {
	$solutions{free_space} = [ 20, N("Use free space"), sub { fsedit::auto_allocate($all_hds); 1 } ]
    } else { 
	push @wizlog, N("Not enough free space to allocate new partitions") . ": " .
	  (@hds_can_add ? 
	   fsedit::free_space(@hds_can_add) . " < $min_linux" :
	   "no harddrive on which partitions can be added");
    }

    if (my @truefs = grep { isTrueFS($_) } @$fstab) {
	#- value twice the ext2 partitions
	$solutions{existing_part} = [ 6 + @truefs + @$fstab, N("Use existing partitions"), sub { $o->ask_mntpoint_s($fstab) } ]
    } else {
	push @wizlog, N("There is no existing partition to use");
    }

    my @fats = grep { isFat($_) } @$fstab;
    fs::df($_) foreach @fats;
    if (my @ok_forloopback = sort { $b->{free} <=> $a->{free} } grep { $_->{free} > $min_linux + $min_swap + $min_freewin } @fats) {
	$solutions{loopback} = 
	  [ -10 - @fats, N("Use the Windows partition for loopback"), 
	    sub { 
		my ($s_root, $s_swap);
		my $part = $o->ask_from_listf('', N("Which partition do you want to use for Linux4Win?"), \&partition_table::description, \@ok_forloopback) or return;
		$max_swap = $min_swap + 1 if $part->{free} - $max_swap < $min_linux;
		$o->ask_from('', N("Choose the sizes"), [ 
		   { label => N("Root partition size in MB: "), val => \$s_root, min => $min_linux >> 11, max => min($part->{free} - $max_swap, $max_linux) >> 11, type => 'range' },
		   { label => N("Swap partition size in MB: "), val => \$s_swap, min => $min_swap >> 11,  max => $max_swap >> 11, type => 'range' },
		]) or return;
		push @{$part->{loopback}}, 
		  { type =>0x483, loopback_file => '/lnx4win/linuxsys.img', mntpoint => '/',    size => $s_root << 11, loopback_device => $part, notFormatted => 1 },
		  { type => 0x82, loopback_file => '/lnx4win/swapfile',     mntpoint => 'swap', size => $s_swap << 11, loopback_device => $part, notFormatted => 1 };
		fsedit::recompute_loopbacks($all_hds);
		1;
	    } ];
	my @ok_for_resize_fat = grep { !fsedit::part2hd($_, $all_hds)->{readonly} } @ok_forloopback;
	$solutions{resize_fat} = 
	  [ 6 - @fats, N("Use the free space on the Windows partition"),
	    sub {
		$o->set_help('resizeFATChoose');
		my $part = $o->ask_from_listf('', N("Which partition do you want to resize?"), \&partition_table::description, \@ok_for_resize_fat) or return;
		$o->set_help('resizeFATWait');
		my $w = $o->wait_message(N("Resizing"), N("Resizing Windows partition"));
		require resize_fat::main;
		my $resize_fat = eval { resize_fat::main->new($part->{device}, devices::make($part->{device})) };
		$@ and die N("The FAT resizer is unable to handle your partition, 
the following error occured: %s", $@);
		my $min_win = $resize_fat->min_size;
		$part->{size} > $min_linux + $min_swap + $min_freewin + $min_win or die N("Your Windows partition is too fragmented. Please reboot your computer under Windows, run the ``defrag'' utility, then restart the Mandrake Linux installation.");
		$o->ask_okcancel('', N("WARNING!

DrakX will now resize your Windows partition. Be careful:
this operation is dangerous. If you have not already done
so, you should first exit the installation, run scandisk
under Windows (and optionally run defrag), then restart the
installation. You should also backup your data.
When sure, press Ok.")) or return;

		my $mb_size = $part->{size} >> 11;
		$o->ask_from('', N("Which size do you want to keep for Windows on"), [
                   { label => N("partition %s", partition_table::description($part)), val => \$mb_size, min => $min_win >> 11, max => ($part->{size} - $min_linux - $min_swap) >> 11, type => 'range' },
                ]) or return;

		my $size = from_Mb($mb_size, $min_win, $part->{size});

		local *log::l = sub { $w->set(join(' ', @_)) };
		eval { $resize_fat->resize($size) };
		$@ and die N("FAT resizing failed: %s", $@);

		$part->{size} = $size;
		$part->{isFormatted} = 1;
		
		my ($hd) = fsedit::part2hd($part, $all_hds);
		$hd->{isDirty} = $hd->{needKernelReread} = 1;
		$hd->adjustEnd($part);
		partition_table::adjust_local_extended($hd, $part);
		partition_table::adjust_main_extended($hd);

		fsedit::auto_allocate($all_hds);
		1;
	    } ] if @ok_for_resize_fat;
    } else {
	push @wizlog, N("There is no FAT partition to resize or to use as loopback (or not enough space left)") .
	  @fats ? "\nFAT partitions:" . join('', map { "\n  $_->{device} $_->{free} (" . ($min_linux + $min_swap + $min_freewin) . ")" } @fats) : '';
    }

    if (@$fstab && @hds_rw) {
	$solutions{wipe_drive} =
	  [ 10, fsedit::is_one_big_fat($hds) ? N("Remove Windows(TM)") : N("Erase entire disk"), 
	    sub {
		$o->set_help('takeOverHdChoose');
		my $hd = $o->ask_from_listf('', N("You have more than one hard drive, which one do you install linux on?"),
					    \&partition_table::description, \@hds_rw) or return;
		$o->set_help('takeOverHdConfirm');
		$o->ask_okcancel('', N("ALL existing partitions and their data will be lost on drive %s", partition_table::description($hd))) or return;
		partition_table::raw::zero_MBR($hd);
		fsedit::auto_allocate($all_hds);
		1;
	    } ];
    }

    if (@hds_rw) {
	$solutions{diskdrake} = [ 0, N("Custom disk partitioning"), sub { partition_with_diskdrake($o, $all_hds, 'nowizard') } ];
    }

    $solutions{fdisk} =
      [ -10, N("Use fdisk"), sub { 
	    $o->enter_console;
	    foreach (@$hds) {
		print "\n" x 10, N("You can now partition %s.
When you are done, don't forget to save using `w'", partition_table::description($_));
		print "\n\n";
		my $pid = 0;
		if (arch() =~ /ppc/) {
			$pid = fork() or exec "pdisk", devices::make($_->{device});
		} else {
			$pid = fork() or exec "fdisk", devices::make($_->{device});
		}			
		waitpid($pid, 0);
	    }
	    $o->leave_console;
	    0;
	} ] if $o->{partitioning}{fdisk};

    log::l("partitioning wizard log:\n", (map { ">>wizlog>>$_\n" } @wizlog));
    %solutions;
}

sub partitionWizard {
    my ($o, $nodiskdrake) = @_;

    $o->set_help('doPartitionDisks');

    my %solutions = partitionWizardSolutions($o, $o->{all_hds});
    if ($o->{lnx4win}) {
	if ($solutions{loopback}) {
	    %solutions = (loopback => $solutions{loopback});
	} else {
	    $o->ask_warn('', N("You don't have enough free space on your Windows partition")) if grep { isFat($_) } fsedit::get_all_fstab($o->{all_hds});
	}
    }

    delete $solutions{diskdrake} if $nodiskdrake;

    my @solutions = sort { $b->[0] <=> $a->[0] } values %solutions;

    my $level = $::expert ? -9999 : 0;
    my @sol = grep { $_->[0] >= $level } @solutions;

    log::l(''  . "solutions found: " . join('', map { $_->[1] } @sol) . 
	   " (all solutions found: " . join('', map { $_->[1] } @solutions) . ")");

    @solutions = @sol if @sol > 1;
    log::l("solutions: ", int @solutions);
    @solutions or $o->ask_warn('', N("I can't find any room for installing")), die 'already displayed';

    log::l('HERE: ', join(',', map { $_->[1] } @solutions));
    if (my $sol = $o->ask_from_listf('', N("The DrakX Partitioning wizard found the following solutions:"), sub { $_[0][1] }, \@solutions)) {
	log::l("partitionWizard calling solution $sol->[1]");
	my $ok = eval { $sol->[2]->() };
	die if $@ =~ /setstep/;
	$@ and $o->ask_warn('', N("Partitioning failed: %s", $@));
	$ok or goto &partitionWizard;
    } else {
	$nodiskdrake ? return : die "setstep setupSCSI\n";
    }
    1;
}

sub upNetwork {
    my ($o, $pppAvoided) = @_;
    my $w = $o->wait_message('', N("Bringing up the network"));
    install_steps::upNetwork($o, $pppAvoided);
}
sub downNetwork {
    my ($o, $pppOnly) = @_;
    my $w = $o->wait_message('', N("Bringing down the network"));
    install_steps::downNetwork($o, $pppOnly);
}



1;
span></li><li><span class="file section"><a href="draksambashare.html#d4e2664">Preparazione</a></span></li><li><span class="file section"><a href="draksambashare.html#d4e2669">Procedura guidata - server autonomo</a></span></li><li><span class="file section"><a href="draksambashare.html#d4e2712">Wizard - Primary domain controller</a></span></li><li><span class="file section"><a href="draksambashare.html#d4e2722">Dichiarare una directory da salvare</a></span></li><li><span class="file section"><a href="draksambashare.html#d4e2735">Voci del menù</a></span></li><li><span class="file section"><a href="draksambashare.html#d4e2751">Stampanti condivise</a></span></li><li><span class="file section"><a href="draksambashare.html#d4e2758">Utilizzatori di Samba</a></span></li></ul></li><li><span class="file section"><a href="diskdrake--nfs.html">Accedi a dischi e cartelle in condivisione NFS</a></span><ul><li><span class="file section"><a href="diskdrake--nfs.html#d4e2775">Introduzione</a></span></li><li><span class="file section"><a href="diskdrake--nfs.html#d4e2781">Procedura</a></span></li></ul></li><li><span class="file section"><a href="draknfs.html">Condividi dischi e cartelle tramite NFS</a></span><ul><li><span class="file section"><a href="draknfs.html#d4e2816">Prerequisiti</a></span></li><li><span class="file section"><a href="draknfs.html#d4e2825">Finestra principale</a></span></li><li><span class="file section"><a href="draknfs.html#d4e2829">Modifica voce</a></span><ul><li><span class="file section"><a href="draknfs.html#d4e2836">Directory NFS</a></span></li><li><span class="file section"><a href="draknfs.html#d4e2840">Accesso host</a></span></li><li><span class="file section"><a href="draknfs.html#d4e2852">Mappatura ID utente</a></span></li><li><span class="file section"><a href="draknfs.html#d4e2862">Opzioni avanzate</a></span></li></ul></li><li><span class="file section"><a href="draknfs.html#d4e2872">Voci del menù</a></span><ul><li><span class="file section"><a href="draknfs.html#d4e2878">File|Write conf</a></span></li><li><span class="file section"><a href="draknfs.html#d4e2881">NFS Server|Restart</a></span></li><li><span class="file section"><a href="draknfs.html#d4e2884">NFS Server|Reload</a></span></li></ul></li></ul></li><li><span class="file section"><a href="diskdrake--dav.html">Accedi ai dispositivi e alle directory condivisi tramite WebDAV</a></span><ul><li><span class="file section"><a href="diskdrake--dav.html#d4e2899">Introduzione</a></span></li><li><span class="file section"><a href="diskdrake--dav.html#d4e2903">Crea una nuova voce</a></span></li></ul></li></ul></li><li><span class="file section"><a href="mcc-localdisks.html">Dischi locali</a></span><ul><li><span class="file section"><a href="drakdisk.html">Gestisci le partizioni del disco</a></span></li><li><span class="file section"><a href="diskdrake--removable.html">Masterizzatore di CD/DVD</a></span><ul><li><span class="file section"><a href="diskdrake--removable.html#d4e2993">Punto di mount</a></span></li><li><span class="file section"><a href="diskdrake--removable.html#d4e2997">Opzioni</a></span><ul><li><span class="file section"><a href="diskdrake--removable.html#d4e3002">user/nouser</a></span></li></ul></li></ul></li><li><span class="file section"><a href="diskdrake--fileshare.html">Condividi le tue partizioni del disco fisso</a></span></li></ul></li><li><span class="file section"><a href="mcc-security.html">Sicurezza</a></span><ul><li><span class="file section"><a href="msecgui.html">MSEC: Sicurezza ed controllo del sistema</a></span><ul><li><span class="file section"><a href="msecgui.html#d4e3069">Presentazione</a></span></li><li><span class="file section"><a href="msecgui.html#d4e3081">Overview tab</a></span></li><li><span class="file section"><a href="msecgui.html#d4e3099">Tab impostazioni di sicurezza</a></span><ul><li><span class="file section"><a href="msecgui.html#d4e3106">Tab sicurezza di base</a></span></li><li><span class="file section"><a href="msecgui.html#d4e3148">Tab sicurezza di sistema</a></span></li><li><span class="file section"><a href="msecgui.html#d4e3165">Sicurezza della rete</a></span></li><li><span class="file section"><a href="msecgui.html#d4e3171">Tab controlli periodici</a></span></li><li><span class="file section"><a href="msecgui.html#d4e3179">Scheda delle eccezioni</a></span></li><li><span class="file section"><a href="msecgui.html#d4e3195">Permessi</a></span></li></ul></li></ul></li><li><span class="file section"><a href="drakfirewall.html">Configura il tuo firewall personale</a></span></li><li><span class="file section"><a href="draksec.html">Configura autenticazione per strumenti Mageia</a></span></li><li><span class="file section"><a href="drakinvictus.html">Impostazioni avanzate per le interfacce di rete ed il firewall</a></span></li><li><span class="file section"><a href="drakguard.html">Filtri per la famiglia</a></span><ul><li><span class="file section"><a href="drakguard.html#d4e3325">Presentazione</a></span></li><li><span class="file section"><a href="drakguard.html#d4e3335">Configurando il Parental control</a></span><ul><li><span class="file section"><a href="drakguard.html#d4e3352">Blacklist/Whitelist tab</a></span></li><li><span class="file section"><a href="drakguard.html#d4e3356">Block Programs Tab</a></span></li></ul></li></ul></li></ul></li><li><span class="file section"><a href="mcc-boot.html">Avvio</a></span><ul><li><span class="file section"><a href="drakboot.html">Imposta l'accesso automatico</a></span></li><li><span class="file section"><a href="drakboot--boot.html">Configura l'avvio del sistema</a></span></li><li><span class="file section"><a href="drakedm.html">Imposta il gestore grafico delle sessioni</a></span></li></ul></li><li><span class="file section"><a href="otherMageiaTools.html">Altri strumenti di Mageia</a></span><ul><li><span class="file section"><a href="drakbug.html">Strumento per la segnalazione di bug di Mageia</a></span></li><li><span class="file section"><a href="drakbug_report.html">Collect Logs and System Information for Bug Reports</a></span></li><li><span class="file section"><a href="lsnetdrake.html">Display Available NFS And SMB Shares</a></span></li><li><span class="file section"><a href="lspcidrake.html">Mostra le informazioni riguardo PCI, USB e PCMCIA</a></span></li></ul></li></ul></div></div><div id="searchDiv"><div id="search"><form onsubmit="Verifie(ditaSearch_Form);return false" name="ditaSearch_Form" class="searchForm"><fieldset class="searchFieldSet"><legend>Ricerca</legend><center><input id="textToSearch" name="textToSearch" type="text" class="searchText"/> &nbsp; <input onclick="Verifie(ditaSearch_Form)" type="button" class="searchButton" value="Go" id="doSearch"/></center></fieldset></form></div><div id="searchResults"><center/></div></div></div></div></div></body></html>