+ Not_found | Failure "int_of_string" ->
+ (* 'dmesg' can't be parsed. The backup plan is to look
+ * at /proc/meminfo.
+ *)
+ let mem = shget "head -1 /proc/meminfo | awk '{print $2/1024}'" in
+ match mem with
+ | Some (mem::_) -> int_of_float (float_of_string mem)
+
+ (* For some reason even /proc/meminfo didn't work. Just
+ * assume 256 MB instead.
+ *)
+ | _ -> 256 in
+
+ (* Autodetect system # pCPUs. *)
+ let system_nr_cpus =
+ let cpus =
+ shget "grep ^processor /proc/cpuinfo | tail -1 | awk '{print $3+1}'" in
+ match cpus with
+ | Some (cpus::_) -> int_of_string cpus
+ | _ -> 1 in
+
+ (* Greeting, type of transfer, network question stages.
+ * These are all done in newt mode.
+ *)
+ let config_transfer_type, config_network =
+ with_newt (
+ fun () ->
+ (* Greeting. *)
+ if !config_greeting then
+ message_box program_name (sprintf (f_ "Welcome to %s, a live CD for migrating a physical machine to a virtualized host.\n\nTo continue press the Return key.\n\nTo get a shell you can use [ALT] [F2] and log in as root with no password.\n\nExtra information is logged in /tmp/virt-p2v.log but this file disappears when the machine reboots.") program_name);
+
+ (* Type of transfer. *)
+ let config_transfer_type =
+ match !config_transfer_type with
+ | Some t -> t
+ | None ->
+ let items = [
+ s_ "Physical to Virtual (P2V)", P2V;
+ s_ "Virtual to Virtual (V2V)", V2V;
+ ] in
+
+ select_single ~stage:(s_ "Transfer type") 40
+ (s_ "Transfer type")
+ items in
+
+ (* Network configuration. *)
+ let config_network =
+ match !config_network with
+ | Some n -> n
+ | None ->
+ open_centered_window ~stage:(s_ "Network")
+ 60 20 (s_ "Configure network");
+
+ let autolist = Newt.listbox 4 2 4 [Newt.SCROLL] in
+ Newt.listbox_set_width autolist 52;
+
+ (* Populate the "Automatic" listbox with RHEL/Fedora
+ * root partitions found which allow us to do
+ * automatic configuration in a known way.
+ *)
+ let rec loop = function
+ | [] -> ()
+ | (partition, LinuxRoot (_, ((RHEL _|Fedora _) as distro)))
+ :: parts ->
+ let label =
+ sprintf "%s (%s)"
+ (dev_of_partition partition)
+ (string_of_linux_distro distro) in
+ ignore (Newt.listbox_append_entry autolist label partition);
+ loop parts
+ | _ :: parts -> loop parts
+ in
+ loop all_partitions;
+
+ (* If there is no suitable root partition (the listbox
+ * is empty) then disable the auto option and the listbox.
+ *)
+ let no_auto = Newt.listbox_item_count autolist = 0 in
+
+ let auto =
+ Newt.radio_button 1 1
+ (s_ "Automatic from:") (not no_auto) None in
+ let shell =
+ Newt.radio_button 1 6
+ (s_ "Start a shell") no_auto (Some auto) in
+
+ if no_auto then (
+ Newt.component_takes_focus auto false;
+ Newt.component_takes_focus
+ (Newt.component_of_listbox autolist) false
+ );
+
+ let qemu =
+ Newt.radio_button 1 7
+ (s_ "QEMU user network") false (Some shell) in
+ let nonet =
+ Newt.radio_button 1 8
+ (s_ "Don't configure the network") false (Some qemu) in
+ let static =
+ Newt.radio_button 1 9
+ (s_ "Static configuration:") false (Some nonet) in
+
+ let label1 = Newt.label 4 10 (s_ "Interface") in
+ let entry1 = Newt.entry 16 10 (Some "eth0") 8 [] in
+ let label2 = Newt.label 4 11 (s_ "IP") in
+ let entry2 = Newt.entry 16 11 None 16 [] in
+ let label3 = Newt.label 4 12 (s_ "Netmask") in
+ let entry3 = Newt.entry 16 12 (Some "255.255.255.0") 16 [] in
+ let label4 = Newt.label 4 13 (s_ "Gateway") in
+ let entry4 = Newt.entry 16 13 None 16 [] in
+ let label5 = Newt.label 4 14 (s_ "Nameserver") in
+ let entry5 = Newt.entry 16 14 None 16 [] in
+
+ let enable_static () =
+ Newt.component_takes_focus entry1 true;
+ Newt.component_takes_focus entry2 true;
+ Newt.component_takes_focus entry3 true;
+ Newt.component_takes_focus entry4 true;
+ Newt.component_takes_focus entry5 true
+ in
+
+ let disable_static () =
+ Newt.component_takes_focus entry1 false;
+ Newt.component_takes_focus entry2 false;
+ Newt.component_takes_focus entry3 false;
+ Newt.component_takes_focus entry4 false;
+ Newt.component_takes_focus entry5 false
+ in
+
+ let enable_autolist () =
+ Newt.component_takes_focus
+ (Newt.component_of_listbox autolist) true
+ in
+ let disable_autolist () =
+ Newt.component_takes_focus
+ (Newt.component_of_listbox autolist) false
+ in
+
+ disable_static ();
+ Newt.component_add_callback auto
+ (fun () ->disable_static (); enable_autolist ());
+ Newt.component_add_callback shell
+ (fun () -> disable_static (); disable_autolist ());
+ Newt.component_add_callback qemu
+ (fun () -> disable_static (); disable_autolist ());
+ Newt.component_add_callback nonet
+ (fun () -> disable_static (); disable_autolist ());
+ Newt.component_add_callback static
+ (fun () -> enable_static (); disable_autolist ());
+
+ let ok = Newt.button 48 16 ok_button in
+
+ let form = Newt.form None None [] in
+ Newt.form_add_components form [auto;
+ Newt.component_of_listbox autolist;
+ shell;qemu;nonet;static;
+ label1;label2;label3;label4;label5;
+ entry1;entry2;entry3;entry4;entry5;
+ ok];
+
+ let n =
+ let rec loop () =
+ ignore (Newt.run_form form);
+
+ let r = Newt.radio_get_current auto in
+ if Newt.component_equals r auto then (
+ match Newt.listbox_get_current autolist with
+ | None -> loop ()
+ | Some part -> Auto part
+ )
+ else if Newt.component_equals r shell then Shell
+ else if Newt.component_equals r qemu then QEMUUserNet
+ else if Newt.component_equals r nonet then NoNetwork
+ else if Newt.component_equals r static then (
+ let interface = Newt.entry_get_value entry1 in
+ let address = Newt.entry_get_value entry2 in
+ let netmask = Newt.entry_get_value entry3 in
+ let gateway = Newt.entry_get_value entry4 in
+ let nameserver = Newt.entry_get_value entry5 in
+ if interface = "" || address = "" ||
+ netmask = "" || gateway = "" then
+ loop ()
+ else
+ Static (interface, address, netmask, gateway, nameserver)
+ )
+ else loop ()
+ in
+ loop () in
+ Newt.pop_window ();
+
+ n in
+
+ config_transfer_type, config_network
+ ) in
+
+ (* Try to bring up the network. *)
+ (match config_network with
+ | Shell ->
+ print_endline (s_ "Network configuration.\n\nPlease configure the network from this shell.\n\nWhen you have finished, exit the shell with ^D or exit.\n");
+ shell ()