summaryrefslogtreecommitdiffstats
path: root/perl-install/devices.pm
blob: 6e1b7ccf4f0b571157ca6877e2c1c61f89801948 (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
package devices;

use diagnostics;
use strict;

use common qw(:system :file);
use run_program;
use log;
use c;

1;


sub size($) {
    local *F;
    sysopen F, $_[0], 0 or log::l("open $_[0]: $!"), return 0;

    my $valid_offset = sub { sysseek(F, $_[0], 0) && sysread(F, my $a, 1) };

    #- first try getting the size nicely
    my $size = 0;
    ioctl(F, c::BLKGETSIZE(), $size) and return unpack("i", $size) * $common::SECTORSIZE;

    #- sad it didn't work, well searching the size using the dichotomy algorithm!
    my $low = 0;
    my ($high, $mid);

    #- first find n where 2^n < size <= 2^n+1
    for ($high = 1; $high > 0 && &$valid_offset($high); $high *= 2) { $low = $high; }

    while ($low < $high - 1) {
	$mid = int ($low + $high) / 2;
	&$valid_offset($mid) ? $low : $high = $mid;
    }
    $low + 1;
}

sub make($) {
    local $_ = my $file = $_[0];
    my ($type, $major, $minor);

    if (m,^(.*/(?:dev|tmp))/(.*),) {
	$_ = $2;
    } else {
	$file = "/tmp/$_";
	-e $file or $file = "/dev/$_";
    }
    -e $file and return $file; #- assume nobody takes fun at creating files named as device

    if (/^sd(.)(\d{0,2})/) {
	$type = c::S_IFBLK();
	$major = 8;
	$minor = 16 * (ord($1) - ord('a')) + ($2 || 0);
    } elsif (/^hd(.)(\d{0,2})/) {
	$type = c::S_IFBLK();
	($major, $minor) =
	    @{ $ {{'a' => [3, 0], 'b' => [3, 64],
		   'c' => [22,0], 'd' => [22,64],
		   'e' => [33,0], 'f' => [33,64],
		   'g' => [34,0], 'h' => [34,64],
	       }}{$1} or die "unknown device $_" };
	$minor += $2 || 0;
    } elsif (/^ram(.*)/) {
	$type = c::S_IFBLK();
	$major = 1;
	$minor = $1 eq '' ? 1 : $1;
    } elsif (m|^rd/c(\d+)d(\d+)(p(\d+))?|) {
	# dac 960 "/rd/cXdXXpX"
        $type = c::S_IFBLK();
	$major = 48 + $1;
	$minor = 8 * $2 + $4;
    } elsif (m|ida/c(\d+)d(\d+)(p(\d+))?|) {
	# Compaq Smart Array "ida/c0d0{p1}"
	$type = c::S_IFBLK();
	$major = 72 + $1;
	$minor = 16 * $2 + ($4 || 0);
    } elsif (/(.*)(\d+)$/) {
	    ($type, $major, $minor) =
	     @{ ${{"fd"     => [ c::S_IFBLK(), 2,  0 ],
		   "md"     => [ c::S_IFBLK(), 9,  0 ],
		   "lp"     => [ c::S_IFCHR(), 6,  0 ],
		   "scd"    => [ c::S_IFBLK(), 11, 0 ],
		   "nst"    => [ c::S_IFCHR(), 9, 128],
		   "ttyS"   => [ c::S_IFCHR(), 4, 64 ],
		   "hidbp-mse-" => [ c::S_IFCHR(), 10, 32 ],
	       }}{$1}};
	    $minor += $2;
    }
    unless ($type) {
	($type, $major, $minor) =
	     @{ ${{"aztcd"   => [ c::S_IFBLK(), 29, 0 ],
		   "bpcd"    => [ c::S_IFBLK(), 41, 0 ],
		   "cdu31a"  => [ c::S_IFBLK(), 15, 0 ],
		   "cdu535"  => [ c::S_IFBLK(), 24, 0 ],
		   "cm206cd" => [ c::S_IFBLK(), 32, 0 ],
		   "tty"     => [ c::S_IFCHR(),  5, 0 ],
		   "gscd"    => [ c::S_IFBLK(), 16, 0 ],
		   "mcd"     => [ c::S_IFBLK(), 23, 0 ],
		   "mcdx"    => [ c::S_IFBLK(), 20, 0 ],
		   "mem"     => [ c::S_IFCHR(), 1,  1 ],
		   "psaux"   => [ c::S_IFCHR(), 10, 1 ],
		   "random"  => [ c::S_IFCHR(), 1,  8 ],
		   "optcd"   => [ c::S_IFBLK(), 17, 0 ],
		   "sbpcd"   => [ c::S_IFBLK(), 25, 0 ],
		   "sjcd"    => [ c::S_IFBLK(), 18, 0 ],
		   "psaux"   => [ c::S_IFCHR(), 10, 1 ],
		   "usbmouse"=> [ c::S_IFCHR(), 10, 32], #- aka hidbp-mse-0
		   "zero"    => [ c::S_IFCHR(), 1,  5 ],		     
	       }}{$_} or die "unknown device $_" };
    }

    #- make a directory for this inode if needed.
    mkdir dirname($file), 0755;

    syscall_('mknod', $file, $type | 0600, makedev($major, $minor)) or die "mknod failed (dev $_): $!";

    $file;
}
href='#n799'>799 800 801 802 803 804 805 806 807 808 809
package move; # $Id$ $

#- Copyright (c) 2003-2004 Mandrakesoft
#-
#- 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 diagnostics;
use strict;

use modules;
use common;
use fs;
use fsedit;
use run_program;
use partition_table qw(:types);
use swap;
use log;
use lang;
use Digest::MD5 qw(md5_hex);

my $key_disabled;

my ($using_existing_user_config, $using_existing_host_config);
my $key_sysconf = '/home/.sysconf';
my $key_part;
my $virtual_key_part;
my $key_mountopts = 'umask=077,uid=501,gid=501,shortname=mixed,nobadchars';

sub symlinkf_short {
    my ($dest, $file) = @_;
    if (my $l = readlink $dest) {
	$dest = $l if $l =~ m!^/!;
    }
    -d $file and log::l("$file already exists and is a directory! writing in directory may be needed, not overwriting"), return;
    symlinkf($dest, $file);
}

sub handle_etcfiles {
    my (@allowed_modes) = @_;
    #- non-trivial files listed from tools/scan-etc.pl
    my ($mode, $allowed);
    foreach (chomp_(cat_('/image/move/etcfiles'))) {
        if (m|^# (\S+)|) {
	    $mode = $1;
	    $allowed = member($mode, @allowed_modes);
	} elsif (m|^/| && $allowed) {
            if ($mode eq 'READ') {
                mkdir_p(dirname($_));
		symlinkf_short("/image$_", $_) if !-e $_;
	    } elsif ($mode eq 'OVERWRITE') {
                mkdir_p(dirname($_));
                cp_f("/image$_", $_);  #- need copy contents
            } elsif ($mode eq 'DIR') {
		mkdir_p $_;
	    }
        }
    }

}

sub handle_virtual_key() {
    return if $key_disabled;
    if (my ($device, $file, $options) = cat_('/proc/cmdline') =~ /\bvirtual_key=([^,\s]+),([^,\s]+)(,\S+)?/) {
        log::l("using device=$device file=$file as a virtual key with options $options");
        my $dir = '/virtual_key_mount';
        mkdir $dir;
        run_program::run('mount', $device, $dir);
        if ($options =~ /format/) {
	    if (! -e "$dir$file") {
		require commands;
		commands::dd("if=/dev/zero", "of=$dir$file", "bs=1M", "count=40");
	    }
	    run_program::run('mkdosfs', "$dir$file");
	}
        require devices;
        my $loop = devices::find_free_loop();
        run_program::run('losetup', $loop, "$dir$file");
        run_program::run('mount', $loop, '/home', '-o', $key_mountopts);
	$virtual_key_part = { device => $loop, mntpoint => '/home', type => 0xc, isMounted => 1 };
    }
}

sub setup_userconf {
    my ($o) = @_;
    if (is_empty_array_ref($o->{users}) && `getent passwd 501` =~ /([^:]+):/) {
        log::l("passwd/501 is $1");
        $o->{users} = [ { name => $1 } ];
	$ENV{HOME} = "/home/$1"; #- used by lang::read()  :-/
        print "using existing user configuration\n";
        $using_existing_user_config = 1;
    }
}

sub lang2move_clp_name {
    my ($lang) = @_;
    my $dir = '/usr/share/locale/' . lang::l2locale($lang);
    my $link = readlink($dir) or return -d $dir ? '' : 'ERROR';
    my ($name) = $link =~ m!image_(i18n_.*?)/! or log::l("ERROR: bad link $link for $dir"), return 'ERROR';
    $name;
}

#- run very soon at stage2 start, setup things on tmpfs rw / that
#- were not necessary to start stage2 itself (there were setup
#- by stage1 of course)
sub init {
    my ($o) = @_;

    $::testing and goto drakx_stuff;

    #- rw things
    mkdir "/$_" foreach qw(home mnt root root/tmp etc var);

    mkdir "/etc/$_" foreach qw(X11);
    touch '/etc/modules.conf';
    touch '/etc/modprobe.conf';
    cp_f('/proc/mounts', '/etc/mtab');

    #- these files need be writable but we need a sensible first contents
    cp_f("/image/etc/$_", '/etc') foreach qw(passwd passwd- group sudoers fstab);

    #- these files are typically opened in read-write mode, we need them copied
    mkdir_p("/etc/$_"), cp_f(glob_("/image/etc/$_/*"), "/etc/$_")
      foreach qw(cups profile.d sysconfig devfs/conf.d);

    #- TODO: cp_af is broken for symlinks to directories
    #- replace below with cp_af is fixed in perl-MDK-Common
    run_program::run('cp', '-a', glob("/image/etc/rc[0-6].d"), '/etc');

    #- directories we badly need as non-links because files will be written in
    handle_etcfiles('DIR');
 
    #- for /etc/sysconfig/networking/ifcfg-lo
    mkdir "/etc/sysconfig/networking";

    #- ro things
    symlinkf_short("/image/etc/$_", "/etc/$_")
      foreach qw(alternatives man.config services shells pam.d inputrc ld.so.conf 
                 DIR_COLORS bashrc profile init.d devfsd.conf gtk-2.0 pango fonts modules.devfs 
                 dynamic hotplug gnome-vfs-2.0 gnome-vfs-mime-magic gtk gconf menu menu-methods nsswitch.conf default login.defs 
                 skel ld.so.cache openoffice xinetd.d xinetd.conf syslog.conf sysctl.conf sysconfig/networking/ifcfg-lo
                 ifplugd);
    symlinkf_short("/image/etc/X11/$_", "/etc/X11/$_")
      foreach qw(encodings.dir app-defaults applnk fs lbxproxy proxymngr rstart wmsession.d xinit xkb xserver xsm);
    symlinkf_short("/image/root/$_", "/root/$_") foreach qw(.bashrc);

    mkdir_p(dirname("/var/$_")), symlinkf_short("/image/var/$_", "/var/$_") foreach qw(lib/samba lib/rpm cache/gstreamer-0.6);

    #- non-trivial files/directories that need be readable, files that will be overwritten
    handle_etcfiles('READ', 'OVERWRITE');

    run_program::run('chown', 'clamav.clamav', '/var/log/clamav/freshclam.log');

    #- create remaining /etc and /var subdirectories if not already copied or symlinked,
    #- because programs most often will not try to create the missing subdir before trying
    #- to write a file, leading to obscure unexpected failures
    foreach (cat_('/image/move/directories-to-create')) {
	my ($mode, $uid, $gid, $name) = split;
	next if -d $name;
	mkdir($name);
	chmod(oct($mode), $name);
	chown($uid, $gid, $name);
    }

    chmod 01777, '/tmp', '/var/tmp';  #- /var/tmp -> badly needed for printing from OOo

    #- remaining non existent /etc files are symlinked from the RO volume,
    #- better to have them RO than non existent.
    #- PB: problems arise when programs try to open then in O_WRONLY
    #- or O_RDWR -> in that case, they should be handled in the
    #- OVERWRITE section of data/etcfiles)
    foreach (chomp_(cat_('/image/move/all-etcfiles'))) {
        -f $_ or symlinkf_short("/image$_", $_);
    }

    #- free up stage1 memory
    eval { fs::umount($_) } foreach qw(/stage1/proc/bus/usb /stage1/proc /stage1);

    #- devfsd needed for devices accessed by old names
    fs::mount("none", "/dev", "devfs", 0);
    fs::mount("none", "/dev/pts", "devpts", 0);
    run_program::run('/sbin/devfsd', '/dev');

    -d '/lib/modules/' . c::kernel_version() or warn("ERROR: kernel package " . c::kernel_version() . " not installed\n"), c::_exit(1);

    $key_disabled = !-e '/cdrom/live_tree_nvidia.clp' && cat_('/proc/mounts') !~ /nfs/;

    run_program::run('/sbin/service', 'syslog', 'start');
    run_program::run('sysctl', '-w', 'kernel.hotplug=/bin/true');
    modules::load_category('bus/usb'); 
    eval { modules::load('usb-storage', 'sd_mod') };
    handle_virtual_key();
    $o->{pcmcia} ||= !$::noauto && c::pcmcia_probe();
    cat_('/proc/cmdline') =~ /\bwaitkey\b/ and sleep 15;
    install_steps::setupSCSI($o);
    run_program::run('sysctl', '-w', 'kernel.hotplug=/sbin/hotplug');

    if (cat_('/proc/cmdline') =~ /\bformatkey\b/) {
	#- waiting until X is launched
    } else {
	key_mount($o);
    }
    if (cat_('/proc/cmdline') =~ /\bcleankey\b/) {
	eval { rm_rf $key_sysconf, glob_('/home/.mdkmove*') };
    }
    key_installfiles('simple');
    setup_userconf($o);
    if (-f '/etc/X11/X') {
        print "using existing host configuration\n";
        $using_existing_host_config = 1;

	#- so that /etc/devfsd/conf.d/mouse.conf is used and /dev/mouse created
	run_program::run('/sbin/service', 'devfsd', 'reload');
    }
    if (-s '/etc/sysconfig/i18n') {
        lang::set($o->{locale} = lang::read('', 0)); #- read ~/.i18n first if it exists
    }

    touch '/var/run/rebootctl';

drakx_stuff:
    $o->{steps}{$_} = { reachable => 1, text => $_ }
      foreach qw(initGraphical autoSelectLanguage verifyKey configMove startMove);
    $o->{orderedSteps_orig} = $o->{orderedSteps};
    $o->{orderedSteps} = [ $using_existing_host_config ?
                           qw(initGraphical verifyKey startMove)
                         : $using_existing_user_config ?
                           qw(initGraphical autoSelectLanguage verifyKey selectMouse selectKeyboard configMove startMove)
                         : qw(initGraphical selectLanguage acceptLicense verifyKey selectMouse selectKeyboard configMove startMove) ];
    $o->{steps}{first} = $o->{orderedSteps}[0];

    #- do not use shadow passwords since pwconv overwrites /etc/shadow hence contents will be lost for usb key
    delete $o->{authentication}{shadow};

    foreach my $lang (keys %lang::langs) {
	my $clp_name = lang2move_clp_name($lang) or next;
	if (! -e "/cdrom/live_tree_$clp_name.clp") {
	    log::l("disabling lang $lang");
	    delete $lang::langs{$lang};
	}
    }
}

sub lomount_clp {
    my ($name, $needed_file) = @_;
    my ($clp, $dir) = ("/cdrom/live_tree_$name.clp", "/image_$name");

    -e "$dir$needed_file" and return;

    if (! -e $clp || cat_('/proc/cmdline') =~ /\blive\b/) {
	symlink "/cdrom/live_tree_$name", $dir;
	return;
    }

    log::l("lomount_clp: lomounting $name");

    mkdir_p($dir);
    my $dev = devices::find_free_loop();
    run_program::run('losetup', '-r', '-e', 'gz', $dev, $clp);
    run_program::run('mount', '-r', $dev, $dir);
}

sub install2::autoSelectLanguage {
    my $o = $::o;

    install_steps::selectLanguage($o);
}

sub handleI18NClp {
    my ($lang) = @_;

    my $clp_name = lang2move_clp_name($lang) or return;
    log::l("move: handleI18NClp (lang=$lang, clp_name=$clp_name)");
    lomount_clp($clp_name, '/usr');
    lomount_clp("always_$clp_name", '/usr');
}

sub clean_partition_table_and_format_key {
    my ($in) = @_;
    my @keys = grep { detect_devices::isKeyUsb($_) } detect_devices::getSCSI() or return;
    my $key = $in->ask_from_listf('', N("Which USB key do you want to format?"),
				 sub { "$_->{usb_description} ($_->{device})" },
				 \@keys);

    $in->ask_warn('', N("You are about to format a USB device \"%s\". This will delete all data on it.
Make sure that the selected device is the USB key you want to format. 
We advise you to unplug all other USB storage devices while doing this operation.", $key->{usb_description}));

    $key->{prefix} ||= $key->{device};
    add2hash_($key, partition_table::raw::get_geometry($key->{file} = devices::make($key->{device})));
    partition_table::raw::zero_MBR($key);
    my ($part) = partition_table::get_normal_parts_and_holes($key);
    $part->{type} = 0xb;
    partition_table::add($key, $part);
    partition_table::write($key);
    fs::real_format_part($part);	
}

sub key_parts {
    my ($o) = @_;

    return () if $key_disabled;

    my @keys = grep { detect_devices::isKeyUsb($_) } @{$o->{all_hds}{hds}};
    my @parts = (fsedit::get_fstab(@keys), grep { detect_devices::isKeyUsb($_) } @{$o->{all_hds}{raw_hds}});
    grep { isFat({ type => fsedit::typeOfPart($_->{device}) }) } @parts;
}
    
sub key_mount {
    my ($o, $o_reread) = @_;

    if ($o_reread) {
        $o->{all_hds} = fsedit::empty_all_hds();
        install_any::getHds($o, $o);
    }
    if ($virtual_key_part) {
        #- :/ merge_from_mtab did not got my virtual key, need to add it manually
        push @{$o->{fstab}}, $virtual_key_part;
	$key_part = $virtual_key_part;
	return;
    }

    foreach (key_parts($o)) {
	if ($key_part) {
	    log::l("trying another usb key partition than $key_part->{device}");
	    fs::umount_part($key_part);
	    delete $key_part->{mntpoint};
	    undef $key_part;
	}
	$_->{mntpoint} = '/home';
	$_->{options} = "$key_mountopts,sync";
	my $ok = eval { fs::mount_part($_); 1 };
	if ($ok) {
	    my ($kb_size) = MDK::Common::System::df('/home');
	    log::l("$_->{device} is $kb_size KB");
	    $ok = $kb_size > 10 * 1024; #- at least 10 MB
	    fs::umount_part($_) if !$ok;
	}
	if ($ok) {
	    $key_part = $_;
	    last if -e $key_sysconf;
	} else {
	    delete $_->{mntpoint};
	}
    } 

    
}

sub machine_ident() {
    #- , c::get_hw_address('eth0');       before detect of network :(
    md5_hex(join '', (map { (split)[1] } cat_('/proc/bus/pci/devices')));
}

sub key_installfiles {
    my ($mode) = @_;

    my $done if 0;
    $done and return;

    mkdir $key_sysconf;
    my $sysconf = "$key_sysconf/" . machine_ident();

    my $copy_userinfo = sub {
        my (@files) = @_;
        my @etcpasswords = glob("$key_sysconf/*/etc/passwd");
        if (@etcpasswords > 1) {
            print "inconsistency: more than one /etc/passwd on key! can not proceed, please clean the key\n";
            exit 1;
        }
        return if !@etcpasswords;
        my ($path) = $etcpasswords[0] =~ m|(.*)/etc/passwd|;
        run_program::run('cp', '-f', "$path$_", $_) foreach @files;
        run_program::run('rm', '-f', $etcpasswords[0]);
    };

    if (!-d $sysconf) {
        if ($mode eq 'full') {
            log::l("key_installfiles: installing config files in $sysconf");
            mkdir $sysconf;
            foreach (chomp_(cat_('/image/move/keyfiles'))) {
                mkdir_p($sysconf . dirname($_));
                my @l = /\*$/ ? glob_($_) : $_;
		foreach (@l) {
		    eval { cp_f($_, "$sysconf$_") };
                    symlinkf("$sysconf$_", $_);
                }
            }
            eval { cp_f('/image/move/README.adding.more.files', $key_sysconf) };
            $done = 1;
        } else {
            #- not in full mode and no host directory, grab user config from first existing host directory if possible
            log::l("key_installfiles: only looking for user config files");
            $copy_userinfo->(qw(/etc/passwd /etc/group /etc/sysconfig/i18n));
        }
    } else {
        log::l("key_installfiles: installing symlinks to key");
        if (!-e "$sysconf/etc/passwd") {
            log::l("key_installfiles: /etc/passwd not here, trying to copy from previous host boot");
            $copy_userinfo->(qw(/etc/passwd /etc/group));
        }
        foreach (chomp_(`find $sysconf -type f`)) {
            my ($path) = /^\Q$sysconf\E(.*)/;
            mkdir_p(dirname($path));
            symlinkf($_, $path);
        }
        $done = 1;
        $::o->{steps}{configMove}{done} = 1;
    }

    #- /etc/sudoers can not be a link
    unlink($_), cp_f("/image$_", $_) foreach qw(/etc/sudoers);
}

sub reboot() {
    output('/var/run/rebootctl', "reboot");  #- tell X_move to not respawn
    run_program::run('killall', 'X');  #- kill it ourselves to be sure that it will not lock console when killed by our init
    exit 0;
}


sub check_key {
    my ($o) = @_;

    if ($key_part) {
	my $tmp = '/home/.touched';
	#- can we write?
	if (eval { output($tmp, 'foo'); cat_($tmp) eq 'foo' && unlink $tmp }) {
	    return 1;
	}

	#- argh, key is read-only
	#- try umounting
	if (eval { fs::umount_part($key_part); undef $key_part; 1 }) {
	    modules::unload('usb-storage');  #- it will not notice change on write protection otherwise :/

	    $o->ask_okcancel_({ title => N("Key is not writable"), 
				messages => formatAlaTeX(
N("The USB key seems to have write protection enabled. Please
unplug it, remove write protection, and then plug it again.")),
				ok => N("Retry"),
				cancel => N("Continue without USB key") }) or return;

	    modules::load('usb-storage');
	    sleep 2;
	} else {
	    #- this case happens when the user boots with a write-protected key containing
	    #- all user and host data, /etc/X11/X which is on key busyfies it
	    $o->ask_okcancel_({ title => N("Key is not writable"), 
				messages => formatAlaTeX(
N("The USB key seems to have write protection enabled, but we can not safely
unplug it now.


Click the button to reboot the machine, unplug it, remove write protection,
plug the key again, and launch Mandrake Move again.")),
				ok => N("Reboot") });
	    reboot();
	}
    } else {
	my $message = key_parts($o) ? 
N("Your USB key does not have any valid Windows (FAT) partitions.
We need one to continue (beside, it's more standard so that you
will be able to move and access your files from machines
running Windows). Please plug in an USB key containing a
Windows partition instead.


You may also proceed without an USB key - you'll still be
able to use Mandrake Move as a normal live Mandrake
Operating System.") :
N("We did not detect any USB key on your system. If you
plug in an USB key now, Mandrake Move will have the ability
to transparently save the data in your home directory and
system wide configuration, for next boot on this computer
or another one. Note: if you plug in a key now, wait several
seconds before detecting again.


You may also proceed without an USB key - you'll still be
able to use Mandrake Move as a normal live Mandrake
Operating System.");
	$o->ask_okcancel_({ title => N("Need a key to save your data"), 
			    messages => formatAlaTeX($message),
			    ok => N("Detect USB key again"),
			    cancel => N("Continue without USB key") }) or return;

    }
    key_mount($o, 'reread');
    check_key($o);
}

sub install2::verifyKey {
    my $o = $::o;

    log::l("automatic transparent key support is disabled"), return if $key_disabled;

    if (cat_('/proc/cmdline') =~ /\bformatkey\b/) {
	clean_partition_table_and_format_key($o);
	key_mount($o, 'reread');
    }

    check_key($o) or return;

    my $_wait = $using_existing_host_config
                || $o->wait_message(N("Setting up USB key"), N("Please wait, setting up system configuration files on USB key..."));

    if (eval { fs::umount_part($key_part); 1 }) {
	log::l("remounting without sync option");
	$key_part->{options} = $key_mountopts;
	fs::mount_part($key_part);
    }

    key_installfiles('full');

    setup_userconf($o);
}

sub enable_service {
    run_program::run('/sbin/chkconfig', '--level', 5, $_[0], 'on');
}

sub install2::configMove {
    my $o = $::o;

    #- just in case
    lomount_clp("always_i18n_$o->{locale}{lang}", '/usr');

    if (!$using_existing_user_config) {
        if (cat_('/proc/cmdline') =~ /\buser=(\w+)/) {
            $o->{users} = [ { name => $1 } ];
        } else {
            require any;
            any::ask_user_one($o, $o->{users} ||= [], $o->{security},
                              additional_msg => N("Enter your user information, password will be used for screensaver"), noaccept => 1, needauser => 1, noicons => 1);
        }
        #- force uid/gid to 501 as it was used when mounting key, addUser may choose 502 when key already holds user data
        put_in_hash($o->{users}[0], { uid => 501, gid => 501 });
        require install_steps;
        install_steps::addUser($o);
    }

    $::noauto and goto after_autoconf;

    my $_wait = $o->wait_message(N("Auto configuration"), N("Please wait, detecting and configuring devices..."));

    #- automatic printer, timezone, network configs
    require install_steps_interactive;
    if (cat_('/proc/mounts') !~ /nfs/) {
        install_steps_interactive::configureNetwork($o);
	touch('/etc/resolv.conf');
        enable_service('network');
    }
    enable_service('netfs');
    install_steps_interactive::summaryBefore($o);

    modules::load_category('multimedia/sound');
    enable_service('sound');

    detect_devices::isLaptop() or enable_service('numlock');

after_autoconf:
    require timezone;
    timezone::write($o->{timezone});

    $o->{useSupermount} = 'magicdev';
    fs::set_removable_mntpoints($o->{all_hds});    
    fs::set_all_default_options($o->{all_hds}, %$o, lang::fs_options($o->{locale}));

    require install_any;
    install_any::write_fstab($o);

    modules::write_conf();
    require mouse;
    mouse::write_conf($o, $o->{mouse}, 1);  #- write xfree mouse conf
    detect_devices::install_addons('');

    {
	my $user = $o->{users}[0]{name};
	my $confdir = "/home/$user/.kde/share/config";
	mkdir_p($confdir);
	output("$confdir/kdeglobals", cat_("/usr/share/config/kdeglobals"));
	lang::configure_kdeglobals($o->{locale}, $confdir);

        run_program::run('chown', '-R', "$user.$user", "/home/$user/.kde");
    }

    foreach my $step (@{$o->{orderedSteps_orig}}) {
        next if member($step, @{$o->{orderedSteps}});
        while (my $f = shift @{$o->{steps}{$step}{toBeDone} || []}) {
            log::l("doing remaining toBeDone for undone step $step");
            eval { &$f() };
            $o->ask_warn(N("Error"), [
N("An error occurred, but I do not know how to handle it nicely.
Continue at your own risk."), formatError($@) ]) if $@;
        }
    }
}

sub install_TrueFS_in_home {
    my ($o) = @_;

    my $home = fsedit::mntpoint2part('/home', $o->{fstab}) or return;

    my %loopbacks = map {
	my $part = { 
		type => 0x83, 
		device => "/home/.mdkmove-$_",
	        loopback_file => "/.mdkmove-$_", loopback_device => $home,
		mntpoint => "/home/$_/.mdkmove-truefs", size => 6 << 11,
		toFormat => ! -e "/home/.mdkmove-$_",
	};
	$_ => $part;
    } list_users();
    $home->{loopback} = [ values %loopbacks ];
    fsedit::recompute_loopbacks($o->{all_hds});
    fs::formatMount_all([], $home->{loopback}, $o->{prefix});

    foreach my $user (keys %loopbacks) {
	my $dir = $loopbacks{$user}{mntpoint};

	foreach (qw(.kde .openoffice)) {
	    if (-d "/home/$user/$_" && ! -d "$dir/$_") {
		run_program::run('mv', "/home/$user/$_", "$dir/$_");
	    }
	    mkdir $_ foreach "/home/$user/$_", "$dir/$_";

	    run_program::run('mount', '-o', 'bind', "$dir/$_", "/home/$user/$_");
	}

	my $cache = "/tmp/.$user-cache";
	foreach (qw(.kde/share/cache)) {
	    mkdir_p("$cache/$_");
	    mkdir_p("/home/$user/" . dirname($_));
	    symlink "$cache/$_", "/home/$user/$_";
	}
        run_program::run('chown', '-R', "$user.$user", $dir);
        run_program::run('chown', '-R', "$user.$user", $cache);

	$ENV{XAUTHORITY} = "$dir/.Xauthority";
	$ENV{ICEAUTHORITY} = "$dir/.ICEauthority";
    }
}

sub errorInStep {
    my ($o, $err) = @_;

    if (!fsedit::mntpoint2part('/home', $o->{fstab})) {