summaryrefslogtreecommitdiffstats
path: root/rescue/make_rescue_img
blob: d0248c052c46d620f87771396141bc143f02b305 (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
#!/usr/bin/perl

use lib "../perl-install";
use keyboard;
use common;

use Config;
Config->import;
my ($arch) = $Config{archname} =~ /(.*)-/;

$tmp = "/tmp/rescue_tmp";
$mnt = "/tmp/rescue_stage2_img";
$mke2fs = "/sbin/mke2fs -q -m 0 -F -s 1";
$rescue = "rescue_stage2";

if ($>) {
    $sudo = "sudo";
    $ENV{PATH} = "/sbin:/usr/sbin:$ENV{PATH}";
}

BEGIN { undef *_; }
sub __ { print @_, "\n"; system(@_); }
sub _ { __ @_; $? and die; }

sub install_ {
    return if -e "$tmp$_[0]";
    my $d = dirname($_[0]);
    commands::mkdir_("-p", "$tmp$d") unless -d "$tmp$d";
    _ "$sudo cp $_[1] $_[0] $tmp$d";
}
sub install_lib { install_($_[0], "") }
sub install { grep {/lib\w+.so/} @_ and install_lib(@_) or install_($_[0], "-a") }

sub installown($$) {
    my ($own, $dir) = @_;
    return if -e "$tmp$dir$own";
    commands::mkdir_("-p", "$tmp$dir") unless -d "$tmp$dir";
    _ "$sudo cp -a $own $tmp$dir";
}

_ "$sudo rm -rf $tmp" if -e $tmp;
_ "mkdir $tmp";
_ 'find . -name "*~" | xargs rm -f';
foreach (cat_("dirs")) {
    chomp;
    commands::mkdir_("-p", "$tmp$_");
}
_ "cp -a tree/* $tmp";
_ "find $tmp -name 'CVS*' | xargs rm -rf";

foreach (keyboard::loadkeys_files) {
    install($_);
    symlink "$2.kmap.gz", "$tmp$1/$3.kmap.gz" if m|(.*)/((..).+)\.kmap\.gz|;
}
unlink "$tmp/usr/lib/kbd/keymaps/i386/qwertz/fr.kmap.gz";

my $perl_version = join ".", unpack "C3", $^V;
@files = map { chomp; s/PERL_VERSION/$perl_version/g; $_ } (cat_("list"), cat_(`../tools/specific_arch list`));
`ls @files`; 
$? == 0 or exit 1;

foreach (@files) {
    install($_);
    chomp, install_lib($_) foreach `ldd $_ 2>/dev/null | grep "=>" | sed -e 's/.*=> //' -e 's/ .*//'`;
}
foreach (cat_("aliases")) {
    chomp; my ($f, $dest) = split;
    symlink $dest, "$tmp$f";
}

chomp($main = `cat ../all.kernels/.main`);

_ "cp ../all.modules/modules.cz-$main $tmp/modules/modules.cz";
_ "cp ../all.modules/$main/modules.dep $tmp/modules";

installown("drvinst", "/usr/bin");
installown("guessmounts", "/usr/bin");

#_ "install -s kernel_read_part $tmp/sbin" if $arch =~ /i.86/;
__ "$sudo strip $tmp/{lib,bin,sbin}/* $tmp/usr/{bin,sbin}/* 2>/dev/null";

exit 0 if $ARGV[0];

$size = `du -s $tmp | cut -f1` + 2048; #- add 2MB of free space

commands::mkdir_("-p", $mnt) if !-e $mnt;
__ "$sudo umount $rescue 2>/dev/null";

_ "dd if=/dev/zero of=$rescue bs=1k count=$size";
_ "$mke2fs $rescue";
_ "$sudo mount -t ext2 $rescue $mnt -o loop";
_ "rmdir $mnt/lost+found";

_ "$sudo chown -R root.root $tmp";
_ "$sudo cp -a $tmp/* $mnt";
_ "$sudo rm -rf $tmp";

_ "$sudo umount $rescue";
_ "rmdir $mnt";

_ "bzip2 -f -9 $rescue";