summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/drakautoinst
blob: 56bc1b8547d08e4bc148ce4d437c4c7f401cd90f (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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#!/usr/bin/perl

#
# Guillaume Cottenceau (gc)
#
# Copyright 2001-2008 Mandriva
#
# This software may be freely redistributed under the terms of the GNU
# public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

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

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

use common;
use interactive;
use devices;
use detect_devices;
use install::steps;
use fs;
use Data::Dumper;


local $_ = join '', @ARGV;

my $direct = /-direct/;

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

my $imagefile = "/root/drakx/replay_install.img";
my $imagefile2 = "/root/drakx/replay_install_drivers.img";
-f $imagefile or $in->ask_warn(N("Error!"), 
			       N("I can not find needed image file `%s'.", $imagefile), 1), quit_global($in, 0);

$direct or $in->ask_okcancel(N("Auto Install Configurator"),
N("You are about to configure an Auto Install floppy. This feature is somewhat dangerous and must be used circumspectly.

With that feature, you will be able to replay the installation you've performed on this computer, being interactively prompted for some steps, in order to change their values.

For maximum safety, the partitioning and formatting will never be performed automatically, whatever you chose during the install of this computer.

Press ok to continue."), 1) or quit_global($in, 0);


my @manual_steps = qw(doPartitionDisks formatPartitions);
my @all_steps;
my @choices;

my $st = \%steps::installSteps;

for (my $f = $st->{first}; $f; $f = $st->{$f}{next}) {
    next if member($f, @manual_steps);
    my $def_choice = 'replay';
    push @choices, { label => translate($st->{$f}{text}), val => \$def_choice, list => [ N("replay"), N("manual") ] };
    push @all_steps, [ $f, \$def_choice ];
}

$in->ask_from(N("Automatic Steps Configuration"),
	      N("Please choose for each step whether it will replay like your install, or it will be manual"),
	      \@choices
	     ) or quit_global($in, 0);

${$_->[1]} eq N("manual") and push @manual_steps, $_->[0] foreach @all_steps;

my $mountdir = "/root/tmp/drakautoinst-mountdir"; -d $mountdir or mkdir $mountdir, 0755;
my $floppy = detect_devices::floppy();
my $dev = devices::make($floppy);
my $again;
do {
    $in->ask_okcancel('', N("Insert a blank floppy in drive %s", $floppy), 1) or quit_global($in, 0);
    log::explanations(N("Creating auto install floppy"));
    my $_w = $in->wait_message('', N("Creating auto install floppy"));
    eval {
	run_program::run('dd', "if=$imagefile", "of=$dev", "bs=1440", "count=1024");
	common::sync();
    };
    $again = $@; #- grrr... $@ is localized in code block :-(
} while $again;
fs::mount::mount($dev, $mountdir, 'vfat', 0);

if (-f $imagefile2) {
    do {
        eval { fs::mount::umount($mountdir) };
        $in->ask_okcancel('', N("Insert another blank floppy in drive %s (for drivers disk)", $floppy), 1) or quit_global($in, 0);
        log::explanations(N("Creating auto install floppy (drivers disk)"));
        my $_w = $in->wait_message('', N("Creating auto install floppy"));
        eval {
            run_program::run('dd', "if=$imagefile2", "of=$dev", "bs=1440", "count=1024");
            common::sync();
        };
        $again = $@; #- grrr... $@ is localized in code block :-(
    } while $again;
    fs::mount::mount($dev, $mountdir, 'ext2', 0);
}

my $cfgfile = "$mountdir/auto_inst.cfg";
eval(cat_($cfgfile));
my $o_old = $o; # BUG (maybe install's $::o ?)
my %struct_gui;

if (!$::isEmbedded && $in->isa('interactive::gtk')) {
    require ugtk2;
    ugtk2->import(qw(:helpers :wrappers :create));

    my %tree;
    $struct_gui{$_} = 'General' foreach qw(lang isUpgrade autoExitInstall timezone default_packages);
    $struct_gui{$_} = 'Security' foreach qw(crypto security);
    $struct_gui{$_} = 'Harddrive' foreach qw(partitions manualFstab useSupermount partitioning);
    $struct_gui{$_} = 'Network' foreach qw(intf netc netcnx);
    $struct_gui{$_} = 'Users' foreach qw(superuser users authentication);
    $struct_gui{$_} = 'Hardware' foreach qw(keyboard mouse X printer wacom nomouseprobe);

    my %pixmap = (lang => 'language',
		isUpgrade => '',
		security => 'security',
		autoExitInstall => '',
		timezone => '',
		default_packages => '',
		partitions => 'harddrive',
		manualFstab => 'partition',
		useSupermount => '',
		partitioning => 'partition',
		net => 'network',
		superuser => 'user',
		users => 'user',
		authentication => '',
		keyboard => 'keyboard',
		mouse => 'mouse',
		X => 'X',
		printer => 'printer',
		wacom => '',
	      );

    exists $struct_gui{$_} and push @{$tree{$struct_gui{$_}}}, [ $_ , $pixmap{$_}, h2widget($o->{$_}, "\$o->\{$_}") ] foreach keys %$o;

    my $W = ugtk2->new('$o edition');
    my @box_to_hide;
    my $nb_pages=0;
    my $notebook = Gtk2::Notebook->new;
    $notebook->set_show_border(0);
    $notebook->set_show_tabs(0);
    $notebook->append_page(gtkpack_(gtkset_border_width(Gtk2::VBox->new(0,0), 10),
				    1, Gtk2::VBox->new(0,0),
				    0, gtkpack_(Gtk2::HBox->new(0,0),
						1, Gtk2::VBox->new(0,0),
						0, gtkadd(gtkset_shadow_type(Gtk2::Frame->new, 'etched-in'),
							  gtkcreate_img('mdk_logo')),
						1, Gtk2::VBox->new(0,0),
					       ),
				    0, N("\nWelcome.\n\nThe parameters of the auto-install are available in the sections on the left"),
				    1, Gtk2::VBox->new(0,0),
				   ), undef);
    $notebook->show_all;
    $notebook->set_current_page(0);

    gtkadd($W->{window},
	   gtkpack_(Gtk2::VBox->new(0,5),
	   1, gtkpack_(Gtk2::HBox->new(0,0),
		    0, gtkadd(gtkset_size_request(gtkset_shadow_type(Gtk2::Frame->new, 'in'), 130, 470),
			    gtkpack_(Gtk2::VBox->new(0,0),
				     map {
					 my $box = Gtk2::VBox->new(0,0);
					 push @box_to_hide, $box;
					 $box->{vis} = 0;
					 my @button_to_hide;
					 0, gtksignal_connect(Gtk2::Button->new($_), clicked => sub {
								if ($box->{vis}) { $box->hide; $box->{vis} = 0; $notebook->set_current_page(0) }
								else {
								    $_->hide, $_->{vis}=0 foreach @box_to_hide;
								    $box->show; $box->{vis} = 1;
								    $box->{active_function} and $box->{active_function}->();
								}
							    }), 1, gtkpack__($box,
							  map {
							      my $button = gtkset_relief(Gtk2::ToggleButton->new, 'none');
							      push @button_to_hide, $button;
							      my $gru = $_->[0];
							      $notebook->append_page(gtkshow($_->[2]), undef);
							      $nb_pages++;
							      my $local_page = $nb_pages;
							      my $function = sub { $notebook->set_current_page($local_page) };
							      gtksignal_connect($button, toggled => sub {
										    $button->get_active and $function->()
										});
							      my $b;
                                         if ($_->[1] ne "") { $b = gtkcreate_img($_->[1]) } else { undef $b };
							      gtksignal_connect(gtkadd($button,
										       gtkpack__(Gtk2::VBox->new(0,3),
												 $b,
												 translate($gru),
												)
										      ), released => sub {
											  $button->get_active or $button->set_active(1), return;
											  $_->set_active(0) foreach @button_to_hide;
											  $button->set_active(1);
											  $box->{active_function} = $function;
											  $function->();
										      })
									    } @{$tree{$_}}
									   )
							} keys(%tree)
				    )
			   ),
		    1, $notebook,
		   ),
	    0, Gtk2::HSeparator->new,
	    0, gtkadd(gtkset_border_width(gtkset_layout(Gtk2::HButtonBox->new, 'end'), 5),
		      gtksignal_connect(Gtk2::Button->new(N("Accept")), clicked => sub { Gtk2->main_quit }),
		      gtksignal_connect(Gtk2::Button->new(N("Cancel")), clicked => sub { $o = $o_old; Gtk2->main_quit; quit_global($in, 0) }),
		     )
	   )
	  );
    $_->hide foreach @box_to_hide;
#    $W->{window}->show_all;
#      gtkadd($W->{window},
#  	   gtkpack_($W->create_box_with_title(N("Edit variables")),
#  		    1, my $notebook = create_notebook( map { h2widget($o->{$_}, "\$o->\{$_\}"), $_ } keys %$o ),
#  		    0, gtkpack(gtkset_border_width(Gtk2::HBox->new(0,0),5), $W->create_okcancel),
#  		   ),
#  	  );
#    $notebook->set_tab_pos('left');
#    $::isEmbedded and gtkflush();
    $W->main;
#    $W->destroy();
}

$o->{interactiveSteps} = \@manual_steps;

my $str = join('',
"#!/usr/bin/perl -cw
#
# Special file generated by ``drakautoinst''.
#
# You should check the syntax of this file before using it in an auto-install.
# You can do this with 'perl -cw auto_inst.cfg.pl' or by executing this file
# (note the '#!/usr/bin/perl -cw' on the first line).
",
	       Data::Dumper->Dump([$o], ['$o']), "\0");
$str =~ s/ {8}/\t/g; #- replace all 8 space char by only one tabulation, this reduces file size so much :-)
output($cfgfile, $str);

fs::mount::umount($mountdir);

$in->ask_okcancel(N("Congratulations!"), 
N("The floppy has been successfully generated.
You may now replay your installation."));

quit_global($in, 0);


sub quit_global {
    my ($in, $exitcode) = @_;
    $in->exit($exitcode);
}



sub h2widget {
    my ($k, $label) = @_;
    my $w;
    if (ref($k) =~ /HASH/) {
	my $vb;
	my @widget_list;
	my $i = -1;
	my @list_keys = keys(%$k);
	if (ref($k->{$list_keys[0]}) =~ /HASH/) {
	    $i++;
	    $w = gtkpack_(Gtk2::VBox->new(0,0),
			  1, create_scrolled_window(gtkpack__($vb = Gtk2::VBox->new(0,10),
							    $widget_list[$i] = create_packtable({ col_spacings => 10, row_spacings => 3 },
					map {
					    my $e;
					    $e = h2widget($k->{$_}, "$label\{$_}");
					    [ "$_ : ", $e ] } @list_keys
									    ),
						       )
					     ),
			  control_buttons($k->{$list_keys[0]},
					  sub { my ($vb, $widget_list2, $ref_local_k, $i) = @_;
						my @widget_list = @$widget_list2;
			my $field = $in->ask_from_entry(N("Auto Install"), ("Enter the name of the new field you want to add")) or return undef;
						$field eq '' and return undef;
						gtkpack__($vb,
							  $widget_list[$i] = create_packtable({ col_spacings => 10, row_spacings => 3 },
										      [ "$field : ", h2widget($ref_local_k, "$label\{$field}") ])
							 );
						@$widget_list2 = @widget_list;
					    },
					  $vb, \$i, \@widget_list)
			 );
	} else {
	    $w = create_packtable({ col_spacings => 10, row_spacings => 3 },
				  map { create_entry_element($k->{$_}, "$label\{$_}", $_) } @list_keys
				 )
	}
    } elsif (ref($k) =~ /ARRAY/) {
	my $vb;
	my @widget_list;
	my $i = -1;
	$w = gtkpack_(Gtk2::VBox->new(0,0),
		      1, create_scrolled_window(
					      gtkpack__($vb = Gtk2::VBox->new(0,5),
							map { $i++; $widget_list[$i] = h2widget($_, "$label\[$i]") } @$k,
						       )
					     ),
		      control_buttons($k->[0],
				      sub { my ($vb, $widget_list2, $ref_local_k, $i) = @_;
					    my @widget_list = @$widget_list2;
					    gtkpack__($vb, $widget_list[$i] = h2widget($ref_local_k, "$label\[$i]"));
					    @$widget_list2 = @widget_list;
					},
				      $vb, \$i, \@widget_list)
		     );
    } else {
	$w = create_packtable({ col_spacings => 10, row_spacings => 3 },
			      create_entry_element($k, $label, $1)) if $label =~ /\$o->\{(.+)\}/;
    }
    return $w;
}


sub create_entry_element {
    my ($text, $value, $label) = @_;
    my $e;
    if (ref $text =~ /HASH/) {
	return [ "$label : ", h2widget($text, $label) ];
    } elsif (ref $text =~ /ARRAY/) {
	return [ "$label : ", h2widget($text, $label) ];
    } else {
	$e = Gtk2::Entry->new;
	$e->{value} = $value;
	my $_tag = Glib::Timeout->add(1000, sub { $e->set_text($text); 0 });
	gtksignal_connect($e, changed => sub {
			      my $exe = $e->{value} . "='" . $e->get_text . "'";
			      print "EXEC : $exe\n ";
			      eval $exe;
			  });
    }
    [ $label ? "$label : " : "" , $e ]
}

sub control_buttons {
    my ($ref_local_k, $local_gui, $vb, $j, $widget_list2) = @_;
    my @widget_list = @$widget_list2;
    my $i = $$j;
    ref($ref_local_k) =~ /HASH/ or return();
    my %local_k = %$ref_local_k;
    my ($button_remove);
    0, gtkadd(gtkset_border_width(gtkset_layout(Gtk2::HButtonBox->new, 'spread'), 5),
	      gtksignal_connect(Gtk2::Button->new(N("Add an item")), clicked => sub {
				    $local_k{$_} = undef foreach keys %local_k;
				    $i++;
				    $local_gui->($vb, \@widget_list, \%local_k, $i) or $i--, return;
				    $i >= 0 and $button_remove->set_sensitive(1);
				}
			       ),
	      gtksignal_connect($button_remove = Gtk2::Button->new(N("Remove the last item")), clicked => sub {
				    $i >= 0 or return;
				    $widget_list[$i]->destroy;
				    $i--;
				    $i >= 0 or $button_remove->set_sensitive(0);
				}
			       )
	     )
}
ass="hl opt">() =~ /ppc/, qw(dmasound_pmac snd-powermac)), if_(arch() =~ /sparc/, qw(snd-sun-amd7930 snd-sun-cs4231 snd-sun-dbri)), if_(arch() !~ /^sparc/, qw(ad1816 ad1848 ad1889 ali5455 audigy audio awe_wave cmpci cs4232 cs4281 cs46xx), qw(emu10k1 es1370 es1371 esssolo1 forte gus i810_audio ice1712 kahlua mad16 maestro), qw(maestro3 mpu401 msnd_pinnacle nm256_audio nvaudio opl3 opl3sa opl3sa2 pas2 pss), qw(rme96xx sam9407 sb sgalaxy snd-ad1816a snd-ad1848 snd-ali5451 snd-als100), qw(snd-als4000 snd-atiixp snd-au8810 snd-au8820 snd-au8830 snd-audigyls snd-azt2320 snd-azt3328 snd-azx), qw(snd-bt87x snd-ca0106 snd-cmi8330 snd-cmipci snd-cs4231 snd-cs4232 snd-cs4236 snd-cs4281), qw(snd-cs46xx snd-darla20 snd-darla24 snd-dt019x snd-emu10k1 snd-emu10k1x snd-ens1370 snd-ens1371 snd-es1688 snd-es18xx), qw(snd-es1938 snd-es1968 snd-es968 snd-fm801 snd-gina20 snd-gina24 snd-gina3g snd-gusclassic snd-gusextreme), qw(snd-gusmax snd-hda-intel snd-hdsp snd-hdspm snd-ice1712 snd-ice1724 snd-indi snd-indigo snd-indigodj snd-indigoio snd-intel8x0 snd-interwave), qw(snd-interwave-stb snd-korg1212 snd-layla20 snd-layla24 snd-layla3g snd-maestro3 snd-mia snd-mixart snd-mona snd-mpu401 snd-nm256), qw(snd-opl3sa2 snd-opti92x-ad1848 snd-opti92x-cs4231 snd-opti93x snd-pcxhr snd-rme32), qw(snd-rme96 snd-rme9652 snd-sb16 snd-sb8 snd-sbawe snd-sgalaxy snd-sonicvibes), qw(snd-sscape snd-trident snd-via82xx snd-vx222 snd-vxp440 snd-vxpocket snd-wavefront), qw(snd-ymfpci sonicvibes sscape trident via82cxxx_audio wavefront ymfpci), ), ], tv => [ qw(bt878 bttv cx8800 cx88-blackbird dpc7146 ivtv saa7134 zr36067) ], dvb => [ qw(budget budget-av budget-ci cinergyT2 dvb-ttusb-budget dvb-usb-a800 dvb-dibusb dvb-usb-dibusb-mb dvb-ttpci dvb-usb-digitv dvb-usb-dtt200u dvb-usb-nova-t-usb2 dvb-usb-umt-010 dvb-usb-vp7045 hexium_orion hexium_gemini skystar2) ], photo => [ qw(dc2xx mdc800) ], radio => [ qw(radio-gemtek-pci radio-maxiradio) ], scanner => [ qw(scanner microtek) ], gameport => [ qw(cs461x ns558 emu10k1-gp fm801-gp lightning ns558 vortex) ], usb_sound => [ qw(audio dabusb dsbr100 snd-usb-audio snd-usb-usx2y usb-midi) ], webcam => [ qw(cpia_usb cyber2000fb ibmcam konicawc mod_quickcam ov511 ov511-alt ov518_decomp ovfx2 pwc quickcam se401 stv680 sn9c102 ultracam usbvideo usbvision vicam w9968cf) ], }, # USB input stuff get automagically loaded by hotplug and thus # magically work through /dev/input/mice multiplexing: input => { joystick => [ qw(iforce xpad), # there're more drivers in drivers/input/joystick but they support non USB or PCI devices # and thus cannot be detected but by slow (and maybe dangerous?) load_category: qw(a3d adi analog cobra db9 gamecon gf2k grip grip_mp guillemot interact), qw(joydump magellan sidewinder spaceball spaceorb stinger tmdc turbografx warrior) ], remote => [ qw(ati_remote) ], # USB tablets and touchscreens: tablet => [ qw(acecad aiptek wacom kbtab) ], touchscreen => [ qw(ads7846_ts gunze hp680_ts_input itmtouch mk712 mtouch mtouchusb touchkitusb) ], }, various => # just here for classification, unused categories (nor auto-detect, nor load_thiskind) { raid => [ qw(dm-crypt dm-mirror dm-mod linear lvm-mod multipath raid0 raid1 raid10 raid5), ], mouse => [ qw(atixlmouse busmouse generic_serial inport logibm logibusmouse msbusmouse pcips2 qpmouse synclinkmp), if_(arch() =~ /ppc/, 'macserial'), qw(hid mousedev usbhid usbmouse), ], char => [ if_(arch() =~ /ia64/, qw(efivars)), qw(applicom n_r3964 nvram pc110pad ppdev), qw(wdt_pci i810-tco sx), #- what are these??? ], crypto => [ qw(amd768_rng amd7xx_tco i810_rng hw_random leedslite padlock), ], laptop => [ qw(i8k sonypi toshiba), ], serial => [ qw(8250_pci 8250 epca esp isicom istallion moxa mxser stallion sx synclink synclinkmp), ], other => [ qw(defxx i810fb ide-floppy ide-scsi ide-tape loop lp nbd sg st), qw(parport_pc parport_serial), qw(btaudio), arch() =~ /i.86/ ? 'aes-i586' : 'aes', if_(arch() =~ /sparc/, 'openprom'), qw(evdev), qw(usblp printer), 'floppy', #- these need checking qw(rrunner meye), ], agpgart => [ if_(arch() =~ /alpha/, qw(alpha-agp)), if_(arch() =~ /ia64/, qw(hp-agp i460-agp)), if_(arch() =~ /ppc/, qw(uninorth-agp)), qw(ali-agp amd64-agp amd-k7-agp ati-agp efficeon-agp intel-agp), qw(k7-agp mch-agp nvidia-agp sis-agp sworks-agp via-agp), ], }, ); my %dependencies; sub load_dependencies { my ($file) = @_; %dependencies = map { my ($f, $deps) = split ':'; $f => [ split ' ', $deps ]; } cat_($file); } sub dependencies_closure { my @l = map { dependencies_closure($_) } @{$dependencies{$_[0]} || []}; (@l, $_[0]); } sub category2modules { map { my ($t1, $t2s) = m|(.*)/(.*)|; my @sub = $t2s eq '*' ? keys %{$l{$t1}} : split('\|', $t2s); map { my $l = $l{$t1}{$_} or die "bad category $t1/$_\n" . backtrace(); @$l; } @sub; } split(' ', $_[0]); } sub all_modules() { map { @$_ } map { values %$_ } values %l; } sub module2category { my ($module) = @_; foreach my $t1 (keys %l) { my $h = $l{$t1}; foreach my $t2 (keys %$h) { $module eq $_ and return "$t1/$t2" foreach @{$h->{$t2}}; } } return; } sub ethernet_categories() { 'network/main|gigabit|pcmcia|tokenring|usb|wireless|firewire'; } sub sub_categories { my ($t1) = @_; keys %{$l{$t1}}; } sub kernel_is_26 { $_[0] =~ /^2\.6/ } sub module_extension { kernel_is_26($_[0]) ? 'ko' : 'o' } 1;