mirror of
https://git.proxmox.com/git/pve-installer
synced 2025-04-28 12:51:31 +00:00
116 lines
3.0 KiB
Perl
Executable File
116 lines
3.0 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use lib '.'; # FIXME
|
|
|
|
use File::Path qw(make_path);
|
|
use Getopt::Long;
|
|
use JSON;
|
|
use Time::HiRes qw(usleep);
|
|
|
|
{
|
|
my $test_mode;
|
|
GetOptions(
|
|
'test-mode|t' => \$test_mode
|
|
) or die "usage error\n";
|
|
|
|
# FIXME: use cleaner approach for setting tet mode?
|
|
Proxmox::Install::ISOEnv::set_test_image('/dev/null') if $test_mode;
|
|
}
|
|
use Proxmox::Install::ISOEnv;
|
|
use Proxmox::Install::RunEnv;
|
|
|
|
use Proxmox::Sys::File qw(file_write_all);
|
|
|
|
use Proxmox::Log;
|
|
use Proxmox::Install::Config;
|
|
use Proxmox::UI;
|
|
|
|
my $commands = {
|
|
'dump-env' => 'Dump the current ISO and Hardware environment to base the installer UI on.',
|
|
'start-session' => 'Start an installation session, with command and result transmitted via stdin/out',
|
|
'help' => 'Output this usage help.',
|
|
};
|
|
|
|
sub usage {
|
|
my ($cmd) = @_;
|
|
|
|
if (!$cmd) {
|
|
printf("ERROR: missing command\n\n");
|
|
} elsif (!exists($commands->{$cmd})) {
|
|
printf("ERROR: unknown command '$cmd'\n\n");
|
|
}
|
|
|
|
print "USAGE: $0 <cmd>\n";
|
|
for my $cmd (sort keys $commands->%*) {
|
|
printf(" %-20s - %s\n", $cmd, $commands->{$cmd});
|
|
}
|
|
|
|
exit($cmd ne 'help' ? 1 : 0);
|
|
}
|
|
|
|
my $cmd = shift;
|
|
if (!$cmd || $cmd eq 'help' || !exists($commands->{$cmd})) {
|
|
usage($cmd // '');
|
|
}
|
|
|
|
Proxmox::Log::init("/tmp/install-low-level-${cmd}.log");
|
|
|
|
my $env = Proxmox::Install::ISOEnv::setup();
|
|
if ($cmd eq 'dump-env') {
|
|
|
|
my $out_dir = $env->{locations}->{run};
|
|
make_path($out_dir);
|
|
die "failed to create output directory '$out_dir'\n" if !-d $out_dir;
|
|
|
|
my $locales_serialized = to_json($env->{locales}, {canonical => 1, utf8 => 1}) ."\n";
|
|
file_write_all("$out_dir/locales.json", $locales_serialized);
|
|
|
|
my $iso_info = {
|
|
'iso-info' => $env->{iso},
|
|
'product' => $env->{product},
|
|
'product-cfg' => $env->{cfg},
|
|
'locations' => $env->{locations},
|
|
};
|
|
my $iso_serialized = to_json($iso_info, {canonical => 1, utf8 => 1}) ."\n";
|
|
file_write_all("$out_dir/iso-info.json", $iso_serialized);
|
|
|
|
my $run_env = Proxmox::Install::RunEnv::query_installation_environment();
|
|
my $run_env_serialized = to_json($run_env, {canonical => 1, utf8 => 1}) ."\n";
|
|
file_write_all("$out_dir/run-env-info.json", $run_env_serialized);
|
|
} elsif ($cmd eq 'start-session') {
|
|
Proxmox::UI::init_stdio({}, $env);
|
|
|
|
my $config_raw;
|
|
while(my $line = <>) {
|
|
if ($line =~ /^\s*{/) {
|
|
$config_raw = $line;
|
|
last;
|
|
}
|
|
}
|
|
my $config = eval { from_json($config_raw, { utf8 => 1 }) };
|
|
die "failed to parse config from stdin - $@\n" if $@;
|
|
|
|
Proxmox::Install::Config::merge($config);
|
|
|
|
print STDERR "got config: ". to_json(Proxmox::Install::Config::get(), { utf8 => 1, canonical => 1 }) ."\n";
|
|
|
|
my $res = Proxmox::UI::prompt("Reply anything?") ? 'ok' : 'not ok';
|
|
Proxmox::UI::message("Test Message - got $res");
|
|
|
|
for (my $i = 1; $i <= 1000; $i += 3) {
|
|
Proxmox::UI::progress($i/1000, 0, 100, "foo $i");
|
|
if ($i > 500 && $i < 600) {
|
|
usleep(50 * 1000);
|
|
} else {
|
|
usleep(10 * 1000);
|
|
}
|
|
}
|
|
|
|
# Proxmox::Install::extract_data(); # TODO
|
|
}
|
|
|
|
exit(0);
|