#!/usr/bin/perl #- Mandriva cryptographic package hdlist and depslist generation tools. #- Copyright (C) 1999-2005 Mandriva (fpons@mandriva.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. #- usage: gencryptofiles #- build an hdlist and depslist file for crypto, need rpmtools also. my %resolver = ( '/bin/sh' => 'bash', '/bin/bash' => 'bash', '/usr/bin/perl' => 'perl', '/usr/bin/perl5' => 'perl', 'libBrokenLocale.so' => 'glibc', 'libICE.so' => 'XFree86-libs', 'libSM.so' => 'XFree86-libs', 'libX11.so' => 'XFree86-libs', 'libXext.so' => 'XFree86-libs', 'libXmu.so' => 'XFree86-libs', 'libXpm.so' => 'xpm', 'libXt.so' => 'XFree86-libs', 'libc.so.6' => 'glibc', 'libgdbm.so' => 'gdbm', 'libgpm.so' => 'gpm', 'libm.so' => 'glibc', 'libncurses.so' => 'ncurses', 'libnsl.so' => 'glibc', 'libpam.so' => 'pam', 'libpthread.so' => 'glibc', 'libreadline.so' => 'readline', 'libstdc++-libc6.1-2.so' => 'libstdc++', 'libstdc++.so' => 'libstdc++-compat', 'libutil.so' => 'glibc', 'libz.so' => 'zlib', 'smtpdaemon' => 'postfix', ); sub gendepslist_crypto { my ($dir) = @_; my %depslist; #- get information about each rpm. local *DIR; opendir DIR, $dir or die "cannot open directory: $!\n"; while ($_ = readdir DIR) { my ($key) = /(.*)\..*\.rpm$/ or next; my ($name) = /(.*)-[^-]*-[^-]*-/; my $size = `rpm -qp --queryformat="%{SIZE}" $dir/$_`; my @filelist = split "\n", `rpm -qpl $dir/$_`; my @requires = split "\n", `rpm -qpR $dir/$_`; $depslist{$key} = { key => $key, size => $size, filelist => \@filelist, requires => \@requires, deps => [], }; foreach (@filelist) { $resolver{$_} = $name; m|.*/([^/]*)$| and $resolver{$1} = $name; } } close DIR; #- resolve the dependancies. foreach my $pkg (values %depslist) { foreach (@{$pkg->{requires}}) { $resolver{$_} and push(@{$pkg->{deps}}, $resolver{$_}), next; m|^([^\s\(]*)| and $resolver{$1} and push(@{$pkg->{deps}}, $resolver{$1}), next; m|^.*/([^/\s\(]*)| and $resolver{$1} and push(@{$pkg->{deps}}, $resolver{$1}), next; m|^([^\s\(]*\.so)| and $resolver{$1} and push(@{$pkg->{deps}}, $resolver{$1}), next; m|^.*/([^\s\(]*\.so)| and $resolver{$1} and push(@{$pkg->{deps}}, $resolver{$1}), next; m|^([\w-]*)(?:\s+.*)$| and push(@{$pkg->{deps}}, $1); #- last and default to package name. } } #- build depslist-crypto file. local *F; open F, ">$dir/depslist-crypto" or die "cannot open depslist-crypto file for writing: $!\n"; foreach (values %depslist) { my %deps; @deps{@{$_->{deps}}} = (); print F "$_->{key} $_->{size} ", join(" ", keys %deps), "\n"; } close F; } sub main { my ($dir) = @_; -d $dir or die "usage: gencryptofiles \n"; -x "/usr/bin/genhdlist_cz2" or die "I need rpmtools to work (ie /usr/bin/genhdlist_cz2)\n"; print `genhdlist_cz2 -o $dir/hdlist-crypto.cz2 $dir`; gendepslist_crypto($dir); } main(@ARGV); p Mageia Installer and base platform for many utilitiesThierry Vignaud [tv]
summaryrefslogtreecommitdiffstats
blob: e65ee06764e8b35afbf5c1b5ef4367f28a9166fd (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
package raid; # $Id: raid.pm 269279 2010-05-24 14:12:09Z pterjan $

use diagnostics;
use strict;

#-######################################################################################
#- misc imports
#-######################################################################################
use common;
use fs::type;
use fs::get;
use run_program;
use devices;
use modules;

sub max_nb() { 31 }

sub check_prog {
    # perl_checker: require interactive
    my ($in) = @_; # perl_checker: $in = interactive->new
    $::prefix ? whereis_binary('mdadm') : $in->do_pkgs->ensure_binary_is_installed('mdadm', 'mdadm');
}

sub new {
    my ($raids, %opts) = @_;
    my $md_part = { %opts };
    add2hash_($md_part, { 'chunk-size' => '64', disks => [], 
			  fs_type => defaultFS(),
			  device => first(free_mds($raids)), 
			  notFormatted => 1, level => 1 });
    push @$raids, $md_part;
    foreach (@{$md_part->{disks}}) {
	$_->{raid} = $md_part->{device};
	fs::type::set_pt_type($_, 0xfd);
	delete $_->{mntpoint};
    }
    update($md_part);
    $md_part;
}

sub add {
    my ($md_part, $part) = @_;
    $md_part->{isMounted} and die N("Cannot add a partition to _formatted_ RAID %s", $md_part->{device});
    inactivate_and_dirty($md_part);
    set_isFormatted($part, 0);
    $part->{raid} = $md_part->{device};
    delete $part->{mntpoint};
    push @{$md_part->{disks}}, $part;
    update($md_part);
}

sub delete {
    my ($raids, $md_part) = @_;
    inactivate_and_dirty($md_part);
    delete $_->{raid} foreach @{$md_part->{disks}};
    @$raids = grep { $_ != $md_part } @$raids;
    write_conf($raids) if $::isStandalone;
}

sub change_device {
    my ($md_part, $new_device) = @_;
    if ($new_device ne $md_part->{device}) {
	inactivate_and_dirty($md_part);
	$md_part->{device} = $new_device;
	$_->{raid} = $new_device foreach @{$md_part->{disks}};
    }
}

sub removeDisk {
    my ($raids, $part) = @_;
    my $md_part = fs::get::device2part($part->{raid}, $raids);
    inactivate_and_dirty($md_part);
    fs::type::set_isFormatted($part, 0);
    delete $part->{raid};
    my $disks = $md_part->{disks};
    @$disks = grep { $_ != $part } @$disks;
    if (@$disks) {
	update($md_part);
    } else {
	@$raids = grep { $_ != $md_part } @$raids;
    }
    write_conf($raids) if $::isStandalone;
}

sub updateSize {
    my ($part) = @_;
    local $_ = $part->{level};
    my @l = map { $_->{size} } @{$part->{disks}};

    $part->{size} = do {
	if (/0|linear/) { sum @l }
	elsif (/1/)     { min @l }
	elsif (/4|5/)   { min(@l) * (@l - 1) }
	elsif (/6/)     { min(@l) * (@l - 2) }
	elsif (/10/)	{ min(@l) * (@l / 2) }
    };
}

sub allmodules {
    ('raid0', 'raid1', 'raid10', 'raid456');
}

sub module {
    my ($part) = @_;
    my $level = $part->{level};
    log::l("level $level");

    if (member($level, 4, 5, 6)) {
	'raid456';
    } elsif (member($level, 10)) {
	'raid10';
    } elsif ($level =~ /^\d+$/) {
	"raid$level";
    } else {
	$level;
    }
}


sub update {
    updateSize($_) foreach @_;
}

sub make {
    my ($raids, $part) = @_;    

    return if is_active($part->{device});

    inactivate_and_dirty($part);

    isRAID($_) and make($raids, $_) foreach @{$part->{disks}};
    eval { modules::load(module($part)) };

    whereis_binary('mdadm') or die 'mdadm not installed';

    my $dev = devices::make($part->{device});
    my $nb = @{$part->{disks}};

    run_program::run_or_die('mdadm', '--create', '--run', $dev, 
			    if_($nb == 1, '--force'),
			    '--chunk=' . $part->{'chunk-size'}, 
			    "--level=$part->{level}", 
			    "--raid-devices=$nb",
			    if_($part->{metadata}, "--metadata=$part->{metadata}"),
			    map { devices::make($_->{device}) } @{$part->{disks}});

    if (my $raw_part = get_md_info($dev)) {
	$part->{UUID} = $raw_part->{UUID};
    }
    write_conf($raids) if $::isStandalone;
}

sub format_part {
    my ($raids, $part) = @_;
    $part->{isFormatted} and return;

    make($raids, $part);
    fs::format::part_raw($part, undef);
    set_isFormatted($_, 1) foreach @{$part->{disks}};
}

sub verify {
    my ($raids) = @_;
    foreach (@$raids) {
	my $nb = $_->{level} =~ /6|10/ ? 4 : $_->{level} =~ /4|5/ ? 3 : 2;
	@{$_->{disks}} >= $nb or die N("Not enough partitions for RAID level %d\n", $_->{level});
    }
}

sub inactivate_and_dirty {
    my ($part) = @_;
    run_program::run('mdadm', '--stop', devices::make($part->{device}));
    set_isFormatted($part, 0);
}

sub active_mds() {
    map { if_(/^(md\S+)\s*:\s*active/, $1) } cat_("/proc/mdstat");
}
sub inactive_mds() {
    map { if_(/^(md\S+)\s*:\s*inactive/, $1) } cat_("/proc/mdstat");
}

sub free_mds {
    my ($raids) = @_;
    difference2([ map { "md$_" } 0 .. max_nb() ], [ map { $_->{device} } @$raids ]);
}

sub detect_during_install {
    my (@parts) = @_;
    eval { modules::load($_) } foreach allmodules();

    # udev may have started raids but failed due to not yet loaded modules and
    # they remains inactive ("md: personality for level 1 is not loaded!")
    stop_inactive_mds();

    detect_during_install_once(@parts);