aboutsummaryrefslogtreecommitdiffstats
path: root/transfugdrake.pm
blob: 9df476437445b5e26d88fc2891850d56245d9762 (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
package transfugdrake;

use strict;
use warnings;
use common;

sub get_insensitive_path {
    my ($prefix, $path) = @_;
    my $full_path = $prefix;
    my @path_l = split("/", $path);
    foreach my $i (@path_l) {
	my $e = find { lc($_) eq lc($i) } all($full_path)
	    or return;
	$full_path .= "/" . $e;
    }
    return $full_path;
}

sub get_windows_system_path {
    my ($prefix, $suffix) = @_;
    foreach my $system (qw(WINDOWS WINNT)) {
	my $p = get_insensitive_path($prefix, join("/", $system, $suffix));
	return $p if $p;
    }
}

sub get_windows_disk() {
    require fs;
    require fs::type;

    my $all_hds = fsedit::get_hds();
    fs::get_raw_hds('', $all_hds);
    fs::get_info_from_fstab($all_hds);
    my $fstab = [ fs::get::fstab($all_hds) ];
    fs::merge_info_from_mtab($fstab);

    my @win_devices = grep { fs::type::isFat_or_NTFS($_) && fs::type::isMounted($_) } @$fstab;
    find {
	get_windows_system_path($_, "system32/config/software");
    } map { $_->{mntpoint} } @win_devices;
}

sub list_windows_users {
    my ($win_prefix) = @_;
    my @users = chomp_(split(/,\s*/, run_program::get_stdout("ma-search-users", "windowsxp", $win_prefix)));
    my ($standard, $admin) = partition { $_ ne "Administrator" } @users;
    sort(@$standard), @$admin;
}

sub list_windows_items {
    my ($win_prefix, $win_user) = @_;
    chomp_(split(/,\s*/, run_program::get_stdout("ma-search-items",
                                                 "--ostype=windowsxp",
                                                 "--path=$win_prefix",
                                                 "--user=$win_user")));
}

sub import_target {
    my ($win_prefix, $win_user, $linux_user, $target) = @_;
    my $lc_target = lc($target);
    $lc_target =~ s/\s//g;
    run_program::raw({ timeout => "never" },
                     "ma-import",
                     "--fromuser=$win_user",
                     "--frompath=$win_prefix",
                     "--touser=$linux_user",
                     "--topath=/",
                     "--target=$lc_target",
                     "--ostype=windowsxp",
    );
}

1;