summaryrefslogtreecommitdiffstats
path: root/globetrotter/make_live
blob: 52ed394f80cc63b732d1e1e69f004017724e1fd3 (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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
#!/usr/bin/perl

$::isInstall = 1; # for /root/drakx/ddebug.log

use strict;
#use lib qw(/usr/lib/libDrakX);
use lib "../perl-install";
use standalone;
use interactive;
use common;
use partition_table;
use fsedit;
use fs;
use any;
use pkgs;
use class_discard;
use run_program;
use log;

# my $in = interactive->vnew;

$::isStandalone = undef;  # for /tmp/ddebug.log

my (%options, @new_ARGV);

foreach (@ARGV) {
    if (/^--(.*)/) {
        $options{$1} = 1;
    } else {
        push @new_ARGV, $_;
    }
}

my $rescue;

if ($0 =~ /restore_globetrotter/) {
    %options = (install => 1, post => 1);
    $rescue = 1;
}

@ARGV = @new_ARGV;

my @suggestions = (
                   { mntpoint => "/",     size => 4500 << 11, type => 0x483, ratio => 1, maxsize => 6000 << 11 },
                   # splited / and /usr:
                   # { mntpoint => "/",     size => 250 << 11, type => 0x483, ratio => 1, maxsize => 2000 << 11 },
                   # { mntpoint => "/usr",  size => 300 << 11, type => 0x483, ratio => 4, maxsize => 4000 << 11 },
                   { mntpoint => "/home", size => 100 << 11, type => 0x483, ratio => 3 },

                   # share partition with windows:
                   { mntpoint => "/mnt/share",  size => 2000 << 11, type => 0xb, ratio => 2, maxsize => 10000 << 11 },
                   { mntpoint => "/mnt/packages", size => 7500 << 11, type => 0x483, ratio => 3, maxsize => 7500 << 11 },
                   # allocated last b/c end of disk is usually faster:
                   { mntpoint => "swap",  size =>  64 << 11, type => 0x82, ratio => 1, maxsize =>  500 << 11 },
                  );


sub get_hds() {
	my $all_hds = fsedit::get_hds();
     my $other;
	($all_hds->{hds}, $other) = partition { $_->{usb_description} eq 'LaCie|LaCie Hard Drive USB' } @{$all_hds->{hds}};
	die "I did not found any LaCie disk\n" if !$all_hds->{hds}[0];
	$all_hds, $all_hds->{hds}[0]; # $other
}


sub prepare_disk() {
    # repartion the hard disk:
    print "PARTITIONNING\n";
    my ($all_hds, $hd, $other) = get_hds();
    # partition_table::remove($hd, $_) while partition_table::get_normal_parts($hd);
    run_program::run("swapoff", "/dev/$all_hds->{hds}[0]{device}8") if any { /$all_hds->{hds}[0]{device}/ } cat_("/proc/partitions");

    partition_table::raw::zero_MBR_and_dirty($hd);
    fsedit::allocatePartitions($all_hds, \@suggestions);
    require diskdrake::interactive;
    require class_discard;
    # diskdrake::interactive::write_partitions(class_discard->new, $_, 'skip_check_rebootNeeded') foreach (@{$all_hds->{hds}});
    foreach (@{$all_hds->{hds}}) {
	    local $::isStandalone = undef;
	    print "WRITE PARTITION ON $_->{file}\n";
	    diskdrake::interactive::write_partitions(class_discard->new, $_, 'skip_check_rebootNeeded')
    }
    # partition_table::write(@{$all_hds->{hds}});
    ($all_hds, $hd, $other);
}


sub formatdisk {
    my ($hd) = @_;
    print "FORMATTING\n";
    foreach (partition_table::get_normal_parts($hd)) { 
        print qq(Formatting "$_->{device}" ($_->{mntpoint})\n); 
        fs::format_part(undef, $_, $::prefix, undef) if !$::testing;
    }
}


#@ARGV <= 1 or die "usage: make_live [live_location=/tmp/live_tree]\n";

    if (!find { m!/proc/bus/usb! } run_program::get_stdout('mount')) {
        warn "USB service is *NOT* started" if !$rescue;
        run_program::get_stdout('service', 'usb', 'start');
    }

sub find_partition {
  my ($label, @parts) = @_;
  find { member(fs::type2fs($_), qw(ext2 ext3)) && chomp_(`e2label /dev/$_->{device} 2>/dev/root`) eq $label } @parts;
}

my $pkg_dev;
if ($rescue) {
    system("mount -t tmpfs none /tmp");
    # let be able to see USB devices:
    system("mount -t usbfs none /proc/bus/usb");
    system("modprobe usb-storage; modprobe sd_mod");
    # let be able to detect SCSI hds:
    mkdir("/sys");
    system("mount -t sysfs none /sys");

    my ($all_hds, $hd, $other) = get_hds();
    print "Looking for the package partition\n";
    my @parts = partition_table::get_normal_parts($hd);
    $pkg_dev = find_partition("MDK-PKGS", @parts);
    die "I cannot find the package partition which is needed in order to restore the system!" if is_empty_hash_ref($pkg_dev) || !$pkg_dev->{device};
    my $root = find_partition("MDK-ROOT", @parts);
    $root = find { $_->{device} eq "sda1" } @parts if is_empty_hash_ref($root);
    die "I cannot find any hard disk to restore!" if is_empty_hash_ref($root) || !$root->{device};
    print "\nPlease wait, disk is being checked, this can take quite some time\n\n";
    run_program::run("e2fsck -C0 -y $_") foreach map {
      my $p = find_partition($_, @parts);
      if_($p, $p->{device}); # handle lost labels
    } "MDK-PKGS", "MDK-HOME"; # MDK-ROOT"
    print "Please wait, disk reinstallation is in progress, this can take quite some time\n";
    print "Formating $root->{device}\n";
    system("mkfs.ext2 -j /dev/$root->{device} > /dev/null\n");
    run_program::run('tune2fs', '-L', "MDK-ROOT", "/dev/$root->{device}"); # prevent lost label if restore aborts before the end
}

sub installPackages() {
    local $::testing = undef;

    # for a gconftool-2 cleaner:
    my $pid = fork();
    !defined $pid and die("cannot fork: $!");
    !$pid and do {
        while (1) {
            sleep(10);
            run_program::run('/usr/bin/killall', 'gconftool-2') if -x '/usr/bin/killall';
        }
    };
    my $_b = before_leaving { kill 'TERM', $pid if $pid };

    # ensure no %_install_langs:
    output_p("$::prefix/etc/rpm/macros", "%_install_langs all\n");
    # ensure boot from USB will work:
    output_p("$::prefix/etc/sysconfig/mkinitrd", "forceusb=yes\n");

    mkdir_p("$::prefix/var/lib/rpm");
    mkdir_p("$::prefix/root/drakx");


    undef *install_any::setDefaultPackages;
    *install_any::setDefaultPackages = sub {};

    undef *install_any::getFile;
    *install_any::getFile = sub {
	my ($f, $o_method) = @_;
	log::l("getFile $f:$o_method");
	open(my $F, '/export/' . install_any::relGetFile($f)) or return;
	$F;
    };

    undef *c::kernel_version;
    *c::kernel_version = sub {
	#my @l = glob_('/export/Mandrake/RPMS/kernel-enterprise-2.6*');
	my @l = glob_('/export/Mandrake/RPMS/kernel-2.6*');
	@l >= 1 or die  "can't find kernel";
	@l <= 1 or die "too many kernels";
	first(`rpm -qp --qf '%{name}' $l[0]` =~ /kernel-(.*)/);
    };

    my $kernel_version = c::kernel_version();

    print "INSTALLING\n";
    install_any::setPackages(my $o = $::o =
                             { 
                              prefix => $::prefix, 
                              meta_class => 'desktop', 
                              default_packages => [
				 #- for screenshots:
				 qw(fb2png),
				 qw(XFree86-server XFree86-xfs XFree86-FBDev),
				 qw(openssh-server), #- fred wants it
				 qw(alsa-utils cdialog newt),
                     qw(k3b-dvd),
				 qw(davfs nfs-utils samba-server sane-backends xsane xsane-gimp ntp),
                     qw(acpi acpid), #- so that removing acpi=ht will work
				 qw(mountloop),	#- crypted folders
				 qw(mandrake-doc-en mandrake-doc-fr mandrake-doc-drakxtools-en mandrake-doc-drakxtools-fr),
				 qw(autologin),
				 qw(synaptics),
				 #- network conf:
				 qw(wireless-tools pcmcia-cs),
				 #- zeroconf:
				 qw(zcip dhcpcd tmdns),
				 #- cnx stuff:
				 qw(dhcp-client ppp kdenetwork-kppp ppp-pppoatm ppp-pppoe pptp-linux pptp-adsl rp-pppoe),
				 #- ISDN stuff:
				 # qw(isdn4net ibod isdn4k-utils), # not installed since it provides an interface (will be automatically installed by drakconnect)
				 #- network file sharing:
				 qw(nfs-utils-clients samba-client),
				 #- network drivers and firmwares:
				 qw(eagle-usb speedtouch speedtouch_mgmt unicorn),
				 #- alt kernels:
				 # glob_('/export/Mandrake/RPMS/kernel-2.4*'), #- for ISDN
				 #- configuration:
				 qw(drakconf drakcronat drakfirsttime drakxtools harddrake-ui mdkonline rpmdrake userdrake2),
				 qw(cups cups-drivers foomatic-db gimpprint hpoj libnet-snmp mtools mtoolsfm nmap printer-filters printer-testpages printer-utils scli xojpanel xpp), #- printer stuff
				 "ATI_kernel-$kernel_version", qw(ATI_GLX ATI_GLX-utils NVIDIA_GLX libMesaGLU1), # ATI_GLX requires ATI_kernel
				 "NVIDIA_kernel-$kernel_version",
				 # qw(hcfpcimodem hsflinmodem ltmodem), #- 2.4.x only
				 qw(xinput), #- for some mice
				 qw(bash-completion binutils  emacs-X11 ntsysv perl-doc perl-Term-Readline-Gnu),  #- allow debugging
				 qw(openssh-askpass-gnome),  #- openssh-askpass for mountloop doesn't allow to click on ok/cancel buttons
				 qw(clanbomber freeciv-client freeciv-server crack-attack kdegames),  #- more games
				 qw(numlock),  # shorewall # not installed since its default config breaks network (will be automatically installed by drakfirewall)
				 qw(xawtv zapping),  #- tv apps
				 qw(scribus scribus-i18n-de scribus-i18n-fr),  #- John Jablonski says it's so much useful
                     (map { "OpenOffice.org-l10n-$_" } qw(ar ca cs da de el en es eu fi fr it ja ko nl pl pt pt_BR ru sk sv tr zh_CN zh_TW)),
				 qw(dosfstools mtools),
				 qw(koffice konsole),
				 qw(devfsd dynamic harddrake hotplug magicdev mandrake-globetrotter netprofile),
				 qw(gnome2),
				 qw(alsa-utils),
				 qw(ipw2100 ipw2100_kernel ipw2100_kernel-2.6.3.13mdk), # ipw2100_kernel-$kernel_version,
                     #- fonts:
				 qw(XFree86-100dpi-fonts XFree86-75dpi-fonts),
				 qw(fonts-bitmap-tscii fonts-hebrew-elmar),
                     (map { "fonts-ttf-$_" } qw(arabic armenian bengali big5 decoratives ethiopic gb2312 japanese kannada korean latex tamil thai tscii vera west_european)),
                     (map { "fonts-type1-$_" } qw(cyrillic greek hebrew)),
                     ],
					    });

    my %compssUsersChoice = map { $_ => 1 } map { @{$_->{flags}} } values %{$o->{compssUsers}};
    $compssUsersChoice{$_} = 1 foreach 'SYSTEM', 'DVD', 'USB', 'SOUND', 'BURNER', 'UTF8', 'DOCS', 'TV', '3D', 'INSTALL';
    $compssUsersChoice{qq(LOCALES"$_")} = 1 foreach lang::langsLANGUAGE({ all => 1 });

    pkgs::setSelectedFromCompssList($o->{packages}, \%compssUsersChoice, 4, 0);

    my $unselect = sub {
        my ($pkg) = @_;
        my $p = pkgs::packageByName($o->{packages}, $pkg);
        pkgs::unselectPackage($o->{packages}, $p) if $p;
    };

    # unselect some packages whose services fsck up the box and whose services are not enabled by appropriate tools:
    # (shorewall must be deselected before iptables is)
    $unselect->($_) foreach qw(at hpoj shorewall iptables ntp tmdns zcip );

    # unselect uim since uim IM break first time wizard when selecting english:
    $unselect->($_) foreach qw(uim-applet uim libuim0);

    my @toInstall = pkgs::packagesToInstall($o->{packages});
    local $ENV{DURING_INSTALL} = 1;
    $ENV{LD_LIBRARY_PATH} = "/lib:/usr/lib:/usr/X11R6/lib:/usr/lib/qt3/lib";
    pkgs::install($::prefix, 0, \@toInstall, $o->{packages});
    
    eval { fs::umount("$::prefix/proc") };
}

sub config_X_proprietary_drivers() {
    unlink "$::prefix/usr/lib/libGL.so";

    my %name_to_Driver = (NVIDIA_GLX => 'nvidia', ATI_GLX => 'fglrx');

    my $lib = 'libGL.so.1';
    symlinkf("/etc/X11/$lib", "$::prefix/usr/lib/$lib");
    foreach (keys %name_to_Driver) {
	my ($full_name) = run_program::rooted_get_stdout($::prefix, 'rpm', '-ql', $_) =~ m!/usr/lib/(\Q$lib\E\..*)! or die '';
	symlinkf($full_name, "$::prefix/usr/lib/$lib.$name_to_Driver{$_}");
    }
    #- remove the dirty hack done by NVIDIA_kernel-xxx proprietary package
    #- we do it by hand when needed
    substInFile { $_ = '' if $_ eq 'nvidia' } "$::prefix/etc/modules";
}

$::prefix = $ARGV[0] || '/tmp/live_tree';

-d $::prefix or mkdir $::prefix;
print "Making live in $::prefix directory.\n";


my ($all_hds, $hd, $other) = do {
    # here we want testing so that diskdrake still set mount points in data structure:
    local $::testing = !$options{partition};
    prepare_disk();
};

formatdisk($hd) if $options{format};

add2hash($hd, $other);

undef $::testing;

my @parts = partition_table::get_normal_parts($hd);

my ($root) = grep { $_->{mntpoint} eq "/" } @parts;
print "Root is $root->{device}\n";
run_program::run('tune2fs', '-L', "MDK-ROOT", "/dev/$root->{device}");
# fs::mount_part($root, $::prefix);
my $fstab = [ fsedit::get_all_fstab($all_hds) ];

# we need to mount every fs we want to see into /etc/fstab !!!
fs::mount_part($_, $::prefix) foreach sort { $a->{mntpoint} cmp $b->{mntpoint} } @$fstab;

symlink("$::prefix/mnt/packages", "/export") if $rescue;

eval {
    print "Installing packages\n";
    installPackages();
} if $options{install};
print "ERROR WHILE INSTALLING PACKAGES: $@\n" if $@;
log::closeLog;

sub doRootSubst {
    my ($file) = @_;
    substInFile {
        s!/dev/$root->{device}!LABEL=MDK-ROOT!g;
    } $file;
}

#fs::merge_info_from_mtab($fstab);
fs::write_fstab($all_hds, $::prefix);
append_to_file("$::prefix/etc/fstab", "none /dev/pts devpts mode=0620 0 0");
doRootSubst("$::prefix/etc/fstab");

my ($home) = grep { $_->{mntpoint} eq "/home" } @parts;
my ($mnt_pkgs) = grep { $_->{mntpoint} eq "/mnt/packages" } @parts;
run_program::run('tune2fs', '-L', "MDK-HOME", "/dev/$home->{device}") if $home;
run_program::run('tune2fs', '-L', "MDK-PKGS", "/dev/$mnt_pkgs->{device}") if $mnt_pkgs;

substInFile {
    s!defaults\s!defaults,ro ! if m!/mnt/packages!;
    s!defaults\s!defaults,umask=0000 ! if m!/mnt/share!;
    s!/dev/$home->{device}!LABEL=MDK-HOME!g;
    s!/dev/$mnt_pkgs->{device}!LABEL=MDK-PKGS!g;
} "$::prefix/etc/fstab";


#-------------------------------------------------------------------
#- Bootloader
print "Configuring bootloader\n";
system("modprobe loop");
require keyboard;
require bootloader;

my $bootloader = {
                  keytable => keyboard::keyboard2kmap(keyboard::lang2keyboard('fr')),
		  bios => { '/dev/sda' => '0x80' },
                 };

bootloader::suggest($bootloader, $all_hds->{hds}, $fstab,
                    vga_fb => 788, 
                    quiet => 1);

# LILO failled to boot from SCSI:
# $bootloader->{method} = 'lilo-graphic';
$bootloader->{method} = 'grub';

eval { bootloader::install($bootloader, $fstab, $all_hds->{hds}) };

doRootSubst("$::prefix/boot/grub/menu.lst");
run_program::rooted($::prefix, 'sh', '/boot/grub/install.sh');

# fix GRUB configuration:
substInFile {
    # use FB by default on versionned entries so that the initial versionned entry behave like those created by /sbin/installkernel:
    s/$/ vga=788/ if /^kernel.*\d\.\d\.\d/;
    # set devfs=mount as well so that installkernel can properly install bootable 2.4.x kernels:
    s/$/ devfs=mount/ if /^kernel/ && !/failsafe/;
} "$::prefix/boot/grub/menu.lst";


## disable ISDN by default (bogus isdn4net came with an enabled interface :-():
#substInFile {
#    s/#ONBOOT.*/ONBOOT="no"/
#} "$::prefix/etc/sysconfig/network-scripts/ifcfg-ippp0";
#

print "Post install misc configuration\n";


# clean services:
# cups-lpd ibod isdn4linux isdnlog)) {
run_program::rooted($::prefix, '/sbin/chkconfig', '--del', $_) foreach qw(acon jserver oki4daemon);
#foreach my $service (qw(acon atd cups-lpd hpoj ibod iptables isdn4linux isdnlog jserver ntpd oki4daemon shorewall tmdns)) {
#    run_program::rooted($::prefix, '/sbin/chkconfig', '--level', $_, $service, 'off') foreach qw(3 5);
#}

# probably useless:
foreach my $service (qw(alsa dm harddrake hotplug sound)) {
    run_program::rooted($::prefix, '/sbin/chkconfig', '--level', $_, $service,  'on') foreach qw(3 5);
}

if ($options{post}) {
    #-------------------------------------------------------------------
    # save a few more files in profiles
    my $prof_cfg = "$::prefix/etc/netprofile/list";
    my @files = map { chomp_($_) } cat_($prof_cfg);
    # do not save the whole /etc/sysconfig;
    push @files, (map { "/etc/X11/$_" } qw(XF86Config XF86Config-4)),
      (map { "/etc/sysconfig/$_" } qw(keyboard harddrake2/previous_hw harddisks)),
        (map { "/etc/$_" } qw(modprobe.conf modprobe.devfs modprobe.preload modules modules.conf modules.devfs)),
          qw(/etc/asound.state /etc/fstab /etc/ld.so.conf/GL.conf /etc/shorewall/);

    output($prof_cfg, join("\n", sort @files));


    #-------------------------------------------------------------------
    #- regenerate library loader and fonts cache
    run_program::rooted($::prefix, 'ldconfig');
    any::fix_broken_alternatives();
    run_program::rooted($::prefix, 'fc-cache'); #- generate cache in all directories mentioned in config file

    #- XFree

    touch("$::prefix/etc/menu/enable_simplified");

    {
        local $ENV{LC_ALL} = 'en_US'; #- update-menus doesn't work when there is no locale (aka locale "C")
        #local $ENV{HOME} = '/'; #- savekdemimetypes.pl needs this otherwise it's tmp file fails
        run_program::rooted($::prefix, 'update-menus', '-n');
    }

    run_program::rooted($::prefix, 'nspluginscan'); #- must be run before kbuildsycoca for the ksycoca to be flash plugin aware

    $ENV{HELP_BROWSER} = "kfmclient openProfile webbrowsing";
    $ENV{BROWSER} = "kfmclient openProfile webbrowsing";
    $ENV{DESKTOP} = "kde";
    #- faster boot:
    foreach my $lang (lang::list_langs()) {
        local $ENV{LC_ALL} = lang::getLANGUAGE($lang);
        unlink "$::prefix/usr/share/services/ksycoca";
        run_program::rooted($::prefix, 'kbuildsycoca', '--global');
        rename("$::prefix/usr/share/services/ksycoca", "$::prefix/usr/share/services/ksycoca-$lang");
    }
    symlinkf('/etc/X11/ksycoca', "$::prefix/usr/share/services/ksycoca");
}

# clean gconftool-2 mess:
unlink $_ foreach glob("$::prefix/core.*");


##- Mandrake
#substInFile {
#    s!Mandrake(l| L)inux release (\S+) \(.*\)!Mandrakelinux Nomad, powered by LaCie Mobile Hard Drive)!;
#} "$::prefix/etc/mandrake-release";
#


system("rsync -rvltp /export/ $::prefix/mnt/packages/") if !$rescue;
unlink $_ foreach glob("$::prefix/var/lib/urpmi/*");
run_program::rooted($::prefix, 'urpmi.addmedia', '-h', 'main', 'file:///mnt/packages/Mandrake/RPMS');
run_program::rooted($::prefix, 'urpmi.addmedia', '-h', 'contrib', 'file:///mnt/packages/Mandrake/RPMS2');

# for fast test replaying:
run_program::rooted($::prefix, 'tar', 'cfj', '/root/etc.tar.bz2', '/etc');

system("umount $::prefix/proc");
eval { fs::umount_all($fstab, $::prefix) } or system("umount $::prefix"); 
/span> " =============oo ", " ============ooo ", " o=========ooo ", " oo=====oooo ", " ooooooooo ", " ooooo ", ); #-my @questionmark_head = ( #-"39 97 6 1", #-" c None", #-". c #000000", #-"+ c #FFFFFF", #-"o c #AAAAAA", #-); #-my @questionmark_body = ( #-("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO") x 10, #-"OOOOOOOOOOOOO.......OOOOOOOOOOOOOOOOOOO", #-"OOOOOOOOOOOO..OOOOOOO.OOOOOOOOOOOOOOOOO", #-"OOOOOOOOOO..OOOOOOOOOOOOOOOOOOOOOOOOOOO", #-"OOOOOOOOOO..OOOOOOO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OOO++++++OOOOOo+++++++OOOOOOOXOOO", #-".OOOOOOOO++++++OOOOOo+++++++OOOOOOXOOOO", #-".OOOOOOOOo++++oOOOOOo++++++oOOOOOOOXOOO", #-".OOOOOOOOOo++oOOOOOOo++++++oOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOOOOO+++++++OOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOOOOO++++++OOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOOOOo+++++oOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOOOO+++++OOOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOOOo+++oOOOOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOOO+++oOOOOOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOOo++OOOOOOOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOO++OOOOOOOOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOO+oOOOOOOOOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOO+OOOOOOOOOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOO+OOOOOOOOOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOOoOOOOOOOOOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOXOOO", #-"O.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOXOOO", #-"OOOOOOOOOOOOOOOOoooOOOOOOOOOOOOOOOOXOOO", #-".OOOOOOOOOOOOOO+++++OOOOOOOOOOOOOOXOOOO", #-"O.OOOOOOOOOOOO++++++oOOOOOOOOOOOOOXXOOO", #-"O.OOOOOOOOOOOo+++++++OOOOOOOOOOOOOXOOOO", #-"O.OOOOOOOOOOOo+++++++OOOOOOOOOOOOOXOOOO", #-"O.OOOOOOOOOOOo+++++++OOOOOOOOOOOOOXOOOO", #-"OOOOOOOOOOOOOO++++++oOOOOO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OOOOOOOOOOOOOOOOOO") x 10); my @red_circle = (@circle_head, "= c #FF0000", "o c #AA5500", @circle_body); my @orange_circle = (@circle_head, "= c #FFAA00", "o c #AA5500", @circle_body); my @green_circle = (@circle_head, "= c #00FF00", "o c #00AA00", @circle_body); #-###################################################################################### #- In/Out Steps Functions #-###################################################################################### sub new($$) { my ($type, $o) = @_; my $old = $SIG{__DIE__}; $SIG{__DIE__} = sub { $_[0] !~ /my_gtk\.pm/ and goto $old }; $ENV{DISPLAY} = $o->{display} || ":0"; unless ($::testing) { $my_gtk::force_focus = $ENV{DISPLAY} eq ":0"; my $f = "/tmp/Xconf"; createXconf($f, @{$o->{mouse}}{"XMOUSETYPE", "device"}, $o->{wacom}); if ($ENV{DISPLAY} eq ":0") { my $launchX = sub { my $ok = 1; local $SIG{CHLD} = sub { $ok = 0 if waitpid(-1, c::WNOHANG()) > 0 }; unless (fork) { exec $_[0], "-dpms","-s" ,"240", "-allowMouseOpenFail", "-xf86config", $f or exit 1; } foreach (1..60) { sleep 1; log::l("Server died"), return 0 if !$ok; return 1 if c::Xtest($ENV{DISPLAY}); } log::l("Timeout!!"); 0; }; my @servers = qw(FBDev VGA16); #-) if (arch() eq "alpha") { require Xconfigurator; my $card = Xconfigurator::cardConfigurationAuto(); add2hash($card, Xconfigurator::cardName2card($card->{type})) if $card && $card->{type}; @servers = $card->{server} || "TGA"; #-@servers = qw(SVGA 3DLabs TGA) } @servers = qw(Mach64) if arch() =~ /^sparc/; @servers = qw(PPCDummy) if arch() eq "ppc"; foreach (@servers) { log::l("Trying with server $_"); my $dir = "/usr/X11R6/bin"; unless (-x "$dir/XF86_$_") { unlink $_ foreach glob_("$dir/XF86_*"); local *F; open F, ">$dir/XF86_$_" or die "failed to write server: $!"; local $/ = \ (16 * 1024); my $f = install_any::getFile("$dir/XF86_$_") or next; syswrite F, $_ foreach <$f>; chmod 0755, "$dir/XF86_$_"; } if (/FB/) { !$o->{vga16} && listlength(cat_("/proc/fb")) or next; $o->{allowFB} = &$launchX("XF86_$_") #- keep in mind FB is used. and goto OK; } else { $o->{vga16} = 1 if /VGA16/; &$launchX("XF86_$_") and goto OK; } } return undef; } } OK: @themes = @themes_vga16 if $o->{simple_themes} || $o->{vga16}; init_sizes(); install_theme($o); create_logo_window($o); $my_gtk::force_center = [ $::rootwidth - $::windowwidth, $::logoheight, $::windowwidth, $::windowheight ]; (bless {}, ref $type || $type)->SUPER::new($o); } sub enteringStep { my ($o, $step) = @_; print _("Entering step `%s'\n", $o->{steps}{$step}{text}); $o->SUPER::enteringStep($step); create_steps_window($o); create_help_window($o); } sub leavingStep { my ($o, $step) = @_; $o->SUPER::leavingStep($step); } #-###################################################################################### #- Steps Functions #-###################################################################################### sub selectLanguage { my ($o) = @_; $o->SUPER::selectLanguage; Gtk->set_locale; install_theme($o); } #------------------------------------------------------------------------------ sub selectMouse { my ($o, $force) = @_; my $old_dev = $o->{mouse}{device}; $o->SUPER::selectMouse($force); my $dev = $o->{mouse}{device}; if ($old_dev ne $dev && $dev =~ /ttyS/) { log::l("telling X server to use another mouse"); eval { commands::modprobe("serial") }; symlinkf($dev, "/dev/mouse"); c::setMouseMicrosoft($ENV{DISPLAY}); } } #------------------------------------------------------------------------------ sub doPartitionDisks($$) { my ($o, $hds, $raid) = @_; if ($::beginner && fsedit::is_one_big_fat($hds)) { #- wizard my $min_linux = 600 << 11; my $max_linux = 1500 << 11; my $min_freewin = 300 << 11; my ($part) = fsedit::get_fstab(@{$o->{hds}}); my $w = $o->wait_message(_("Resizing"), _("Computing fat filesystem bounds")); my $resize_fat = eval { resize_fat::main->new($part->{device}, devices::make($part->{device})) }; $@ and goto diskdrake; my $min_win = $resize_fat->min_size; if (!$@ && $part->{size} > $min_linux + $min_freewin + $min_win && $o->ask_okcancel('', _("WARNING! DrakX now needs to 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."))) { my $hd = $hds->[0]; my $oldsize = $part->{size}; $hd->{isDirty} = $hd->{needKernelReread} = 1; $part->{size} -= min($max_linux, $part->{size} - $min_win); $hd->adjustEnd($part); partition_table::adjust_local_extended($hd, $part); partition_table::adjust_main_extended($hd); local *log::l = sub { $w->set(join(' ', @_)) }; eval { $resize_fat->resize($part->{size}) }; if ($@) { $part->{size} = $oldsize; $o->ask_warn('', _("Automatic resizing failed")); } else { $part->{isFormatted} = 1; eval { fsedit::auto_allocate($hds, $o->{partitions}) }; if (!$@) { partition_table::write($hd) unless $::testing; return; } } } } diskdrake: while (1) { diskdrake::main($hds, $raid, interactive_gtk->new, $o->{partitions}); if (!grep { isSwap($_) } fsedit::get_fstab(@{$o->{hds}})) { if ($::beginner) { $o->ask_warn('', _("You must have a swap partition")); } elsif (!$::expert) { $o->ask_okcancel('', _("You don't have a swap partition\n\nContinue anyway?")) and last; } else { last } } else { last } } } #------------------------------------------------------------------------------ sub chooseSizeToInstall { my ($o, $packages, $min_size, $max_size) = @_; my ($min, $max) = map { pkgs::correctSize($_ / sqr(1024)) } $min_size, $max_size; log::l("choosing size to install between $min and $max (really between $min_size and $max_size)"); my $w = my_gtk->new(''); my $adj = create_adjustment($max, $min, $max); my $spin = gtkset_usize(new Gtk::SpinButton($adj, 0, 0), 100, 0); gtkadd($w->{window}, gtkpack(new Gtk::VBox(0,20), _("Now that you've selected desired groups, please choose how many packages you want, ranging from minimal to full installation of each selected groups.") . ($::expert ? "\n" . _("You will be able to choose more precisely in next step") : ''), create_packtable({ col_spacings => 10 }, [ _("Choose the size you want to install"), $spin, _("MB"), ], [ undef, new Gtk::HScrollbar($adj) ], ), create_okcancel($w) ) ); $spin->signal_connect(activate => sub { $w->{retval} = 1; Gtk->main_quit }); $spin->grab_focus(); $w->main and pkgs::invCorrectSize($spin->get_value_as_int) * sqr(1024); } sub choosePackagesTree { my ($o, $packages, $compss) = @_; my ($curr, $info_widget, $w_size, $go, $idle); my (%wtree, %ptree); my $w = my_gtk->new(''); my $details = new Gtk::VBox(0,0); my $tree = Gtk::CTree->new(2, 0); $tree->set_selection_mode('browse'); $tree->set_column_auto_resize($_, 1) foreach 0..1; gtkadd($w->{window}, gtkpack_(new Gtk::VBox(0,5), 0, _("Choose the packages you want to install"), 1, gtkpack(new Gtk::HBox(0,0), createScrolledWindow($tree), gtkadd(gtkset_usize(new Gtk::Frame(_("Info")), 150, 0), createScrolledWindow($info_widget = new Gtk::Text), )), 0, gtkpack__(new Gtk::HBox(0,0), $w_size = new Gtk::Label('')), 0, gtkpack(new Gtk::HBox(0,10), $go = gtksignal_connect(new Gtk::Button(_("Install")), "clicked" => sub { $w->{retval} = 1; Gtk->main_quit }), ) )); $w->{window}->set_usize(map { $_ - 2 * $my_gtk::border - 4 } $::windowwidth, $::windowheight); $go->grab_focus; $w->show; $tree->freeze; my $dir = $::testing && $ENV{SHARE_PATH} || "/usr/share"; my $pix_base = [ Gtk::Gdk::Pixmap->create_from_xpm($w->{window}->window, $w->{window}->style->bg('normal'), "$dir/rpm-base.xpm") ]; my $pix_selected = [ Gtk::Gdk::Pixmap->create_from_xpm($w->{window}->window, $w->{window}->style->bg('normal'), "$dir/rpm-selected.xpm") ]; my $pix_unselect = [ Gtk::Gdk::Pixmap->create_from_xpm_d($w->{window}->window, undef, "1 1 1 1", " c None", " ") ]; my $parent; $parent = sub { if (my $w = $wtree{$_[0]}) { return $w } my $s; foreach (split '/', $_[0]) { $wtree{"$s/$_"} ||= $tree->insert_node($s ? $parent->($s) : undef, undef, [$_], 5, (undef) x 4, 0, 0); $s = "$s/$_"; } $wtree{$s}; }; my $add_node = sub { my ($leaf, $root) = @_; my $node = $tree->insert_node($parent->($root), undef, [$leaf], 5, (undef) x 4, 1, 0); my $p = $packages->[0]{$leaf} or return; my $pix = pkgs::packageFlagBase($p) ? $pix_base : pkgs::packageFlagSelected($p) ? $pix_selected : $pix_unselect; $tree->node_set_pixmap($node, 1, $pix->[0], $pix->[1]); push @{$ptree{$leaf}}, $node; }; my ($root, $leaf); foreach (sort keys %{$packages->[0]}) { $add_node->($_, 'all'); } foreach (sort @$compss) { ($root, $leaf) = m|(.*)/(.+)|o or ($root, $leaf) = ('', $_); $add_node->($leaf, $root); } $tree->thaw; my $display_info = sub { my $p = $packages->[0]{$curr} or return gtktext_insert($info_widget, ''); pkgs::extractHeaders($o->{prefix}, [$p], $p->{medium}); $p->{header} or die; my $ind = $o->{compssListLevels}{$o->{install_class}}; my $imp = translate($pkgs::compssListDesc{pkgs::packageFlagBase($p) ? 100 : round_down($p->{values}[$ind], 10)}); gtktext_insert($info_widget, $@ ? _("Bad package") : _("Version: %s\n", pkgs::packageVersion($p) . '-' . pkgs::packageRelease($p)) . _("Size: %d KB\n", pkgs::packageSize($p) / 1024) . ($imp && _("Importance: %s\n", $imp)) . "\n" . formatLines(c::headerGetEntry($p->{header}, 'description'))); c::headerFree(delete $p->{header}); 0; }; $tree->signal_connect(tree_select_row => sub { Gtk->timeout_remove($idle) if $idle; if ($_[1]->row->is_leaf) { ($curr) = $tree->node_get_pixtext($_[1], 0); $idle = Gtk->timeout_add(100, $display_info); } else { $curr = $_[1]; } }); my $update_size = sub { my $size = 0; foreach (values %{$packages->[0]}) { $size += pkgs::packageSize($_) - ($_->{installedCumulSize} || 0) if pkgs::packageFlagSelected($_); #- on upgrade, installed packages will be removed. } $w_size->set(_("Total size: %d / %d MB", pkgs::correctSize($size / sqr(1024)), install_any::getAvailableSpace($o) / sqr(1024))); }; my $toggle = sub { if (ref $curr) { $tree->toggle_expansion($curr); } else { my $p = $packages->[0]{$curr} or return; pkgs::togglePackageSelection($packages, $p, my $l = {}); if (my @l = grep { $l->{$_} } keys %$l) { @l > 1 and $o->ask_okcancel('', [ _("The following packages are going to be install/removed"), join(", ", sort @l) ], 1) || return; pkgs::togglePackageSelection($packages, $p); foreach (@l) { my $p = $packages->[0]{$_}; my $pix = pkgs::packageFlagSelected($p) ? $pix_selected : $pix_unselect; $tree->node_set_pixmap($_, 1, $pix->[0], $pix->[1]) foreach @{$ptree{$_}}; } &$update_size; } else { $o->ask_warn('', _("This is a mandatory package, it can't be unselected")); } } }; $tree->signal_connect(button_press_event => sub { &$toggle if $_[1]{type} =~ /^2/ }); $tree->signal_connect(key_press_event => sub { my ($w, $e) = @_; my $c = chr $e->{keyval}; &$toggle if $e->{keyval} >= 0x100 ? $c eq "\r" || $c eq "\x8d" : $c eq ' '; 1; }); &$update_size; $w->main; } #------------------------------------------------------------------------------ sub installPackages { my ($o, $packages) = @_; my ($current_total_size, $last_size, $nb, $total_size, $start_time, $last_dtime, $trans_progress_total); my $w = my_gtk->new(_("Installing"), grab => 1); $w->{window}->set_usize($::windowwidth * 0.8, $::windowheight * 0.5); my $text = new Gtk::Label; my ($msg, $msg_time_remaining, $msg_time_total) = map { new Gtk::Label($_) } '', (_("Estimating")) x 2; my ($progress, $progress_total) = map { new Gtk::ProgressBar } (1..2); gtkadd($w->{window}, gtkadd(new Gtk::EventBox, gtkpack(new Gtk::VBox(0,10), _("Please wait, "), $msg, $progress, create_packtable({}, [_("Time remaining "), $msg_time_remaining], [_("Total time "), $msg_time_total], ), $text, $progress_total, '', gtkadd(create_hbox(), gtksignal_connect(new Gtk::Button(_("Cancel")), clicked => sub { $pkgs::cancel_install = 1 })), ))); $msg->set(_("Preparing installation")); $w->sync; my $oldInstallCallback = \&pkgs::installCallback; local *pkgs::installCallback = sub { my $m = shift; if ($m =~ /^Starting installation/) { $nb = $_[0]; $total_size = $_[1]; $current_total_size = 0; $start_time = time(); $msg->set(_("%d packages", $nb) . _(", %U MB", pkgs::correctSize($total_size / sqr(1024)))); $w->flush; } elsif ($m =~ /^Starting installing package/) { $progress->update(0); my $name = $_[0]; $msg->set(_("Installing package %s", $name)); $current_total_size += $last_size; $last_size = c::headerGetEntry($o->{packages}[0]{$name}{header}, 'size'); $text->set((split /\n/, c::headerGetEntry($o->{packages}[0]{$name}{header}, 'summary'))[0] || ''); $w->flush; } elsif ($m =~ /^Progressing installing package/) {