8 use File
::Path
qw(make_path);
11 use Time
::HiRes
qw(usleep);
16 'test-image|t=s' => \
$test_image
17 ) or die "usage error\n";
19 Proxmox
::Install
::ISOEnv
::set_test_image
($test_image) if $test_image;
22 use Proxmox
::Install
::ISOEnv
;
23 use Proxmox
::Install
::RunEnv
;
24 use Proxmox
::Sys
::Udev
;
26 use Proxmox
::Sys
::File
qw(file_write_all);
30 use Proxmox
::Install
::Config
;
34 'dump-env' => 'Dump the current ISO and Hardware environment to base the installer UI on.',
35 'dump-udev' => 'Dump disk and network device info. Used for the auto installation.',
36 'start-session' => 'Start an installation session, with command and result transmitted via stdin/out',
37 'start-session-test' => 'Start an installation TEST session, with command and result transmitted via stdin/out',
38 'help' => 'Output this usage help.',
45 printf("ERROR: missing command\n\n");
46 } elsif (!exists($commands->{$cmd})) {
47 printf("ERROR: unknown command '$cmd'\n\n");
50 print "USAGE: $0 <cmd>\n";
51 for my $cmd (sort keys $commands->%*) {
52 printf(" %-20s - %s\n", $cmd, $commands->{$cmd});
55 exit($cmd ne 'help' ?
1 : 0);
58 sub read_and_merge_config
{
60 while (my $line = <>) {
61 if ($line =~ /^\s*\{/) {
67 my $config = eval { from_json
($config_raw, { utf8
=> 1 }) };
68 die "failed to parse config from stdin - $@\n" if $@;
70 Proxmox
::Install
::Config
::merge
($config);
71 log_info
("got installation config: ". to_json
(Proxmox
::Install
::Config
::get
(), { utf8
=> 1, canonical
=> 1 }) ."\n");
72 file_write_all
("/tmp/low-level-config.json", to_json
(Proxmox
::Install
::Config
::get
()));
75 sub send_reboot_ui_message
{
76 if (Proxmox
::Install
::Config
::get_autoreboot
()) {
79 Proxmox
::UI
::finished
(1, "Installation finished - auto-rebooting in $secs seconds ..");
84 Proxmox
::UI
::finished
(1, "Installation finished - reboot now?");
89 if (!$cmd || $cmd eq 'help' || !exists($commands->{$cmd})) {
93 Proxmox
::Log
::init
("/tmp/install-low-level-${cmd}.log");
95 my $env = Proxmox
::Install
::ISOEnv
::get
();
96 if ($cmd eq 'dump-env') {
97 Proxmox
::UI
::init_stdio
({}, $env);
99 my $out_dir = $env->{locations
}->{run
};
101 die "failed to create output directory '$out_dir'\n" if !-d
$out_dir;
103 my $locales_serialized = to_json
($env->{locales
}, {canonical
=> 1, utf8
=> 1}) ."\n";
104 file_write_all
("$out_dir/locales.json", $locales_serialized);
107 'iso-info' => $env->{iso
},
108 'product' => $env->{product
},
109 'product-cfg' => $env->{cfg
},
110 'run-env-cache-file' => $env->{'run-env-cache-file'},
111 'locations' => $env->{locations
},
113 my $iso_serialized = to_json
($iso_info, {canonical
=> 1, utf8
=> 1}) ."\n";
114 file_write_all
("$out_dir/iso-info.json", $iso_serialized);
116 my $run_env_file = Proxmox
::Install
::ISOEnv
::get
('run-env-cache-file');
118 my $run_env = Proxmox
::Install
::RunEnv
::query_installation_environment
();
119 my $run_env_serialized = to_json
($run_env, {canonical
=> 1, utf8
=> 1}) ."\n";
120 file_write_all
($run_env_file, $run_env_serialized);
121 } elsif ($cmd eq 'dump-udev') {
122 my $out_dir = $env->{locations
}->{run
};
124 die "failed to create output directory '$out_dir'\n" if !-d
$out_dir;
127 disks
=> Proxmox
::Sys
::Block
::udevadm_disk_details
(),
128 nics
=> Proxmox
::Sys
::Net
::udevadm_netdev_details
(),
131 my $output_serialized = to_json
($output, {canonical
=> 1, utf8
=> 1}) ."\n";
132 file_write_all
("$out_dir/run-env-udev.json", $output_serialized);
133 } elsif ($cmd eq 'start-session') {
134 Proxmox
::UI
::init_stdio
({}, $env);
135 read_and_merge_config
();
137 eval { Proxmox
::Install
::extract_data
() };
139 # suppress "empty" error as we got some case where the user choose to abort on a prompt,
140 # there it doesn't make sense to show them an error again, they "caused" it after all.
142 warn "installation failed - $err\n";
143 log_error
("installation failed: $err");
144 Proxmox
::UI
::finished
(0, $err);
147 send_reboot_ui_message
();
149 } elsif ($cmd eq 'start-session-test') {
150 Proxmox
::UI
::init_stdio
({}, $env);
151 read_and_merge_config
();
153 my $res = Proxmox
::UI
::prompt
("Reply anything?") ?
'ok' : 'not ok';
154 Proxmox
::UI
::message
("Test Message - got $res");
156 for (my $i = 1; $i <= 1000; $i += 3) {
157 Proxmox
::UI
::progress
($i/100000, 0, 100, "foo $i");
158 if ($i > 500 && $i < 600) {
165 send_reboot_ui_message
();