]> git.proxmox.com Git - pve-installer.git/blobdiff - proxmox-low-level-installer
sys: command: allow terminating the process early from log subroutine
[pve-installer.git] / proxmox-low-level-installer
index 0f2bf4f68f8cc1e11d85624521bf246694726c35..28482959ae0f96c63b54f96365774110e7f50598 100755 (executable)
@@ -53,6 +53,35 @@ sub usage {
     exit($cmd ne 'help' ? 1 : 0);
 }
 
+sub read_and_merge_config {
+    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");
+}
+
+sub send_reboot_ui_message {
+    if (Proxmox::Install::Config::get_autoreboot()) {
+       my $secs = 5;
+       while ($secs > 0) {
+           Proxmox::UI::finished(1, "Installation finished - auto-rebooting in $secs seconds ..");
+           sleep 1;
+           $secs -= 1;
+       }
+    } else {
+       Proxmox::UI::finished(1, "Installation finished - reboot now?");
+    }
+}
+
 my $cmd = shift;
 if (!$cmd || $cmd eq 'help' || !exists($commands->{$cmd})) {
     usage($cmd // '');
@@ -62,6 +91,7 @@ Proxmox::Log::init("/tmp/install-low-level-${cmd}.log");
 
 my $env = Proxmox::Install::ISOEnv::get();
 if ($cmd eq 'dump-env') {
+    Proxmox::UI::init_stdio({}, $env);
 
     my $out_dir = $env->{locations}->{run};
     make_path($out_dir);
@@ -87,19 +117,7 @@ if ($cmd eq 'dump-env') {
     file_write_all($run_env_file, $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);
-    log_info("got installation config: ". to_json(Proxmox::Install::Config::get(), { utf8 => 1, canonical => 1 }) ."\n");
+    read_and_merge_config();
 
     eval { Proxmox::Install::extract_data() };
     if (my $err = $@) {
@@ -111,28 +129,11 @@ if ($cmd eq 'dump-env') {
            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?");
-       }
+       send_reboot_ui_message();
     }
 } 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";
+    read_and_merge_config();
 
     my $res = Proxmox::UI::prompt("Reply anything?") ? 'ok' : 'not ok';
     Proxmox::UI::message("Test Message - got $res");
@@ -146,11 +147,7 @@ if ($cmd eq 'dump-env') {
        }
     }
 
-    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?");
-    }
+    send_reboot_ui_message();
 }
 
 exit(0);