]> git.proxmox.com Git - pve-installer.git/blobdiff - proxmox-low-level-installer
low level installer: drop printing about extracting deb packages to stderr
[pve-installer.git] / proxmox-low-level-installer
index 814961e5d5a4e73457aaa5df85e7b87e38708af7..e5c2908c3a2b06b9d3d59d3bd4a252a1d0195c63 100755 (executable)
@@ -11,16 +11,17 @@ use JSON;
 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::Udev;
 
 use Proxmox::Sys::File qw(file_write_all);
 
@@ -31,6 +32,7 @@ use Proxmox::UI;
 
 my $commands = {
     'dump-env' => 'Dump the current ISO and Hardware environment to base the installer UI on.',
+    'dump-udev' => 'Dump disk and network device info. Used for the auto installation.',
     '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.',
@@ -53,6 +55,36 @@ 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");
+    file_write_all("/tmp/low-level-config.json", to_json(Proxmox::Install::Config::get()));
+}
+
+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 +94,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);
@@ -85,21 +118,21 @@ if ($cmd eq 'dump-env') {
     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($run_env_file, $run_env_serialized);
-} elsif ($cmd eq 'start-session') {
-    Proxmox::UI::init_stdio({}, $env);
+} elsif ($cmd eq 'dump-udev') {
+    my $out_dir = $env->{locations}->{run};
+    make_path($out_dir);
+    die "failed to create output directory '$out_dir'\n" if !-d $out_dir;
 
-    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 $@;
+    my $output = {
+       disks => Proxmox::Sys::Block::udevadm_disk_details(),
+       nics => Proxmox::Sys::Net::udevadm_netdev_details(),
+    };
 
-    Proxmox::Install::Config::merge($config);
-    log_info("got installation config: ". to_json(Proxmox::Install::Config::get(), { utf8 => 1, canonical => 1 }) ."\n");
+    my $output_serialized = to_json($output, {canonical => 1, utf8 => 1}) ."\n";
+    file_write_all("$out_dir/run-env-udev.json", $output_serialized);
+} elsif ($cmd eq 'start-session') {
+    Proxmox::UI::init_stdio({}, $env);
+    read_and_merge_config();
 
     eval { Proxmox::Install::extract_data() };
     if (my $err = $@) {
@@ -111,28 +144,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 +162,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);