summaryrefslogtreecommitdiffstats
path: root/perl-install/install_interactive.pm
blob: 3b8e350e4f847f7a85c0bb52e0ef63477aa1fccf (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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
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 install_any;
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; 

    do {
	$ok = 1;
	my $do_force_reload = sub {
	    $o->{all_hds} = fsedit::empty_all_hds();
	    install_any::getHds($o, $o);
	    $all_hds = $o->{all_hds};
	    $o->{all_hds};
	};
	require diskdrake::interactive;
	{
	    local $::expert = $::expert;
	    diskdrake::interactive::main($o, $all_hds, $nowizard, $do_force_reload, $o->interactive_help_sub_display_id('partition_with_diskdrake'));
	}
	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 (!any { isSwap($_) } @fstab) {
	    $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);

    my $min_linux = 400 << 11;
    my $max_linux = 2000 << 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;
	    } ];
    } else {
	push @wizlog, N("There is no FAT partition 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 (my @ok_for_resize_fat = grep { isFat_or_NTFS($_) && !fsedit::part2hd($_, $all_hds)->{readonly} } @$fstab) {
	$solutions{resize_fat} = 
	  [ 6 - @ok_for_resize_fat, N("Use the free space on the Windows partition"),
	    sub {
		my $part = $o->ask_from_listf_raw({ messages => N("Which partition do you want to resize?"),
						    interactive_help_id => 'resizeFATChoose',
						  }, \&partition_table::description, \@ok_for_resize_fat) or return;
		my $hd = fsedit::part2hd($part, $all_hds);
		my $resize_fat = eval {
		    my $pkg = isFat($part) ? do { 
			require resize_fat::main;
			'resize_fat::main';
		    } : do {
			require diskdrake::resize_ntfs;
			'diskdrake::resize_ntfs';
		    };
		    $pkg->new($part->{device}, devices::make($part->{device}));
		};
		$@ and die \N("The FAT resizer is unable to handle your partition, 
the following error occured: %s", formatError($@));
		my $min_win = do {
		    my $_w = $o->wait_message(N("Resizing"), N("Computing the size of the Windows partition"));
		    $resize_fat->min_size;
		};
		#- make sure that even after normalizing the size to cylinder boundaries, the minimun will be saved,
		#- this save at least a cylinder (less than 8Mb).
		$min_win += partition_table::raw::cylinder_size($hd);

		$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('', formatAlaTeX(N("WARNING!

DrakX will now resize your Windows partition. Be careful: this
operation is dangerous. If you have not already done so, you
first need to exit the installation, run \"chkdsk c:\" from a
Command Prompt under Windows (beware, running graphical program
\"scandisk\" is not enough, be sure to use \"chkdsk\" in a
Command Prompt!), 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 $oldsize = $part->{size};
		$part->{size} = from_Mb($mb_size, $min_win, $part->{size});

		$hd->adjustEnd($part);

		eval { 
		    my $_w = $o->wait_message(N("Resizing"), N("Resizing Windows partition"));
		    $resize_fat->resize($part->{size});
		};
		if (my $err = $@) {
		    $part->{size} = $oldsize;
		    die \N("FAT resizing failed: %s", formatError($err));
		}

		$o->ask_warn('', N("To ensure data integrity after resizing the partition(s), 
filesystem checks will be run on your next boot into Windows(TM)")) if !isFat($part);

		$part->{isFormatted} = 1;
		$hd->{isDirty} = $hd->{needKernelReread} = 1;
		partition_table::adjust_local_extended($hd, $part);
		partition_table::adjust_main_extended($hd);

		fsedit::auto_allocate($all_hds);
		1;
	    } ];
    } else {
	push @wizlog, N("There is no FAT partition to resize (or not enough space left)");
    }

    if (@$fstab && @hds_rw) {
	$solutions{wipe_drive} =
	  [ 10, fsedit::is_one_big_fat_or_NT($hds) ? N("Remove Windows(TM)") : N("Erase entire disk"), 
	    sub {
		my $hd = $o->ask_from_listf_raw({ messages => N("You have more than one hard drive, which one do you install linux on?"),
						  interactive_help_id => 'takeOverHdChoose',
						},
						\&partition_table::description, \@hds_rw) or return;
		$o->ask_okcancel_({ messages => N("ALL existing partitions and their data will be lost on drive %s", partition_table::description($hd)),
				    interactive_help_id => 'takeOverHdConfirm' }) 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, $b_nodiskdrake) = @_;

    my %solutions = partitionWizardSolutions($o, $o->{all_hds});

    delete $solutions{diskdrake} if $b_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));
    my $sol;
    $o->ask_from_({ messages => N("The DrakX Partitioning wizard found the following solutions:"),
		    interactive_help_id => 'doPartitionDisks',
		  }, 
		  [ { val => \$sol, list => \@solutions, format => sub { $_[0][1] }, type => 'list' } ]);
    log::l("partitionWizard calling solution $sol->[1]");
    my $ok = eval { $sol->[2]->() };
    $@ and $o->ask_warn('', N("Partitioning failed: %s", formatError($@)));
    $ok or goto &partitionWizard;
    1;
}

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



1;
t">->{fstab}, undef); } #------------------------------------------------------------------------------ sub setPackages { my ($o) = @_; install::any::setPackages($o); } sub ask_deselect_media__copy_on_disk { my (undef, $_hdlists, $_copy_rpms_on_disk) = @_; 0; } sub ask_change_cd { my (undef, $phys_m, $_o_rel_file) = @_; log::l("change to medium " . install::media::phys_medium_to_string($phys_m) . " refused (it can't be done automatically)"); 0; } sub selectSupplMedia { '' } sub choosePackages { my ($o) = @_; #- now for upgrade, package that must be upgraded are #- selected first, after is used the same scheme as install. #- make sure we kept some space left for available else the system may #- not be able to start my $available = install::any::getAvailableSpace($o); my $availableCorrected = install::pkgs::invCorrectSize($available / sqr(1024)) * sqr(1024); log::l(sprintf "available size %s (corrected %s)", formatXiB($available), formatXiB($availableCorrected)); add2hash_($o, { compssListLevel => 5 }) if !$::auto_install; #- !! destroying user selection of packages (they may have done individual selection before) exists $o->{compssListLevel} and install::pkgs::setSelectedFromCompssList($o->{packages}, $o->{rpmsrate_flags_chosen}, $o->{compssListLevel}, $availableCorrected); $availableCorrected; } sub upgrading_redhat() { #- remove weird config files that bother Xconfig::* too much unlink "$::prefix/etc/X11/XF86Config"; unlink "$::prefix/etc/X11/XF86Config-4"; sub prefering_mdk { my ($lpkg, $rpkg_ver, $c) = @_; my $lpkg_ver = $lpkg->version . '-' . $lpkg->release; log::l($lpkg->name . ' ' . ': prefering ' . ($c == 1 ? "$lpkg_ver over $rpkg_ver" : "$rpkg_ver over $lpkg_ver")); } my $old_compare_pkg = \&URPM::Package::compare_pkg; undef *URPM::Package::compare_pkg; *URPM::Package::compare_pkg = sub { my ($lpkg, $rpkg) = @_; my $c = ($lpkg->release =~ /mdk$/ ? 1 : 0) - ($rpkg->release =~ /mdk$/ ? 1 : 0); if ($c) { prefering_mdk($lpkg, $rpkg->version . '-' . $rpkg->release, $c); $c; } else { &$old_compare_pkg; } }; my $old_compare = \&URPM::Package::compare; undef *URPM::Package::compare; *URPM::Package::compare = sub { my ($lpkg, $rpkg_ver) = @_; my $c = ($lpkg->release =~ /mdk$/ ? 1 : 0) - ($rpkg_ver =~ /mdk$/ ? 1 : 0); if ($c) { prefering_mdk($lpkg, $rpkg_ver, $c); return $c; } &$old_compare; }; } sub beforeInstallPackages { my ($o) = @_; read_bootloader_config($o); if ($o->{isUpgrade}) { $o->{modules_conf}->merge_into(modules::any_conf->read); } #- save these files in case of upgrade failure. if ($o->{isUpgrade}) { foreach (@filesToSaveForUpgrade) { unlink "$::prefix/$_.mdkgisave"; if (-e "$::prefix/$_") { eval { cp_af("$::prefix/$_", "$::prefix/$_.mdkgisave") }; } } foreach (@filesNewerToUseAfterUpgrade) { unlink "$::prefix/$_.rpmnew"; } } #- mainly for upgrading redhat packages, but it can help other my @should_not_be_dirs = qw(/usr/share/locale/zh_TW/LC_TIME /usr/include/GL); my @should_be_dirs = qw(/etc/X11/xkb); my @to_remove = ( (grep { !-l $_ && -d $_ } map { "$::prefix$_" } @should_not_be_dirs), (grep { -l $_ || !-d $_ && -e $_ } map { "$::prefix$_" } @should_be_dirs), ); rm_rf(@to_remove); if ($o->{isUpgrade} eq 'redhat') { upgrading_redhat(); } if ($o->{isUpgrade} =~ /redhat|conectiva/) { #- to ensure supermount is removed (???) fs::mount_options::set_all_default($o->{all_hds}, %$o, lang::fs_options($o->{locale})); } #- some packages need such files for proper installation. install::any::write_fstab($o); require network::network; network::network::add2hosts("localhost", "127.0.0.1"); #- resolv.conf will be modified at boot time #- the following will ensure we have a working DNS during install if (-e "/etc/resolv.conf" && ! -e "$::prefix/etc/resolv.conf") { cp_af("/etc/resolv.conf", "$::prefix/etc"); } log::l("setting excludedocs to $o->{excludedocs}"); substInFile { s/%_excludedocs.*//; $_ .= "%_excludedocs yes\n" if eof && $o->{excludedocs} } "$::prefix/etc/rpm/macros"; #- add oem theme if the files exists. mkdir_p("$::prefix/usr/share"); install::media::getAndSaveFile_($o->{stage2_phys_medium}, "install/oem-theme.rpm", "$::prefix/usr/share/oem-theme.rpm"); system("sh", "-c", $o->{preInstallNonRooted}) if $o->{preInstallNonRooted}; } #- returns number of packages installed, 0 if none were selected. sub pkg_install { my ($o, @l) = @_; log::l("selecting packages " . join(" ", @l)); install::pkgs::select_by_package_names($o->{packages}, \@l); my @toInstall = install::pkgs::packagesToInstall($o->{packages}); if (@toInstall) { log::l("installing packages"); $o->installPackages; } else { log::l("all packages selected are already installed, nothing to do"); delete $o->{packages}{rpmdb}; #- make sure rpmdb is closed 0; } } sub installCallback { # my (undef, $msg, @para) = @_; # log::l("$msg: " . join(',', @para)); } sub installPackages { #- complete REWORK, TODO and TOCHECK! my ($o) = @_; my $packages = $o->{packages}; install::pkgs::remove_marked_ask_remove($packages, \&installCallback); #- small transaction will be built based on this selection and depslist. my @toInstall = install::pkgs::packagesToInstall($packages); my $time = time(); { local $ENV{DURING_INSTALL} = 1; local $ENV{TMPDIR} = '/tmp'; local $ENV{TMP} = '/tmp'; install::pkgs::install($o->{isUpgrade}, \@toInstall, $packages, \&installCallback); } any::writeandclean_ldsoconf($::prefix); run_program::rooted_or_die($::prefix, 'ldconfig'); log::l("Install took: ", formatTimeRaw(time() - $time)); install::media::log_sizes(); scalar(@toInstall); #- return number of packages installed. } sub afterInstallPackages($) { my ($o) = @_; read_bootloader_config($o) if $o->{isUpgrade} && is_empty_hash_ref($o->{bootloader}); die N("Some important packages did not get installed properly. Either your cdrom drive or your cdrom is defective. Check the cdrom on an installed computer using \"rpm -qpl media/main/*.rpm\" ") if any { m|read failed: Input/output error| } cat_("$::prefix/root/drakx/install.log"); if (arch() !~ /^sparc/) { #- TODO restore it as may be needed for sparc -x "$::prefix/usr/bin/dumpkeys" or $::testing or die "Some important packages did not get installed properly. Please switch to console 2 (using ctrl-alt-f2) and look at the log file /tmp/ddebug.log Consoles 1,3,4,7 may also contain interesting information"; } #- why not? cuz weather is nice today :-) [pixel] common::sync(); common::sync(); #- generate /etc/lvmtab needed for rc.sysinit run_program::rooted($::prefix, 'lvm2', 'vgscan') if -e '/etc/lvmtab'; require harddrake::autoconf; #- configure PCMCIA services if needed. harddrake::autoconf::pcmcia($o->{pcmcia}); #- configure CPU frequency modules harddrake::autoconf::cpufreq(); #- for mandrake_firstime touch "$::prefix/var/lock/TMP_1ST"; fs::any::set_cdrom_symlink_udev_rule($o->{all_hds}{raw_hds}); any::config_mtools($::prefix); #- make sure wins is disabled in /etc/nsswitch.conf #- else if eth0 is not existing, glibc segfaults. substInFile { s/\s*wins// if /^\s*hosts\s*:/ } "$::prefix/etc/nsswitch.conf"; #- make sure some services have been enabled (or a catastrophic restart will occur). #- these are normally base package post install scripts or important services to start. run_program::rooted($::prefix, "chkconfig", "--add", $_) foreach qw(netfs network rawdevices sound kheader keytable syslog crond portmap); if ($o->{mouse}{device} =~ /ttyS/) { log::l("disabling gpm for serial mice (does not get along nicely with X)"); run_program::rooted($::prefix, "chkconfig", "--del", "gpm"); } #- install urpmi before as rpmdb will be opened, this will cause problem with update-menus. $o->install_urpmi; if ($o->{pcmcia}) { substInFile { s/.*(TaskBarShowAPMStatus).*/$1=1/ } "$::prefix/usr/lib/X11/icewm/preferences"; eval { cp_af("$::prefix/usr/share/applnk/System/kapm.kdelnk", "$::prefix/etc/skel/Desktop/Autostart/kapm.kdelnk") }; } if ($o->{brltty}) { output("$::prefix/etc/brltty.conf", <<EOF); braille-driver $o->{brltty}{driver} braille-device $o->{brltty}{device} text-table $o->{brltty}{table} EOF } install::any::disable_user_view() if $o->{security} >= 3 || $o->{authentication}{NIS}; run_program::rooted($::prefix, "kdeDesktopCleanup"); #- move some file after an upgrade that may be seriously annoying. #- and rename saved files to .mdkgiorig. if ($o->{isUpgrade}) { my $pkg = install::pkgs::packageByName($o->{packages}, 'rpm'); $pkg && ($pkg->flag_selected || $pkg->flag_installed) && $pkg->compare(">= 4.0") and install::pkgs::cleanOldRpmDb(); log::l("moving previous desktop files that have been updated to Trash of each user"); install::any::kdemove_desktop_file($::prefix); foreach (@filesToSaveForUpgrade) { renamef("$::prefix/$_.mdkgisave", "$::prefix/$_.mdkgiorig") if -e "$::prefix$_.mdkgisave"; } foreach (@filesNewerToUseAfterUpgrade) { if (-e "$::prefix/$_.rpmnew" && -e "$::prefix/$_") { renamef("$::prefix/$_", "$::prefix/$_.mdkgiorig"); renamef("$::prefix/$_.rpmnew", "$::prefix/$_"); } } } renamef(install::pkgs::removed_pkgs_to_upgrade_file(), install::pkgs::removed_pkgs_to_upgrade_file() . '.done'); unlink(glob("$::prefix/root/drakx/*.upgrading")); if ($o->{upgrade_by_removing_pkgs_matching}) { if (cat_("$::prefix/etc/inittab.rpmsave") =~ /^id:5:initdefault:\s*$/m) { $o->{X}{xdm} = 1; require Xconfig::various; Xconfig::various::runlevel(5); } } any::fix_broken_alternatives($o->{isUpgrade} eq 'redhat'); #- update theme directly from a package (simplest). if (-s "$::prefix/usr/share/oem-theme.rpm") { run_program::rooted($::prefix, "rpm", "-U", "/usr/share/oem-theme.rpm"); unlink "/usr/share/oem-theme.rpm"; } #- call update-menus at the end of package installation push @{$o->{waitpids}}, run_program::raw({ root => $::prefix, detach => 1 }, "update-menus", "-n"); $o->install_hardware_packages; if ($o->{updatemodules}) { $o->updatemodules($ENV{THIRDPARTY_DEVICE}, $ENV{THIRDPARTY_DIR}); } } sub install_urpmi { my ($o) = @_; my $pkg = install::pkgs::packageByName($o->{packages}, 'urpmi'); if ($pkg && ($pkg->flag_selected || $pkg->flag_installed) #- this is a workaround. if many urpmi packages are found in the #- provides of all media, packages_providing() might return the wrong #- one. This probably needs to be fixed in URPM || run_program::rooted_get_stdout($::prefix, '/bin/rpm', '-q', 'urpmi') =~ /urpmi/ ) { install::media::install_urpmi($o->{method}, $o->{packages}); install::pkgs::saveCompssUsers($o->{packages}, $o->{compssUsers}); } else { log::l("skipping install_urpmi, urpmi not installed"); } } sub install_hardware_packages { my ($o) = @_; if ($o->{match_all_hardware}) { my @l; require Xconfig::card; require Xconfig::proprietary; my $cards = Xconfig::card::readCardsDB("$ENV{SHARE_PATH}/ldetect-lst/Cards+"); my @drivers = grep { $_ } uniq(map { $_->{Driver2} } values %$cards); push @l, map { Xconfig::proprietary::pkgs_for_Driver2($_, $o->do_pkgs) } @drivers; require network::connection; require network::thirdparty; foreach my $type (network::connection->get_types) { $type->can('get_thirdparty_settings') or next; foreach my $settings (@{$type->get_thirdparty_settings || []}) { foreach (@network::thirdparty::thirdparty_types) { my @packages = network::thirdparty::get_required_packages($_, $settings); push @l, network::thirdparty::get_available_packages($_, $o, @packages); } } } $o->do_pkgs->install(@l) if @l; } } sub updatemodules { my ($_o, $dev, $rel_dir) = @_; return if $::testing; $dev = devices::make($dev) or log::l("updatemodules: bad device $dev"), return; my $mount_dir = '/updatemodules'; find { eval { fs::mount::mount($dev, $mount_dir, $_, 0); 1 }; } 'ext2', 'vfat' or log::l("updatemodules: can't mount $dev"), return; my $dir = "$mount_dir$rel_dir"; foreach my $kernel_version (all("$::prefix/lib/modules")) { log::l("examining updated modules for kernel $kernel_version"); -d "$dir/$kernel_version" or next; log::l("found updatable modules"); run_program::run("cd $dir/$kernel_version ; find -type f | cpio -pdu $::prefix/lib/modules/$kernel_version"); run_program::rooted($::prefix, 'depmod', '-a', '-F', "/boot/System.map-$kernel_version", $kernel_version); } my $category; foreach (cat_("$dir/to_load")) { chomp; if (/^#/) { ($category) = $1 if /\[list_modules: (.*?)\]/; } elsif ($category) { log::l("adding $_ to $category\n"); my $r = \%list_modules::l; $r = $r->{$_} foreach split('/', $category); push @$r, $_; $category = ''; } } fs::mount::umount($mount_dir); } #------------------------------------------------------------------------------ sub selectMouse($) { my ($_o) = @_; } #------------------------------------------------------------------------------ sub configureNetwork { my ($o) = @_; require network::network; network::network::configure_network($o->{net}, $o, $o->{modules_conf}); configure_firewall($o) if !$o->{isUpgrade}; #- only a http proxy can be used by stage1 #- the method is http even for ftp connections through a http proxy #- use this http proxy for both http and ftp connections if ($o->{method} eq "http" && $ENV{PROXY}) { my $proxy = "http://$ENV{PROXY}" . ($ENV{PROXYPORT} && ":$ENV{PROXYPORT}"); add2hash($o->{miscellaneous} ||= {}, { http_proxy => $proxy, ftp_proxy => $proxy, }); network::network::proxy_configure($o->{miscellaneous}); } } sub configure_firewall { my ($o) = @_; #- set up a firewall if ports have been specified or if the security level is high enough $o->{firewall_ports} ||= '' if $o->{security} >= 3 && !exists $o->{firewall_ports}; if (defined $o->{firewall_ports}) { require network::drakfirewall; $o->{firewall_ports} ||= ''; #- don't open any port by default network::drakfirewall::set_ports($o->do_pkgs, 0, $o->{firewall_ports}, 'log_net_drop'); network::drakfirewall::set_ifw($o->do_pkgs, 1, [ 'psd' ], ''); } } #------------------------------------------------------------------------------ sub installUpdates { my ($o) = @_; my $u = $o->{updates} or return; $u->{url} or return; upNetwork($o); require mirror; my $phys_medium = install::media::url2mounted_phys_medium($o, $u->{url} . '/media/main/updates'); my $update_medium = { name => "Updates for Mandriva Linux " . $o->{product_id}{version}, update => 1 }; install::media::get_standalone_medium($o, $phys_medium, $o->{packages}, $update_medium); $o->pkg_install(@{$u->{packages} || []}); #- re-install urpmi with update security medium. install_urpmi($o); } sub summaryBefore {} sub summary { my ($o) = @_; configureTimezone($o); } sub summaryAfter { my ($_o) = @_; } #------------------------------------------------------------------------------ sub configureTimezone { my ($o) = @_; install::any::preConfigureTimezone($o); $o->pkg_install('ntp') if $o->{timezone}{ntp}; require timezone; timezone::write($o->{timezone}); } #------------------------------------------------------------------------------ sub configureServices { my ($o) = @_; if ($o->{services}) { require services; services::doit($o, $o->{services}); } } #------------------------------------------------------------------------------ sub setRootPassword_addUser { my ($o) = @_; setRootPassword($o); addUser($o); } sub setRootPassword { my ($o) = @_; $o->{superuser} ||= {}; require authentication; authentication::set_root_passwd($o->{superuser}, $o->{authentication}); install::any::set_authentication($o); } sub addUser { my ($o) = @_; my $users = $o->{users} ||= []; if ($::prefix) { #- getpwnam, getgrnam, getgrid works symlinkf("$::prefix/etc/passwd", '/etc/passwd'); symlinkf("$::prefix/etc/group", '/etc/group'); } any::add_users($users, $o->{authentication}); if ($o->{autologin}) { $o->{desktop} ||= first(any::sessions()); $o->pkg_install("autologin") if !member($o->{desktop}, 'KDE', 'GNOME'); } any::set_autologin($o->do_pkgs, $o->{autologin}, $o->{desktop}); install::any::disable_user_view() if @$users == (); } #------------------------------------------------------------------------------ sub read_bootloader_config { my ($o) = @_; require bootloader; eval { add2hash($o->{bootloader} ||= {}, bootloader::read($o->{all_hds})) }; $@ && $o->{isUpgrade} and log::l("read_bootloader_config failed: $@"); $o->{bootloader}{bootUnsafe} = 0 if $o->{bootloader}{boot}; #- when upgrading, do not ask where to install the bootloader (mbr vs boot partition) } sub setupBootloaderBefore { my ($o) = @_; any::setupBootloaderBefore($o->do_pkgs, $o->{bootloader}, $o->{all_hds}, $o->{fstab}, $o->{keyboard}, $o->{allowFB}, $o->{vga}, $o->{meta_class} ne 'server'); } sub setupBootloader { my ($o) = @_; any::install_acpi_pkgs($o->do_pkgs, $o->{bootloader}); require bootloader; bootloader::install($o->{bootloader}, $o->{all_hds}); } #------------------------------------------------------------------------------ sub configureXBefore { my ($o) = @_; #- keep this here if the package has to be updated. $o->pkg_install("task-x11"); } sub configureX { my ($o) = @_; configureXBefore($o); require Xconfig::default; $o->{raw_X} = Xconfig::default::configure($o->do_pkgs, $o->{keyboard}, $o->{mouse}); require Xconfig::main; Xconfig::main::configure_everything_auto_install($o->{raw_X}, $o->do_pkgs, $o->{X}, install::any::X_options_from_o($o)); configureXAfter($o); } sub configureXAfter { my ($_o) = @_; } #------------------------------------------------------------------------------ sub miscellaneousBefore { my ($o) = @_; require security::level; require security::various; $o->{security} ||= security::level::get(); $o->{security_user} ||= security::various::config_security_user($::prefix); $o->{libsafe} ||= security::various::config_libsafe($::prefix); log::l("security level is $o->{security}"); } sub miscellaneous { my ($_o) = @_; #- keep some given parameters #-TODO } sub miscellaneousAfter { my ($o) = @_; $ENV{SECURE_LEVEL} = $o->{security}; #- deprecated with chkconfig 1.3.4-2mdk, uses /etc/sysconfig/msec addToBeDone { addVarsInSh("$::prefix/etc/sysconfig/system", { META_CLASS => $o->{meta_class} }); eval { install::any::set_security($o) }; } 'installPackages'; } #------------------------------------------------------------------------------ sub exitInstall { my ($o) = @_; install::any::deploy_server_notify($o) if exists $o->{deploy_server}; #- mainly for auto_install's #- do not use run_program::xxx because it does not leave stdin/stdout unchanged system("bash", "-c", $o->{postInstallNonRooted}) if $o->{postInstallNonRooted}; system("chroot", $::prefix, "bash", "-c", $o->{postInstall}) if $o->{postInstall}; eval { my $report = '/root/drakx/report.bug'; unlink "$::prefix$report", "$::prefix$report.gz"; output "$::prefix$report", install::any::report_bug(); run_program::rooted($::prefix, 'gzip', $report); }; eval { install::any::getAndSaveAutoInstallFloppies($o, 1) } if arch() !~ /^ppc/; eval { output "$::prefix/root/drakx/README", "This directory contains several installation-related files, mostly log files (very useful if you ever report a bug!). Beware that some Mandriva Linux tools rely on the contents of some of these files... so remove any file from here at your own risk! " }; #- wait for remaining processes. foreach (@{$o->{waitpids}}) { waitpid $_, 0; log::l("pid $_ returned $?"); } install::media::umount_media($o->{packages}); install::media::openCdromTray(install::media::first_medium($o->{packages})->{phys_medium}{device}) if !detect_devices::is_xbox() && $o->{method} eq 'cdrom'; install::media::log_sizes(); } #------------------------------------------------------------------------------ sub hasNetwork { my ($o) = @_; $o->{net}{type} && $o->{net}{network}{NETWORKING} ne 'no' and return 1; log::l("no network seems to be configured for internet ($o->{net}{type},$o->{net}{network}{NETWORKING})"); 0; } sub network_is_cheap { my ($o) = @_; member($o->{net}{type}, qw(adsl lan cable)); } sub start_network_interface { my ($o) = @_; require network::tools; network::tools::start_net_interface($o->{net}, 0); } sub stop_network_interface { my ($o) = @_; require network::tools; network::tools::stop_net_interface($o->{net}, 0); } #------------------------------------------------------------------------------ sub upNetwork { my ($o, $b_pppAvoided) = @_; install::any::is_network_install($o) || $::local_install and return 1; $o->{modules_conf}->write; if (! -e "/etc/resolv.conf") { #- symlink resolv.conf in install root too so that updates and suppl media can be added symlink "$::prefix/etc/resolv.conf", "/etc/resolv.conf"; } if (hasNetwork($o)) { if (network_is_cheap($o)) { log::l("starting network ($o->{net}{type})"); start_network_interface($o); return 1; } elsif (!$b_pppAvoided) { log::l("starting network (ppp: $o->{net}{type})"); eval { modules::load(qw(serial ppp bsd_comp ppp_deflate)) }; run_program::rooted($::prefix, "/etc/rc.d/init.d/syslog", "start"); start_network_interface($o); return 1; } else { log::l(qq(not starting network (b/c ppp avoided and type is "$o->{net}{type})")); } } $::testing; } #------------------------------------------------------------------------------ sub downNetwork { my ($o, $costlyOnly) = @_; install::any::is_network_install($o) || $::local_install and return 1; $o->{modules_conf}->write; if (hasNetwork($o)) { if (!$costlyOnly) { stop_network_interface($o); return 1; } elsif (!network_is_cheap($o)) { stop_network_interface($o); run_program::rooted($::prefix, "/etc/rc.d/init.d/syslog", "stop"); eval { modules::unload(qw(ppp_deflate bsd_comp ppp serial)) }; return 1; } } $::testing; } #------------------------------------------------------------------------------ sub cleanIfFailedUpgrade($) { my ($o) = @_; #- if an upgrade has failed, there should be .mdkgisave files around. if ($o->{isUpgrade}) { foreach (@filesToSaveForUpgrade) { if (-e "$::prefix/$_" && -e "$::prefix/$_.mdkgisave") { rename "$::prefix/$_", "$::prefix/$_.mdkginew"; #- keep new files around in case ! rename "$::prefix/$_.mdkgisave", "$::prefix/$_"; } } } } 1;