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
|
package install_any;
use diagnostics;
use strict;
use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK);
@ISA = qw(Exporter);
%EXPORT_TAGS = (
all => [ qw(getNextStep spawnSync spawnShell addToBeDone) ],
);
@EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
#-######################################################################################
#- misc imports
#-######################################################################################
use common qw(:common :system);
use commands;
use run_program;
use detect_devices;
use pkgs;
use log;
#-######################################################################################
#- Functions
#-######################################################################################
sub relGetFile($) {
local $_ = $_[0];
my $dir = m|/| ? "mdkinst" :
(member($_, qw(compss compssList depslist hdlist)) ? "base" : "RPMS");
$_ = "Mandrake/$dir/$_";
s/i386/i586/;
$_;
}
sub getFile($) {
local $^W = 0;
if ($::o->{method} && $::o->{method} eq "ftp") {
require 'ftp.pm';
*install_any::getFile = \&ftp::getFile;
} else {
*install_any::getFile = sub($) {
open getFile, "/tmp/rhimage/" . relGetFile($_[0]) or return;
\*getFile;
};
}
goto &getFile;
}
sub kernelVersion {
local $_ = readlink("$::o->{prefix}/boot/vmlinuz") || $::testing && "vmlinuz-2.2.testversion" or die "I couldn't find the kernel package!";
first(/vmlinuz-(.*)/);
}
sub getNextStep {
my ($s) = $::o->{steps}{first};
$s = $::o->{steps}{$s}{next} while $::o->{steps}{$s}{done};
$s;
}
sub spawnSync {
return if $::o->{localInstall} || $::testing;
fork and return;
while (1) { sleep(30); sync(); }
}
sub spawnShell {
return if $::o->{localInstall} || $::testing;
-x "/bin/sh" or die "cannot open shell - /usr/bin/sh doesn't exist";
fork and return;
local *F;
sysopen F, "/dev/tty2", 2 or die "cannot open /dev/tty2 -- no shell will be provided";
open STDIN, "<&F" or die '';
open STDOUT, ">&F" or die '';
open STDERR, ">&F" or die '';
close F;
c::setsid();
ioctl(STDIN, c::TIOCSCTTY(), 0) or warn "could not set new controlling tty: $!";
exec {"/bin/sh"} "-/bin/sh" or log::l("exec of /bin/sh failed: $!");
}
sub shells($) {
my ($o) = @_;
my @l = grep { -x "$o->{prefix}$_" } @{$o->{shells}};
@l ? @l : "/bin/bash";
}
sub getAvailableSpace {
my ($o) = @_;
do { $_->{mntpoint} eq '/usr' and return $_->{size} * 512 } foreach @{$o->{fstab}};
do { $_->{mntpoint} eq '/' and return $_->{size} * 512 } foreach @{$o->{fstab}};
if ($::testing) {
log::l("taking 2000MB for testing");
return 2000 << 20;
}
die "missing root partition";
}
sub setPackages($$) {
my ($o, $install_classes) = @_;
if ($o->{packages}) {
$_->{selected} = 0 foreach values %{$o->{packages}};
} else {
my $useHdlist = $o->{method} !~ /nfs|hd/;
eval { $o->{packages} = pkgs::psUsingHdlist() } if $useHdlist;
$o->{packages} = pkgs::psUsingDirectory() if !$useHdlist || $@;
pkgs::getDeps($o->{packages});
$o->{compss} = pkgs::readCompss($o->{packages});
$o->{compssListLevels} = pkgs::readCompssList($o->{packages}, $o->{compss});
$o->{compssListLevels} ||= $install_classes;
push @{$o->{base}}, "kernel-smp" if detect_devices::hasSMP();
push @{$o->{base}}, "kernel-pcmcia-cs" if $o->{pcmcia};
}
unless ($o->{isUpgrade}) {
do {
my $p = $o->{packages}{$_} or log::l("missing base package $_"), next;
pkgs::select($o->{packages}, $p, 1);
} foreach @{$o->{base}};
}
pkgs::setShowFromCompss($o->{compss}, $o->{installClass}, $o->{lang});
($o->{packages_}{ind}, $o->{packages_}{select_level}) = pkgs::setSelectedFromCompssList($o->{compssListLevels}, $o->{packages}, getAvailableSpace($o) * 0.7, $o->{installClass}, $o->{lang}, $o->{isUpgrade});
}
sub selectPackagesToUpgrade($) {
my ($o) = @_;
pkgs::selectPackagesToUpgrade($o->{packages}, $o->{prefix});
}
sub addToBeDone(&$) {
my ($f, $step) = @_;
return &$f() if $::o->{steps}{$step}{done};
push @{$::o->{steps}{$step}{toBeDone}}, $f;
}
sub install_cpio {
my ($dir, $name) = @_;
return "$dir/$name" if -e "$dir/$name";
my $cpio = "$dir.cpio.bz2";
-e $cpio or return;
eval { commands::rm("-r", $dir) };
mkdir $dir, 0755;
run_program::run("cd $dir ; bzip2 -cd $cpio | cpio -id $name $name/*");
"$dir/$name";
}
|