1 -- $Id: 800_configure_network.lua,v 1.7 2005/03/27 01:20:40 cpressey Exp $
7 -- XXX Several of the functions in this script should be in
8 -- XXX scripts/demo/lib/network_ui.lua (or something) instead.
10 local execute_and_wait_for = function(ni, cmds)
11 if cmds:execute() then
13 predicate = function()
20 "Waiting for interface %s to come up...",
24 -- show_ifconfig(a->c, interface);
26 "Interface\n\n%s\n\nis now up, with IP address %s.",
27 ni:get_desc(), ni:get_inet_addr()
31 -- show_ifconfig(a->c, interface);
33 "Interface\n\n%s\n\nfailed to come up.",
43 local dhcp_configure = function(ni)
44 local cmds = CmdChain.new()
46 ni:cmds_dhcp_configure(cmds)
47 return execute_and_wait_for(ni, cmds)
50 local static_configure = function(ni)
51 local response = App.ui:present{
53 name = _("Assign IP Address"),
54 short_desc = _("Configuring Interface:"),
58 name = _("IP Address"),
59 short_desc = _("Enter the IP Address you would like to use")
64 short_desc = _("Enter the netmask of the IP address")
67 id = "default_router",
68 name = _("Default Router"),
69 short_desc = _("Enter the IP address of the default router")
73 name = _("Primary DNS Server"),
74 short_desc = _("Enter the IP address of primary DNS Server")
82 name = _("Domain Name")
88 name = _("Configure Interface")
92 name = _("Return to Utilities Menu")
107 if response.action_id == "ok" then
108 local ip = response.datasets[1].ip
109 local netmask = response.datasets[1].netmask
110 local default_router = response.datasets[1].default_router
111 local primary_dns = response.datasets[1].primary_dns
112 local host = response.datasets[1].host
113 local domain = response.datasets[1].domain
115 local cmds = CmdChain.new()
116 -- XXX check ip for wellformedness first
117 ni:cmds_assign_inet_addr(cmds, ip)
118 ni:cmds_assign_netmask(cmds, netmask)
121 cmdline = "${root}${ROUTE} add default ${default_router}",
123 default_router = default_router
127 local success = execute_and_wait_for(ni, cmds)
129 -- XXX this isn't quite right, yet...
130 -- XXX nowhere to write these yet! :)
131 local rc_conf = ConfigVars.new()
134 string.format("ifconfig_%s", ni:get_name()),
135 string.format("inet %s netmask %s", ip, netmask)
137 rc_conf:set("defaultrouter", default_router)
139 rc_conf:set("hostname", string.format("%s.%s", host, domain))
141 local resolv_conf = ConfigVars.new()
143 resolv_conf:set("search", domain)
144 resolv_conf:set("nameserver", primary_dns)
150 title = "Configure your Network",
151 action = function(fsm)
152 local actions, ifname, ni, result
154 if not App.state.net_if then
155 App.state.net_if = NetworkInterfaces.new()
156 App.state.net_if:probe()
159 if App.state.net_if:ip_addr_count() > 0 then
163 if not App.ui:confirm(_(
164 "You have not yet configured your network settings. " ..
165 "Would you like to do so now? (Having an operational " ..
166 "network connection will enhance the ability of " ..
167 "subsequent tasks, such as installing."
172 ni = App.state.net_if:ui_select_interface()
178 "Would you like to try dynamically configuring this interface? " ..
179 "(This requires that you have a DHCP server operating on " ..
180 "the network that this interface is attached to.)"