]> git.proxmox.com Git - pve-installer.git/blobdiff - proxmox-low-level-installer
tui: install_progress: split out reboot handling into own function
[pve-installer.git] / proxmox-low-level-installer
index 861198d626a1f6dcf13dd99ea8dbfce1088b796e..0f2bf4f68f8cc1e11d85624521bf246694726c35 100755 (executable)
@@ -8,27 +8,31 @@ use lib '.'; # FIXME
 use File::Path qw(make_path);
 use Getopt::Long;
 use JSON;
-
-use Proxmox::Sys::File qw(file_write_all);
-
-use Proxmox::Log;
-use Proxmox::Install::ISOEnv;
-use Proxmox::Install::RunEnv;
-use Proxmox::UI;
+use Time::HiRes qw(usleep);
 
 {
-    my $test_mode;
+    my $test_image;
     GetOptions(
-       'test-mode|t' => \$test_mode
+       'test-image|t=s' => \$test_image
     ) or die "usage error\n";
 
-    # FIXME: use cleaner approach for setting tet mode?
-    Proxmox::Install::ISOEnv::set_test_image('/dev/null') if $test_mode;
+    Proxmox::Install::ISOEnv::set_test_image($test_image) if $test_image;
 }
 
+use Proxmox::Install::ISOEnv;
+use Proxmox::Install::RunEnv;
+
+use Proxmox::Sys::File qw(file_write_all);
+
+use Proxmox::Log;
+use Proxmox::Install;
+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',
+    'start-session-test' => 'Start an installation TEST session, with command and result transmitted via stdin/out',
     'help' => 'Output this usage help.',
 };
 
@@ -56,7 +60,7 @@ if (!$cmd || $cmd eq 'help' || !exists($commands->{$cmd})) {
 
 Proxmox::Log::init("/tmp/install-low-level-${cmd}.log");
 
-my $env = Proxmox::Install::ISOEnv::setup();
+my $env = Proxmox::Install::ISOEnv::get();
 if ($cmd eq 'dump-env') {
 
     my $out_dir = $env->{locations}->{run};
@@ -70,17 +74,83 @@ if ($cmd eq 'dump-env') {
        'iso-info' => $env->{iso},
        'product' => $env->{product},
        'product-cfg' => $env->{cfg},
+       'run-env-cache-file' => $env->{'run-env-cache-file'},
        '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_file = Proxmox::Install::ISOEnv::get('run-env-cache-file');
+
     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);
+    file_write_all($run_env_file, $run_env_serialized);
 } elsif ($cmd eq 'start-session') {
     Proxmox::UI::init_stdio({}, $env);
-    die "TODO";
+
+    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);
+    log_info("got installation config: ". to_json(Proxmox::Install::Config::get(), { utf8 => 1, canonical => 1 }) ."\n");
+
+    eval { Proxmox::Install::extract_data() };
+    if (my $err = $@) {
+       # suppress "empty" error as we got some case where the user choose to abort on a prompt,
+       # there it doesn't make sense to show them an error again, they "caused" it after all.
+       if ($err ne "\n") {
+           warn "installation failed - $err\n";
+           log_error("installation failed: $err");
+           Proxmox::UI::finished(0, $err);
+       }
+    } else {
+       if (Proxmox::Install::Config::get_autoreboot()) {
+           Proxmox::UI::finished(1, "Installation finished - auto-rebooting in ~ 5 seconds");
+       } else {
+           Proxmox::UI::finished(1, "Installation complete - reboot now?");
+       }
+    }
+} elsif ($cmd eq 'start-session-test') {
+    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/100000, 0, 100, "foo $i");
+       if ($i > 500 && $i < 600) {
+           usleep(50 * 1000);
+       } else {
+           usleep(10 * 1000);
+       }
+    }
+
+    if (Proxmox::Install::Config::get_autoreboot()) {
+       Proxmox::UI::finished(1, "Installation finished - auto-rebooting in ~ 5 seconds");
+    } else {
+       Proxmox::UI::finished(1, "Installation complete - reboot now?");
+    }
 }
 
 exit(0);