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
|
#!/usr/bin/perl
use MDK::Common;
sub create_light_tree {
my ($live_name, $prefix, $light_prefix, $list) = @_;
-e $light_prefix and die "you can't make_live_tree_boot since one already exists
Maybe you should remove it first with 'make_live_tree_boot -u'\n";
foreach my $orig (@$list) {
my $dest = $orig;
$dest =~ s|^$prefix|$light_prefix|;
my $link = $orig;
$link =~ s|^$prefix|/image_$live_name|;
mkdir_p(dirname($dest));
rename $orig, $dest or die "moving $orig to $dest failed: $!\n";
symlink $link, $orig or die "symlinking from $dest to $orig failed: $!\n";
}
}
sub remove_light_tree {
my ($live_name, $prefix, $light_prefix, $list) = @_;
-d $light_prefix or return;
foreach my $dest (@$list) {
my $orig = $dest;
$orig =~ s|^$prefix|$light_prefix|;
next if !-e $orig;
if (-e $dest && -s $dest != -s $orig) {
warn "ERROR: $dest already exist, skipping\n";
} elsif (!-d $dest || -l $dest) {
unlink $dest or die "removing $dest failed: $!\n";
rename $orig, $dest or die "moving $orig to $dest failed: $!\n";
}
}
rmdir($_) foreach reverse(chomp_(`find $light_prefix -type d`));
if (-e $light_prefix) {
print "still there:\n";
system('find', $light_prefix);
foreach my $dest (chomp_(`find $prefix -type l`)) {
my $orig = readlink($dest) or next;
$orig =~ s!/image_$live_name/!$light_prefix/! or next;
unlink $dest or die "removing $dest failed: $!\n";
rename $orig, $dest or die "moving $orig to $dest failed: $!\n";
}
rmdir($_) foreach reverse(chomp_(`find $light_prefix -type d`));
}
if (-e $light_prefix) {
print "still there:\n";
system('find', $light_prefix);
}
}
my $prefix = '/tmp/live_tree';
my ($boot_prefix, $always_prefix) = ('/tmp/live_tree_boot', '/tmp/live_tree_always');
my @boot_list = chomp_(cat_('data/boot.list'));
my @always_list = chomp_(cat_('data/always.list'));
@boot_list = difference2(\@boot_list, \@always_list);
remove_light_tree('boot', $prefix, $boot_prefix, \@boot_list);
remove_light_tree('always', $prefix, $always_prefix, \@always_list);
if (!@ARGV) {
create_light_tree('boot', $prefix, $boot_prefix, \@boot_list);
create_light_tree('always', $prefix, $always_prefix, \@always_list);
}
|