forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.cgi
executable file
·137 lines (121 loc) · 3.61 KB
/
install.cgi
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
#!/usr/local/bin/perl
# install.cgi
# Install a downloaded perl module
require './cpan-lib.pl';
&ReadParse();
@pfile = split(/\0/, $in{'pfile'});
if ($in{'need'}) {
# Some pre-reqs are needed .. return to the download form
@cpan = ( split(/\0/, $in{'needreq'}), split(/\0/, $in{'mod'}) );
unlink(@pfile); # will re-get
&redirect("download.cgi?source=3&cpan=".&urlize(join(" ", @cpan)));
}
foreach $pfile (@pfile) {
-r $pfile || &error(&text('install_efile', "<tt>$pfile</tt>"));
}
&ui_print_unbuffered_header(undef, $text{'install_title'}, "");
# Set environment variables
for($i=0; defined($in{"name_$i"}); $i++) {
if ($in{"name_$i"} ne "") {
$ENV{$in{"name_$i"}} = $in{"value_$i"};
}
}
# Go through all the modules
@mods = split(/\0/, $in{'mod'});
@dirs = split(/\0/, $in{'dir'});
$perl_path = &get_perl_path();
for($i=0; $i<@mods; $i++) {
print &text('install_doing_'.$in{'act'}, "<tt>$mods[$i]</tt>"),"<p>\n";
# Untar the perl module
$mod_dir = &transname($dirs[$i]);
($mod_par = $mod_dir) =~ s/\/[^\/]+$//;
system("rm -rf $mod_dir >/dev/null 2>&1");
&show_output($text{'install_untar'}, $mod_par,
"gunzip -c $pfile[$i] | tar xvf -");
if (-r "$mod_dir/Makefile.PL") {
# Run Makefile.PL and make
&show_output($text{'install_make'}, $mod_dir,
"$perl_path Makefile.PL $in{'args'} && make") ||
&build_error();
# Run make test (if requested)
if ($in{'act'} == 1 || $in{'act'} == 3) {
&show_output($text{'install_test'}, $mod_dir,
"make test") || &build_error();
}
# Run make install (if requested)
if ($in{'act'} == 2 || $in{'act'} == 3) {
&show_output($text{'install_install'}, $mod_dir,
"make install") || &build_error();
}
}
else {
# Run Build.PL and Build
&show_output($text{'install_make'}, $mod_dir,
"$perl_path Build.PL $in{'args'} && ./Build") ||
&build_error();
# Run Build test (if requested)
if ($in{'act'} == 1 || $in{'act'} == 3) {
&show_output($text{'install_test'}, $mod_dir,
"./Build test") || &build_error();
}
# Run Build install (if requested)
if ($in{'act'} == 2 || $in{'act'} == 3) {
&show_output($text{'install_install'}, $mod_dir,
"./Build install") || &build_error();
}
}
# Clean up files
print "<p>",&text('install_done_'.$in{'act'}, "<tt>$mods[$i]</tt>"),
"<p>\n";
system("rm -rf $mod_dir") if ($mod_dir && -d $mod_dir);
}
&clean_up(1);
# clean_up(success)
sub clean_up
{
system("rm -rf $mod_dir") if ($mod_dir && -d $mod_dir);
unlink(@pfile) if ($in{'need_unlink'} && (!$config{'save_partial'} || $_[0]));
&ui_print_footer($in{'return'}, $in{'returndesc'} || $text{'index_return'});
}
# show_output(desc, dir, command)
sub show_output
{
local (%seen, $endless_loop);
print &ui_table_start($_[0], undef, 2);
local $msg = "<pre>".&text('install_exec', $_[2])."\n";
$msg .= (" " x 100)."\n";
open(CMD, "(cd $_[1] ; $_[2]) 2>&1 </dev/null |");
while(<CMD>) {
if ($seen{$_}++ > 100) {
$endless_loop = 1;
$msg .= "\n$text{'install_loop'}\n";
last;
}
while(length($_) > 100) {
s/^(.{100})//;
$msg .= &html_escape($1)."\n";
}
$msg .= &html_escape($_);
}
close(CMD);
$msg .= "</pre>";
print &ui_table_row(undef, $msg, 2);
print &ui_table_end();
return $? || $endless_loop ? 0 : 1;
}
sub build_error
{
print "<p>",&text('install_err', "<tt>$mods[$i]</tt>"),"<br>\n";
if ($in{'source'} == 3) {
print &text('install_err2', "<tt>perl -MCPAN -e shell</tt>"),"\n";
}
print "<p>\n";
if ($in{'need_unlink'} && $config{'save_partial'}) {
# File needs to be deleted
print &text('install_needunlink',
"delete_file.cgi?".
join("&", map { "file=".&urlize($_) } @pfile)),"<p>\n";
}
&clean_up(0);
exit;
}