]>
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; | |
28 | use Proxmox::Install::Config; | |
29 | use Proxmox::UI; | |
989191f0 TL |
30 | |
31 | my $commands = { | |
32 | 'dump-env' => 'Dump the current ISO and Hardware environment to base the installer UI on.', | |
33 | 'start-session' => 'Start an installation session, with command and result transmitted via stdin/out', | |
34 | 'help' => 'Output this usage help.', | |
35 | }; | |
36 | ||
37 | sub usage { | |
38 | my ($cmd) = @_; | |
39 | ||
40 | if (!$cmd) { | |
41 | printf("ERROR: missing command\n\n"); | |
42 | } elsif (!exists($commands->{$cmd})) { | |
43 | printf("ERROR: unknown command '$cmd'\n\n"); | |
44 | } | |
45 | ||
46 | print "USAGE: $0 <cmd>\n"; | |
47 | for my $cmd (sort keys $commands->%*) { | |
48 | printf(" %-20s - %s\n", $cmd, $commands->{$cmd}); | |
49 | } | |
50 | ||
51 | exit($cmd ne 'help' ? 1 : 0); | |
52 | } | |
53 | ||
54 | my $cmd = shift; | |
55 | if (!$cmd || $cmd eq 'help' || !exists($commands->{$cmd})) { | |
56 | usage($cmd // ''); | |
57 | } | |
58 | ||
92c7b5c9 TL |
59 | Proxmox::Log::init("/tmp/install-low-level-${cmd}.log"); |
60 | ||
8b39b0aa | 61 | my $env = Proxmox::Install::ISOEnv::setup(); |
989191f0 | 62 | if ($cmd eq 'dump-env') { |
989191f0 TL |
63 | |
64 | my $out_dir = $env->{locations}->{run}; | |
65 | make_path($out_dir); | |
66 | die "failed to create output directory '$out_dir'\n" if !-d $out_dir; | |
67 | ||
68 | my $locales_serialized = to_json($env->{locales}, {canonical => 1, utf8 => 1}) ."\n"; | |
69 | file_write_all("$out_dir/locales.json", $locales_serialized); | |
70 | ||
71 | my $iso_info = { | |
72 | 'iso-info' => $env->{iso}, | |
73 | 'product' => $env->{product}, | |
74 | 'product-cfg' => $env->{cfg}, | |
75 | 'locations' => $env->{locations}, | |
76 | }; | |
77 | my $iso_serialized = to_json($iso_info, {canonical => 1, utf8 => 1}) ."\n"; | |
78 | file_write_all("$out_dir/iso-info.json", $iso_serialized); | |
79 | ||
db97dbac TL |
80 | my $run_env = Proxmox::Install::RunEnv::query_installation_environment(); |
81 | my $run_env_serialized = to_json($run_env, {canonical => 1, utf8 => 1}) ."\n"; | |
82 | file_write_all("$out_dir/run-env-info.json", $run_env_serialized); | |
8b39b0aa TL |
83 | } elsif ($cmd eq 'start-session') { |
84 | Proxmox::UI::init_stdio({}, $env); | |
5c3d53f5 TL |
85 | |
86 | my $config_raw; | |
87 | while(my $line = <>) { | |
88 | if ($line =~ /^\s*{/) { | |
89 | $config_raw = $line; | |
90 | last; | |
91 | } | |
92 | } | |
93 | my $config = eval { from_json($config_raw, { utf8 => 1 }) }; | |
94 | die "failed to parse config from stdin - $@\n" if $@; | |
95 | ||
96 | Proxmox::Install::Config::merge($config); | |
97 | ||
98 | print STDERR "got config: ". to_json(Proxmox::Install::Config::get(), { utf8 => 1, canonical => 1 }) ."\n"; | |
99 | ||
100 | my $res = Proxmox::UI::prompt("Reply anything?") ? 'ok' : 'not ok'; | |
101 | Proxmox::UI::message("Test Message - got $res"); | |
102 | ||
103 | for (my $i = 1; $i <= 1000; $i += 3) { | |
104 | Proxmox::UI::progress($i/1000, 0, 100, "foo $i"); | |
105 | if ($i > 500 && $i < 600) { | |
106 | usleep(50 * 1000); | |
107 | } else { | |
108 | usleep(10 * 1000); | |
109 | } | |
110 | } | |
111 | ||
112 | # Proxmox::Install::extract_data(); # TODO | |
989191f0 TL |
113 | } |
114 | ||
115 | exit(0); |