]>
Commit | Line | Data |
---|---|---|
989191f0 TL |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use lib '.'; # FIXME | |
7 | ||
8 | use File::Path qw(make_path); | |
9 | use Getopt::Long; | |
10 | use JSON; | |
5c3d53f5 | 11 | use Time::HiRes qw(usleep); |
989191f0 TL |
12 | |
13 | { | |
14 | my $test_mode; | |
15 | GetOptions( | |
16 | 'test-mode|t' => \$test_mode | |
17 | ) or die "usage error\n"; | |
18 | ||
19 | # FIXME: use cleaner approach for setting tet mode? | |
026620be | 20 | Proxmox::Install::ISOEnv::set_test_image('/dev/null') if $test_mode; |
989191f0 | 21 | } |
5c3d53f5 TL |
22 | use Proxmox::Install::ISOEnv; |
23 | use Proxmox::Install::RunEnv; | |
24 | ||
25 | use Proxmox::Sys::File qw(file_write_all); | |
26 | ||
27 | use Proxmox::Log; | |
140f3f40 | 28 | use Proxmox::Install; |
5c3d53f5 TL |
29 | use Proxmox::Install::Config; |
30 | use Proxmox::UI; | |
989191f0 TL |
31 | |
32 | my $commands = { | |
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', | |
140f3f40 | 35 | 'start-session-test' => 'Start an installation TEST session, with command and result transmitted via stdin/out', |
989191f0 TL |
36 | 'help' => 'Output this usage help.', |
37 | }; | |
38 | ||
39 | sub usage { | |
40 | my ($cmd) = @_; | |
41 | ||
42 | if (!$cmd) { | |
43 | printf("ERROR: missing command\n\n"); | |
44 | } elsif (!exists($commands->{$cmd})) { | |
45 | printf("ERROR: unknown command '$cmd'\n\n"); | |
46 | } | |
47 | ||
48 | print "USAGE: $0 <cmd>\n"; | |
49 | for my $cmd (sort keys $commands->%*) { | |
50 | printf(" %-20s - %s\n", $cmd, $commands->{$cmd}); | |
51 | } | |
52 | ||
53 | exit($cmd ne 'help' ? 1 : 0); | |
54 | } | |
55 | ||
56 | my $cmd = shift; | |
57 | if (!$cmd || $cmd eq 'help' || !exists($commands->{$cmd})) { | |
58 | usage($cmd // ''); | |
59 | } | |
60 | ||
92c7b5c9 TL |
61 | Proxmox::Log::init("/tmp/install-low-level-${cmd}.log"); |
62 | ||
8b39b0aa | 63 | my $env = Proxmox::Install::ISOEnv::setup(); |
989191f0 | 64 | if ($cmd eq 'dump-env') { |
989191f0 TL |
65 | |
66 | my $out_dir = $env->{locations}->{run}; | |
67 | make_path($out_dir); | |
68 | die "failed to create output directory '$out_dir'\n" if !-d $out_dir; | |
69 | ||
70 | my $locales_serialized = to_json($env->{locales}, {canonical => 1, utf8 => 1}) ."\n"; | |
71 | file_write_all("$out_dir/locales.json", $locales_serialized); | |
72 | ||
73 | my $iso_info = { | |
74 | 'iso-info' => $env->{iso}, | |
75 | 'product' => $env->{product}, | |
76 | 'product-cfg' => $env->{cfg}, | |
77 | 'locations' => $env->{locations}, | |
78 | }; | |
79 | my $iso_serialized = to_json($iso_info, {canonical => 1, utf8 => 1}) ."\n"; | |
80 | file_write_all("$out_dir/iso-info.json", $iso_serialized); | |
81 | ||
db97dbac TL |
82 | my $run_env = Proxmox::Install::RunEnv::query_installation_environment(); |
83 | my $run_env_serialized = to_json($run_env, {canonical => 1, utf8 => 1}) ."\n"; | |
84 | file_write_all("$out_dir/run-env-info.json", $run_env_serialized); | |
8b39b0aa TL |
85 | } elsif ($cmd eq 'start-session') { |
86 | Proxmox::UI::init_stdio({}, $env); | |
5c3d53f5 TL |
87 | |
88 | my $config_raw; | |
140f3f40 TL |
89 | while (my $line = <>) { |
90 | if ($line =~ /^\s*\{/) { | |
91 | $config_raw = $line; | |
92 | last; | |
93 | } | |
94 | } | |
95 | my $config = eval { from_json($config_raw, { utf8 => 1 }) }; | |
96 | die "failed to parse config from stdin - $@\n" if $@; | |
97 | ||
98 | Proxmox::Install::Config::merge($config); | |
99 | log_info("got installation config: ". to_json(Proxmox::Install::Config::get(), { utf8 => 1, canonical => 1 }) ."\n"); | |
100 | ||
101 | Proxmox::Install::extract_data(); | |
102 | } elsif ($cmd eq 'start-session-test') { | |
103 | Proxmox::UI::init_stdio({}, $env); | |
104 | ||
105 | my $config_raw; | |
106 | while (my $line = <>) { | |
107 | if ($line =~ /^\s*\{/) { | |
5c3d53f5 TL |
108 | $config_raw = $line; |
109 | last; | |
110 | } | |
111 | } | |
112 | my $config = eval { from_json($config_raw, { utf8 => 1 }) }; | |
113 | die "failed to parse config from stdin - $@\n" if $@; | |
114 | ||
115 | Proxmox::Install::Config::merge($config); | |
116 | ||
117 | print STDERR "got config: ". to_json(Proxmox::Install::Config::get(), { utf8 => 1, canonical => 1 }) ."\n"; | |
118 | ||
119 | my $res = Proxmox::UI::prompt("Reply anything?") ? 'ok' : 'not ok'; | |
120 | Proxmox::UI::message("Test Message - got $res"); | |
121 | ||
122 | for (my $i = 1; $i <= 1000; $i += 3) { | |
123 | Proxmox::UI::progress($i/1000, 0, 100, "foo $i"); | |
124 | if ($i > 500 && $i < 600) { | |
125 | usleep(50 * 1000); | |
126 | } else { | |
127 | usleep(10 * 1000); | |
128 | } | |
129 | } | |
130 | ||
131 | # Proxmox::Install::extract_data(); # TODO | |
989191f0 TL |
132 | } |
133 | ||
134 | exit(0); |