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

use MDK::Common;
use lib "../perl-install";
use keyboard;

my $lib = (arch() =~ /x86_64/ ? "lib64" : "lib");
my $tmp = "/tmp/rescue_tmp";
my $rescue = "rescue.clp";

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

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

sub install_raw {
    s|^/|| foreach @_;
    _ "tar c -C / @_ | tar x -C $tmp" if @_;
}
sub install_deref {
    s|^/|| foreach @_;
    _ "tar c -C / --dereference @_ | tar x -C $tmp" if @_;
}

sub install_l {
    my @l = @_;

    @l = uniq(map { chomp_($_) } @l);
    push @l, 
      `ldd @l 2>/dev/null | grep "=>" | perl -pe 's/.*=> //; s/ .*//; s,^/(lib|lib64)/.*?/,/\\1/,'`;

    my ($deref, $raw) = partition { /lib.*\.so/ || readlink("/$_") =~ m|/etc/alternatives| } uniq(map { chomp_($_) } @l);
    install_raw(@$raw);
    install_deref(@$deref);
}

sub installown($$) {
    my ($own, $dir) = @_;
    return if -e "$tmp$dir/" . basename($own);
    mkdir_p("$tmp$dir");
    _ "cp -rL $own $tmp$dir";
}

sub install_perl_script {
    my ($script, $dir) = @_;
    my @gi_modules;
    foreach (`../tools/get-needed-drakx-modules ../perl-install /usr/lib/libDrakX $script`) {
	chomp;
	my ($local, $dest) = split "\t";
	installown($local, dirname($dest || $local));
	push @gi_modules, "$tmp$dest" if $dest;
    }    
    installown($script, $dir);
    system('../tools/simplify-drakx-modules', @gi_modules, "$tmp$dir/$script");
}

_ "$sudo rm -rf $tmp" if -e $tmp;
_ "mkdir $tmp";
_ 'find . -name "*~" | xargs rm -f';
foreach (cat_("dirs")) {
    chomp;
    mkdir_p("$tmp$_");
}
_ "cp -a tree/* $tmp";
_ "find $tmp -name 'CVS*' | xargs rm -rf";
_ "perl devices.pl $tmp/dev";
substInFile { s/DISTRIB_DESCR/$ENV{DISTRIB_DESCR}/ } "$tmp/etc/issue";

install_raw(keyboard::loadkeys_files());
my %keytable_conflicts;
my @less_important_keytables = qw(am_old am_phonetic no-dvorak fr_CH-latin1);
foreach (keyboard::loadkeys_files()) {
    my ($dir, $fname) = (dirname($_), basename($_));
    my ($name) = $fname =~ /(.*)\.kmap\.gz/ or next;
    next if member($name, @less_important_keytables);
    if (my ($short) = $name =~ m|(.+?)[\W_]|) {
	$keytable_conflicts{$short} and warn("conflict between $keytable_conflicts{$short} and $name for short name $short (choosing the first)\n"), next;
	$keytable_conflicts{$short} = $name;
	# create the short name based on the long one
	symlinkf($fname, "$tmp$dir/$short.kmap.gz");
    }
}

my $perl_version = join ".", unpack "C3", $^V;
my @bad;
my @files = map { 
    chomp;
    s/PERL_VERSION/$perl_version/g;
    s|/LIB/|/$lib/|g;
    my @l = glob($_) or push @bad, $_;
    m|\*.*/| && @l != 1 and die "multiple match for $_\n";
    @l;
} (cat_("list"), cat_(`../tools/specific_arch list`));
@bad and die "files missing\n" . join("\n", @bad) . "\n";
install_l(@files);

foreach (cat_("aliases")) {
    chomp; my ($f, $dest) = split;
    symlink $dest, "$tmp$f";
}

-e "../kernel/all.kernels" or die "use ./update_kernel in gi/kernel first\n";

my $main = chomp_(`cat ../kernel/all.kernels/.main`);

_ "cp ../kernel/all.kernels/$main/modules.{cz,dep} $tmp/modules";

installown("drvinst", "/usr/bin");
install_perl_script("guessmounts", "/usr/bin");
install_perl_script("install_bootloader", "/usr/bin");
if (arch() =~ /^i.86|x86_64/) {
    install_perl_script("restore_ms_boot", "/usr/bin");
}
install_perl_script("lsparts", "/usr/bin");
installown("rescue-doc", "/usr/bin");
_ "cd ../mdk-stage1 && make rescue-gui dhcp-client";
installown("../mdk-stage1/rescue-gui", "/usr/bin");
installown("../mdk-stage1/dhcp-client", "/usr/sbin");

#- note that on biarch systems, we may need to have both /lib and /lib64
__ "strip $tmp/{lib,$lib,bin,sbin}/* $tmp/usr/{bin,sbin}/* 2>/dev/null";

if ($ENV{PARTIMAGE_DIR}) {

    install_perl_script('partimage_whole_disk', '/usr/sbin');

    _ "rpm2cpio $ENV{PARTIMAGE_RPM} | (cd $tmp ; cpio -idu ./usr/sbin/partimage)";
    my $server = 'partimaged';
    $server = 'leia';
    substInFile {
	$_ = <<EOF if /^\s*rescue-gui/;
  if grep -q save_all /proc/cmdline; then
      drvinst NETWORK ; dhcp-client ; partimage_whole_disk save_all $ENV{PARTIMAGE_DIR} $server
      echo "Press enter"
      read
  fi
  if grep -q rest_all /proc/cmdline; then
      local=/tmp/image$ENV{PARTIMAGE_DIR}
      if [ -d \$local ]; then
          partimage_whole_disk rest_all \$local
      else
          drvinst NETWORK ; dhcp-client ; partimage_whole_disk rest_all $ENV{PARTIMAGE_DIR} $server
      fi
      echo "Press enter"
      read
  fi
EOF
    } "$tmp/etc/rc.sysinit";
}

exit 0 if $ARGV[0];

_ "mkisofs -quiet -D -R $tmp | create_compressed_fs - 65536 $rescue 200 2>/dev/null";
_ "$sudo rm -rf $tmp";