8 use File
::Path
qw(make_path);
11 use Time
::HiRes
qw(usleep);
16 'test-mode|t' => \
$test_mode
17 ) or die "usage error\n";
19 # FIXME: use cleaner approach for setting tet mode?
20 Proxmox
::Install
::ISOEnv
::set_test_image
('/dev/null') if $test_mode;
22 use Proxmox
::Install
::ISOEnv
;
23 use Proxmox
::Install
::RunEnv
;
25 use Proxmox
::Sys
::File
qw(file_write_all);
29 use Proxmox
::Install
::Config
;
33 'dump-env' => 'Dump the current ISO and Hardware environment to base the installer UI on.',
34 'start-session' => 'Start an installation session, with command and result transmitted via stdin/out',
35 'start-session-test' => 'Start an installation TEST session, with command and result transmitted via stdin/out',
36 'help' => 'Output this usage help.',
43 printf("ERROR: missing command\n\n");
44 } elsif (!exists($commands->{$cmd})) {
45 printf("ERROR: unknown command '$cmd'\n\n");
48 print "USAGE: $0 <cmd>\n";
49 for my $cmd (sort keys $commands->%*) {
50 printf(" %-20s - %s\n", $cmd, $commands->{$cmd});
53 exit($cmd ne 'help' ?
1 : 0);
57 if (!$cmd || $cmd eq 'help' || !exists($commands->{$cmd})) {
61 Proxmox
::Log
::init
("/tmp/install-low-level-${cmd}.log");
63 my $env = Proxmox
::Install
::ISOEnv
::get
();
64 if ($cmd eq 'dump-env') {
66 my $out_dir = $env->{locations
}->{run
};
68 die "failed to create output directory '$out_dir'\n" if !-d
$out_dir;
70 my $locales_serialized = to_json
($env->{locales
}, {canonical
=> 1, utf8
=> 1}) ."\n";
71 file_write_all
("$out_dir/locales.json", $locales_serialized);
74 'iso-info' => $env->{iso
},
75 'product' => $env->{product
},
76 'product-cfg' => $env->{cfg
},
77 'run-env-cache-file' => $env->{'run-env-cache-file'},
78 'locations' => $env->{locations
},
80 my $iso_serialized = to_json
($iso_info, {canonical
=> 1, utf8
=> 1}) ."\n";
81 file_write_all
("$out_dir/iso-info.json", $iso_serialized);
83 my $run_env_file = Proxmox
::Install
::ISOEnv
::get
('run-env-cache-file');
85 my $run_env = Proxmox
::Install
::RunEnv
::query_installation_environment
();
86 my $run_env_serialized = to_json
($run_env, {canonical
=> 1, utf8
=> 1}) ."\n";
87 file_write_all
($run_env_file, $run_env_serialized);
88 } elsif ($cmd eq 'start-session') {
89 Proxmox
::UI
::init_stdio
({}, $env);
92 while (my $line = <>) {
93 if ($line =~ /^\s*\{/) {
98 my $config = eval { from_json
($config_raw, { utf8
=> 1 }) };
99 die "failed to parse config from stdin - $@\n" if $@;
101 Proxmox
::Install
::Config
::merge
($config);
102 log_info
("got installation config: ". to_json
(Proxmox
::Install
::Config
::get
(), { utf8
=> 1, canonical
=> 1 }) ."\n");
104 eval { Proxmox
::Install
::extract_data
() };
106 # suppress "empty" error as we got some case where the user choose to abort on a prompt,
107 # there it doesn't make sense to show them an error again, they "caused" it after all.
109 warn "installation failed - $err\n";
110 log_error
("installation failed: $err");
111 Proxmox
::UI
::finished
(0, $err);
114 if (Proxmox
::Install
::Config
::get_autoreboot
()) {
115 Proxmox
::UI
::finished
(1, "Installation finished - auto-rebooting in ~ 5 seconds");
117 Proxmox
::UI
::finished
(1, "Installation complete - reboot now?");
120 } elsif ($cmd eq 'start-session-test') {
121 Proxmox
::UI
::init_stdio
({}, $env);
124 while (my $line = <>) {
125 if ($line =~ /^\s*\{/) {
130 my $config = eval { from_json
($config_raw, { utf8
=> 1 }) };
131 die "failed to parse config from stdin - $@\n" if $@;
133 Proxmox
::Install
::Config
::merge
($config);
135 print STDERR
"got config: ". to_json
(Proxmox
::Install
::Config
::get
(), { utf8
=> 1, canonical
=> 1 }) ."\n";
137 my $res = Proxmox
::UI
::prompt
("Reply anything?") ?
'ok' : 'not ok';
138 Proxmox
::UI
::message
("Test Message - got $res");
140 for (my $i = 1; $i <= 1000; $i += 3) {
141 Proxmox
::UI
::progress
($i/100000, 0, 100, "foo $i");
142 if ($i > 500 && $i < 600) {
149 if (Proxmox
::Install
::Config
::get_autoreboot
()) {
150 Proxmox
::UI
::finished
(1, "Installation finished - auto-rebooting in ~ 5 seconds");
152 Proxmox
::UI
::finished
(1, "Installation complete - reboot now?");