summaryrefslogtreecommitdiffstats
path: root/perl-install/bootlook.pm
blob: d472b77055d2c7909e5b93eca9f2e72040ffd398 (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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#!/usr/bin/perl -w

# Control-center

# Copyright (C) 2001 MandrakeSoft
# Yves Duret <yduret at mandrakesoft.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


use Gtk;
use Config;
init Gtk;
use POSIX;
use Locale::GetText;
use lib qw(/usr/lib/libDrakX);
use interactive;
use standalone;
use common qw(:common :file :functional :system);
use my_gtk qw(:helpers :wrappers);
use any;

setlocale (LC_ALL, "");
Locale::GetText::textdomain ("Bootlookdrake");

import Locale::GetText I_;
*_ = *I_;


$::isEmbedded = ($::XID, $::CCPID) = "@ARGV" =~/--embedded (\S*) (\S*)/;
if ($::isEmbedded) {
  print "EMBED\n";
  print "XID : $::XID\n";
  print "CCPID :  $::CCPID\n";
}

my $in = interactive::vnew('su');
local $_ = join '', @ARGV;

/-h/ and die _("no help implemented yet.\n");

my @winm;
my @usernames;
parse_etc_passwd();

my $x_mode = isXlaunched();
my $a_mode = (-e "/etc/aurora/Monitor") ? 1 : 0;
my $l_mode = isAutologin();
my %auto_mode = get_autologin("");
my $inmain = 0;

my $window = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window ("toplevel");
$window->signal_connect(delete_event => sub { $::isEmbedded ? kill(USR1, $::CCPID) : Gtk->exit(0) });
$window->set_title(_("Boot Style Configuration") );
$window->border_width(10);
$window->realize;

# drakX mode
my ($t_pixmap, $t_mask) = gtkcreate_png("tradi.png");
my ($h_pixmap, $h_mask) = gtkcreate_png("hori.png");
my ($v_pixmap, $v_mask) = gtkcreate_png("verti.png");
my ($g_pixmap, $g_mask) = gtkcreate_png("gmon.png");
my ($c_pixmap, $c_mask) = gtkcreate_png("categ.png");

# a pixmap widget to contain the pixmap
my $pixmap = new Gtk::Pixmap( $h_pixmap, $h_mask );

### menus definition
# the menus are not shown
# but they provides shiny shortcut like C-q
my @menu_items = ( { path        => _("/_File"),
		     type        => '<Branch>' },
		   { path        => _("/File/_New"),
		     accelerator => _("<control>N"),
		     callback    => \&print_hello },
		   { path        => _("/File/_Open"),
		     accelerator => _("<control>O"),
		     callback    => \&print_hello },
		   { path        => _("/File/_Save"),
		     accelerator => _("<control>S"),
		     callback    => \&print_hello },
		   { path        => _("/File/Save _As") },
		   { path        => _("/File/-"),
		     type        => '<Separator>' },
		   { path        => _("/File/_Quit"),
		     accelerator => _("<control>Q"),
		     callback    => sub { $::isEmbedded ? kill(USR1, $::CCPID) : Gtk->exit(0) } },
		   { path        => _("/_Options"),
		     type        => '<Branch>' },
		   { path        => _("/Options/Test")},
		   { path        => _("/_Help"),
		     type        => '<LastBranch>' },
		   { path        => _("/Help/_About...")} );

my $menubar = get_main_menu( $window );

######### menus end

my $global_vbox = new Gtk::VBox();
#$global_vbox->pack_start (new Gtk::Label(_("Boot style configuration")), 0, 0, 0);

# lilo/grub
my $lilo_dedans = new Gtk::HBox(0, 0);
my $lilo_button = new Gtk::Button _("Lilo/Grub configuration");
$lilo_dedans->pack_end($lilo_button,0,0,0);
$lilo_button->signal_connect(clicked => sub { lilo_choice(); });

my $lilo_frame = new Gtk::Frame _("Lilo/grub mode");
$lilo_frame->add($lilo_dedans);
$global_vbox->pack_start ($lilo_frame, 0, 0, 0);


######## aurora part
my $a_dedans = new Gtk::VBox(0, 5);
$a_dedans->border_width(0);
my $a_box = new Gtk::VBox(0, 0);

my $a_c_button = new Gtk::RadioButton _("NewStyle Categorizing Monitor");
$a_c_button->signal_connect(clicked => sub { $pixmap->set($c_pixmap, $c_mask) });
$a_box->pack_start($a_c_button, 0, 0, 0);
my $a_h_button = new Gtk::RadioButton _("NewStyle Monitor"), $a_c_button;
$a_h_button->signal_connect(clicked => sub { $pixmap->set($h_pixmap, $h_mask) });
$a_box->pack_start($a_h_button, 0, 0, 0);
my $a_v_button = new Gtk::RadioButton _("Traditional Monitor"), $a_c_button;
$a_v_button->signal_connect(clicked => sub { $pixmap->set($v_pixmap, $v_mask) });
$a_box->pack_start($a_v_button, 0, 0, 0);
my $a_g_button = new Gtk::RadioButton _("Traditional Gtk+ Monitor"), $a_c_button;
$a_g_button->signal_connect(clicked => sub { $pixmap->set($g_pixmap, $g_mask) });
$a_box->pack_start($a_g_button, 0, 0, 0);

my $a_button = new Gtk::CheckButton(_("Launch Aurora at boot time") );
$a_button->signal_connect(clicked => sub {
			      if ($inmain) {
				  $a_box->set_sensitive(!$a_mode);
				  $a_mode = !$a_mode;
				  if ($a_mode) {
				      $pixmap->set($c_pixmap, $c_mask) if $a_c_button->get_active();
				      $pixmap->set($h_pixmap, $h_mask) if $a_h_button->get_active();
				      $pixmap->set($v_pixmap, $v_mask) if $a_v_button->get_active();
				      $pixmap->set($g_pixmap, $g_mask) if $a_g_button->get_active();
				  } else {
				      $pixmap->set($t_pixmap, $t_mask);
				  }
			      }
			   });
$a_dedans->pack_start($a_button, 0, 0, 0);
$a_dedans->pack_start ($a_box, 0, 0, 0);

my $a_main_hbox = new Gtk::HBox;
$a_main_hbox->pack_start ($a_dedans, 0, 0, 0);
my $a_pix_hbox = new Gtk::HBox;
$a_pix_hbox->border_width(0);
$a_pix_hbox->pack_start ($pixmap, 0, 0, 0);
$a_main_hbox->pack_end ($a_pix_hbox, 0, 0, 0);

my $aurora_frame = new Gtk::Frame _("Boot mode");
$aurora_frame->add($a_main_hbox);
$global_vbox->pack_start ($aurora_frame, 0, 0, 0);

### X mode
my $x_dedans = new Gtk::VBox(0, 0);
$x_dedans->border_width (0);
my $x_box = new Gtk::VBox(0, 0);
$x_box->border_width (0);

my $x_button = new Gtk::CheckButton _("Launch the X-Window system at start");
$x_button->set_active($x_mode);
$x_button->signal_connect(clicked => sub {
			       $x_box->set_sensitive(!$x_mode);
			       $x_mode = !$x_mode;
			   });
$x_dedans->pack_start ($x_button, 0, 0, 0);

my $x_no_button = new Gtk::RadioButton _("No, I don't want autologin");
$x_no_button->set_active(!$l_mode);
$x_box->pack_start($x_no_button, 0, 0, 0);

my $user_dedans = new Gtk::HBox(0, 10);
$user_dedans->border_width (0);
my $x_yes_button = new Gtk::RadioButton _("Yes, I want autologin with this (user, desktop)"), $x_no_button;
$x_yes_button->set_active($l_mode);
my $x_combo_vbox = new Gtk::VBox(0, 10);
my $user_combo = new Gtk::Combo;
$user_combo->set_popdown_strings(@usernames);
$user_combo->entry->set_text($auto_mode{autologin}) if ($auto_mode{autologin});

my $desktop_combo =new Gtk::Combo;
$desktop_combo->set_popdown_strings(get_wm());
$desktop_combo->entry->set_text($auto_mode{desktop}) if ($auto_mode{desktop});
$x_combo_vbox->pack_start($user_combo, 0, 0, 0);
$x_combo_vbox->pack_start($desktop_combo, 0, 0, 0);
$user_dedans->pack_start($x_yes_button, 0, 0, 0);
$user_dedans->pack_start($x_combo_vbox, 0, 0, 0);
$x_box->pack_start ($user_dedans, 0, 0, 0);
$x_box->set_sensitive($x_mode);
$x_dedans->pack_start ($x_box, 0, 0, 0);
my $x_main_frame = new Gtk::Frame _("System mode");
$x_main_frame->add($x_dedans);
$global_vbox->pack_start ($x_main_frame, 1, 1, 0);

### final buttons
my $bbox = new Gtk::HButtonBox;
$global_vbox->pack_start($bbox, 0, 0, 0);
$bbox->set_layout(-end);
my $build_button = new Gtk::Button _("OK");
$bbox->add($build_button);
my $cancel_button = new Gtk::Button $::isEmbedded ? _("Cancel") : _("Quit");
$bbox->add($cancel_button);
my $fin_hbox = new Gtk::HBox( 0, 0 );
$cancel_button->signal_connect(clicked => sub {$::isEmbedded ? kill(USR1, $::CCPID) : Gtk->exit(0)});
$build_button->signal_connect(clicked=>sub{updateInit();updateAutologin();updateAurora();$::isEmbedded ? kill(USR1,$::CCPID) : Gtk->exit(0)});

### back to window
$window->add($global_vbox);
$window->show_all();

$a_box->set_sensitive($a_mode); # box grisée == false == "0"
$a_button->set_active($a_mode); # up == false == "0"
if ($a_mode) {
    my $a = readlink "/etc/aurora/Monitor";
    $a =~ s#/lib/aurora/Monitors/##;
    if ($a eq "NewStyle-Categorizing-WsLib") {$a_c_button->set_active(1);  $pixmap->set($c_pixmap, $c_mask);}
    if ($a eq "NewStyle-WsLib") {$a_h_button->set_active(1);  $pixmap->set($h_pixmap, $h_mask);}
    if ($a eq "Traditional-WsLib") {$a_v_button->set_active(1); $pixmap->set($v_pixmap, $v_mask);}  
    if ($a eq "Traditional-Gtk+") {$a_g_button->set_active(1); $pixmap->set($g_pixmap, $g_mask);}
} else {
    $pixmap->set($t_pixmap, $t_mask);
}

Gtk->main_iteration while Gtk->events_pending;
$::isEmbedded and kill USR2, $::CCPID;
$inmain=1;
Gtk->main;
Gtk->exit(0);

#-------------------------------------------------------------
# get user names to put in combo  
#-------------------------------------------------------------

sub parse_etc_passwd
{
    my ($uname, $uid);
    setpwent();
    do {
	@user_info = getpwent();
	($uname, $uid) = @user_info[0,2];
	if ($uid > 500) {
	    push (@usernames, $uname);
	}
    } while (@user_info);
}

sub get_wm
{
    @winm = (split (' ', `/usr/sbin/chksession -l`));
}

#-------------------------------------------------------------
# menu callback functions
#-------------------------------------------------------------

sub print_hello {
  print( "mcdtg !\n" );
}

sub get_main_menu {
  my ( $window ) = @_;

  my $accel_group = new Gtk::AccelGroup();
  my $item_factory = new Gtk::ItemFactory( 'Gtk::MenuBar', '<main>', $accel_group );
  $item_factory->create_items( @menu_items );
  $window->add_accel_group( $accel_group );
  return ( $item_factory->get_widget( '<main>' ) );
}

#-------------------------------------------------------------
# launch X functions
#-------------------------------------------------------------

sub isXlaunched
{
    my $line;
    
    open INITTAB, "/etc/inittab" or die _("can not open /etc/inittab for reading: $!");
    while (<INITTAB>) {
	if (/id:([1-6]):initdefault:/) { $line = $_; last; }
    }
    close INITTAB;
    $line =~ s/id:([1-6]):initdefault:/$1/;
    return ($line-3);
}

sub updateInit
{
    my $runlevel = ($x_mode) ? 5 : 3;
    substInFile { s/^id:\d:initdefault:\s*$/id:$runlevel:initdefault:\n/ } "/etc/inittab";
}

#-------------------------------------------------------------
# aurora functions
#-------------------------------------------------------------



sub updateAurora
{
    if ($a_mode) {
        if ($a_c_button->get_active()) {
            symlinkf("/lib/aurora/Monitors/NewStyle-Categorizing-WsLib",    "/etc/aurora/Monitor");
            $in->standalone::pkgs_install(q(Aurora-Monitor-NewStyle-Categorizing-WsLib)) if !(-e "/lib/aurora/Monitors/NewStyle-Categorizing-WsLib");
        }
        if ($a_h_button->get_active()) {
            symlinkf("/lib/aurora/Monitors/NewStyle-WsLib",    "/etc/aurora/Monitor");
            $in->standalone::pkgs_install(q(Aurora-Monitor-NewStyle-WsLib)) if !(-e "/lib/aurora/Monitors/NewStyle-WsLib");
        }
        if ($a_v_button->get_active()) {
            symlinkf("/lib/aurora/Monitors/Traditional-WsLib", "/etc/aurora/Monitor");
            $in->standalone::pkgs_install(q(Aurora-Monitor-Traditional-WsLib)) if !(-e "/lib/aurora/Monitors/Traditional-WsLib");
        }
        if ($a_g_button->get_active()) {
            symlinkf("/lib/aurora/Monitors/Traditional-Gtk+",  "/etc/aurora/Monitor");
            $in->standalone::pkgs_install(q(Aurora-Monitor-Traditional-Gtk+)) if !(-e "/lib/aurora/Monitors/Traditional-Gtk+");
	}
    } else {
	unlink "/etc/aurora/Monitor";
    }
    
}

#-------------------------------------------------------------
# launch autologin functions
#-------------------------------------------------------------

sub isAutologin
{
    my $line;
    
    open AUTOLOGIN, "/etc/sysconfig/autologin" or die _("can not open /etc/sysconfig/autologin for reading: $!");
    while (<AUTOLOGIN>) {
	if (/AUTOLOGIN=(yes|no)/) { $line = $_; last; }
    }
    close AUTOLOGIN;
    $line =~ s/AUTOLOGIN=(yes|no)/$1/;
    chomp ($line);
    $line =  ($line eq "yes");
    return ($line);
}

sub get_autologin {
    my ($prefix) = @_;
    my %o;
    my %l = getVarsFromSh("$prefix/etc/sysconfig/autologin");

    $o{autologin} = $l{USER};
    %l = getVarsFromSh("$prefix/etc/sysconfig/desktop");
    $o{desktop} = $l{DESKTOP};
    %o;
}

sub updateAutologin
{
    my ($usern,$deskt)=($user_combo->entry->get_text(), $desktop_combo->entry->get_text());

    if ($x_yes_button->get_active()) {
	$in->standalone::pkgs_install(q(autologin)) if $x_mode;
	set_autologin('',$usern,$deskt);
    } else {
	set_autologin('',undef) if ($x_no_button->get_active());
    }
}
 
sub set_autologin {
  my ($prefix, $user, $desktop) = @_;

  output "$prefix/etc/sysconfig/desktop", uc($desktop), "\n" if $user;

  setVarsInSh("$prefix/etc/sysconfig/autologin",
	      { USER => $user, AUTOLOGIN => bool2yesno($user), EXEC => "/usr/X11R6/bin/startx" });
#  log::l("cat $prefix/etc/sysconfig/autologin: ", cat_("$prefix/etc/sysconfig/autologin"));
}


#-------------------------------------------------------------
# lilo/grub functions
#-------------------------------------------------------------
sub lilo_choice
{
    my $bootloader = bootloader::read('', '/etc/lilo.conf');
    local ($_) = `detectloader`;
    $bootloader->{methods} = { lilo => 1, grub => !!/grub/i };
    
    my ($hds) = catch_cdie { fsedit::hds([ detect_devices::hds() ], {}) } sub { 1 };
    my $fstab = [ fsedit::get_fstab(@$hds) ];
    fs::get_mntpoints_from_fstab($fstab);
 
    $::expert=1;
  ask:
    $::isEmbedded = 0;
    any::setupBootloader($in, $bootloader, $hds, $fstab, $ENV{SECURE_LEVEL}) or $in->exit(0);
    eval { bootloader::install('', $bootloader, $fstab, $hds) };  
    if ($@) {
	$in->ask_warn('', 
		      [ _("Installation of LILO failed. The following error occured:"),
			grep { !/^Warning:/ } cat_("/tmp/.error") ]);
	unlink "/tmp/.error";
	goto ask;
    }
    $::isEmbedded = 0;
}