/[gli]/trunk/src/fe/dialog/dialogfe.py
Gentoo

Contents of /trunk/src/fe/dialog/dialogfe.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 603 - (show annotations) (download) (as text)
Sat May 28 06:27:40 2005 UTC (13 years, 6 months ago) by agaffney
File MIME type: text/x-python
File size: 36236 byte(s)
Rewrite of set_partitions() for new GLIStorageDevice API

1 #!/usr/bin/python
2
3 import sys
4 sys.path.append("../..")
5
6 import dialog
7 import GLIException
8 import GLIInstallProfile
9 import GLIClientConfiguration
10 import GLIClientController
11 import GLIUtility
12 import GLIStorageDevice
13 import crypt
14 import random
15 import commands
16 import string
17 import copy
18 import signal
19 #import pprint
20 import time
21 import string
22 import re
23 import glob
24 import os
25 import platform
26
27 d = dialog.Dialog()
28 client_profile = GLIClientConfiguration.ClientConfiguration()
29 install_profile = GLIInstallProfile.InstallProfile()
30 cc = GLIClientController.GLIClientController(pretend=True)
31 exception_waiting = None
32 next_step_waiting = False
33 install_done = False
34 local_install = True
35
36 DLG_OK = 0
37 DLG_YES = 0
38 DLG_CANCEL = 1
39 DLG_NO = 1
40 DLG_ESC = 2
41 DLG_ERROR = 3
42 DLG_EXTRA = 4
43 DLG_HELP = 5
44
45 def dmenu_list_to_choices(list):
46 choices = []
47 for i in range(0, len(list)):
48 choices.append((str(i + 1), list[i]))
49
50 return choices
51
52 def run(cmd):
53 output_string = commands.getoutput(cmd)
54 output_list = []
55 while output_string.find("\n") != -1:
56 index = output_string.find("\n") + 1
57 output_list.append(output_string[:index])
58 output_string = output_string[index:]
59
60 return output_list
61
62 def set_partitions():
63 devices = install_profile.get_partition_tables()
64 drives = devices.keys()
65 drives.sort()
66 if not devices:
67 tmp_drives = GLIStorageDevice.detect_devices()
68 tmp_drives.sort()
69 for drive in tmp_drives:
70 devices[drive] = GLIStorageDevice.Device(drive)
71 if local_install:
72 devices[drive].set_partitions_from_disk()
73 drives.append(drive)
74 while 1:
75 code, drive_to_partition = d.menu("Which drive would you like to partition?", choices=dmenu_list_to_choices(drives), cancel="Done")
76 if code != DLG_OK: break
77 drive_to_partition = drives[int(drive_to_partition)-1]
78 while 1:
79 partitions = devices[drive_to_partition].get_partitions()
80 partlist = devices[drive_to_partition].get_ordered_partition_list()
81 tmpparts = devices[drive_to_partition].get_partitions()
82 partsmenu = []
83 for part in partlist:
84 tmppart = tmpparts[part]
85 entry = ""
86 if tmppart.get_type() == "free":
87 entry = "Unallocated space ("
88 if tmppart.is_logical():
89 entry += "logical, "
90 entry += str(tmppart.get_mb()) + "MB)"
91 elif tmppart.get_type() == "extended":
92 entry = str(int(tmppart.get_minor())) + " - Extended (" + str(tmppart.get_mb()) + "MB)"
93 else:
94 entry = str(int(tmppart.get_minor())) + " - "
95 # Type: " + tmppart.get_type() + ", Mountpoint: " + tmppart.get_mountpoint() + ", Mountopts: " + tmppart.get_mountopts() + "("
96 if tmppart.is_logical():
97 entry += "Logical ("
98 else:
99 entry += "Primary ("
100 entry += tmppart.get_type() + ", "
101 entry += (tmppart.get_mountpoint() or "none") + ", "
102 entry += (tmppart.get_mountopts() or "none") + ", "
103 entry += str(tmppart.get_mb()) + "MB)"
104 partsmenu.append(entry)
105 code, part_to_edit = d.menu("Select a partition or unallocated space to edit", width=70, choices=dmenu_list_to_choices(partsmenu), cancel="Back")
106 if code != DLG_OK: break
107 part_to_edit = partlist[int(part_to_edit)-1]
108 tmppart = tmpparts[part_to_edit]
109 if tmppart.get_type() == "free":
110 free_mb = tmppart.get_mb()
111 code, new_mb = d.inputbox("Size of new partition in MB (max " + str(free_mb) + "MB):", init=str(free_mb))
112 if code != DLG_OK: continue
113 if int(new_mb) > free_mb:
114 d.msgbox("The size you entered (" + new_mb + "MB) is larger than the maximum of " + str(free_mb) + "MB")
115 continue
116 part_types = ["ext2", "ext3", "linux-swap", "fat32", "ntfs", "extended", "other"]
117 code, type = d.menu("Type for new partition (reiserfs not yet supported!)", choices=dmenu_list_to_choices(part_types))
118 if code != DLG_OK: continue
119 type = part_types[int(type)-1]
120 if type == "other":
121 code, type = d.inputbox("New partition's type:")
122 if code != DLG_OK: continue
123 devices[drive_to_partition].add_partition(part_to_edit, int(new_mb), 0, 0, type)
124 else:
125 while 1:
126 tmppart = tmpparts[part_to_edit]
127 tmptitle = drive_to_partition + str(part_to_edit) + " - "
128 if tmppart.is_logical():
129 tmptitle += "Logical ("
130 else:
131 tmptitle += "Primary ("
132 tmptitle += tmppart.get_type() + ", "
133 tmptitle += (tmppart.get_mountpoint() or "none") + ", "
134 tmptitle += (tmppart.get_mountopts() or "none") + ", "
135 tmptitle += str(tmppart.get_mb()) + "MB)"
136 menulist = ["Delete", "Mount Point", "Mount Options", "Format"]
137 code, part_action = d.menu(tmptitle, choices=dmenu_list_to_choices(menulist), cancel="Back")
138 if code != DLG_OK: break
139 part_action = menulist[int(part_action)-1]
140 if part_action == "Delete":
141 answer = (d.yesno("Are you sure you want to delete the partition " + drive_to_partition + str(part_to_edit) + "?") == DLG_YES)
142 if answer == True:
143 tmpdev = tmppart.get_device()
144 tmpdev.remove_partition(part_to_edit)
145 break
146 elif part_action == "Mount Point":
147 code, answer = d.inputbox("Enter a mountpoint for partition " + str(part_to_edit), init=tmppart.get_mountpoint())
148 if code == DLG_OK: tmppart.set_mountpoint(answer)
149 elif part_action == "Mount Options":
150 code, answer = d.inputbox("Enter your mount options for partition " + str(part_to_edit), init=(tmppart.get_mountopts() or "defaults"))
151 if code == DLG_OK: tmppart.set_mountopts(answer)
152 elif part_action == "Format":
153 code = d.yesno("Do you want to format this partition?")
154 if code == DLG_YES:
155 tmppart.set_format(True)
156 else:
157 tmppart.set_format(False)
158
159 install_profile.set_partition_tables(devices)
160
161 def set_network_mounts():
162 # This is where any NFS mounts will be specified
163 network_mounts = copy.deepcopy(install_profile.get_network_mounts())
164 while 1:
165 menulist = []
166 for mount in network_mounts:
167 menulist.append(mount['host'] + ":" + mount['export'])
168 menulist.append("Add new network mount")
169 choices = dmenu_list_to_choices(menulist)
170 code, menuitemidx = d.menu("Select a network mount", choices=choices, cancel="Done")
171 if code:
172 if d.yesno("Do you want to save changes?") == DLG_YES:
173 install_profile.set_network_mounts(network_mounts)
174 break
175 menuitem = menulist[int(menuitemidx)-1]
176 if menuitem == "Add new network mount":
177 code, nfsmount = d.inputbox("Enter NFS mount or just enter the IP/hostname to search for available mounts")
178 if code != DLG_OK: continue
179 if not GLIUtility.is_nfs(nfsmount):
180 if GLIUtility.is_ip(nfsmount) or GLIUtility.is_hostname(nfsmount):
181 remotemounts = run("/usr/sbin/showmount -e " + nfsmount + " 2>&1 | egrep '^/' | cut -d ' ' -f 1 && echo")
182 if not len(remotemounts):
183 d.msgbox("No NFS exports detected on " + nfsmount)
184 continue
185 for i in range(0, len(remotemounts)):
186 remotemounts[i] = string.strip(remotemounts[i])
187 code, nfsmount2 = d.menu("Select a NFS export", choices=dmenu_list_to_choices(remotemounts), cancel="Back")
188 if code != DLG_OK: continue
189 nfsmount2 = remotemounts[int(nfsmount2)-1]
190 else:
191 d.msgbox("Enter '" + nfsmount + "' is not a valid IP or hostname")
192 else:
193 colon_location = nfsmount.find(':')
194 menuitem = nfsmount
195 nfsmount = menuitem[:colon_location]
196 nfsmount2 = menuitem[colon_location+1:]
197 for mount in network_mounts:
198 if nfsmount == mount['host'] and nfsmount2 == mount['export']:
199 d.msgbox("There is already an entry for " + nfsmount + ":" + nfsmount2 + ".")
200 nfsmount = None
201 break
202 if nfsmount == None: continue
203 network_mounts.append({'export': nfsmount2, 'host': nfsmount, 'mountopts': '', 'mountpoint': '', 'type': 'nfs'})
204 menuitem = nfsmount + ":" + nfsmount2
205 menuitemidx = len(network_mounts)
206
207 if menuitem.find(':') != -1:
208 colon_location = menuitem.find(':')
209 tmpmount = network_mounts[int(menuitemidx)-1]
210 code, mountpoint = d.inputbox("Enter a mountpoint", init=tmpmount['mountpoint'])
211 if code == DLG_OK: tmpmount['mountpoint'] = mountpoint
212 code, mountopts = d.inputbox("Enter mount options", init=tmpmount['mountopts'])
213 if code == DLG_OK: tmpmount['mountopts'] = mountopts
214 network_mounts[int(menuitemidx)-1] = tmpmount
215
216 def set_install_stage():
217 # The install stage and stage tarball will be selected here
218 install_stages = ("1","2","3","3 + GRP (use binary packages)")
219 code, install_stage = d.menu("Which stage do you want to start at?", choices=dmenu_list_to_choices(install_stages), cancel="Back")
220 if code == DLG_OK:
221 install_stage = install_stages[int(install_stage)-1]
222 if install_stage == "3 + GRP (use binary packages)":
223 install_stage = "3"
224 install_profile.set_grp_install(None, True, None)
225 install_profile.set_install_stage(None, install_stage, None)
226 tarball_options = ("Use Local", "Specify URI")
227 code, tarball_option = d.menu("Select a local stage " + install_stage + " tarball or manually specify a URI:", choices=dmenu_list_to_choices(tarball_options))
228 if code == DLG_OK:
229 tarball_option = tarball_options[int(tarball_option)-1]
230 if tarball_option == "Use Local":
231 stages_dir = "/mnt/cdrom/stages"
232 if os.path.isdir(stages_dir) and os.listdir(stages_dir):
233 local_tarballs = glob.glob(stages_dir + "/stage" + install_stage + "*.bz2")
234 local_tarballs.sort()
235 code, stage_tarball = d.menu("Select a local tarball:", choices=dmenu_list_to_choices(local_tarballs))
236 if code != DLG_OK: return
237 stage_tarball = local_tarballs[int(stage_tarball)-1]
238 else:
239 d.msgbox("There don't seem to be any local tarballs available. Hit OK to manually specify a URI.")
240 tarball_option = "Specify URI"
241 if tarball_option != "Use Local":
242 code, stage_tarball = d.inputbox("Specify the stage tarball URI or local file:", init=install_profile.get_stage_tarball_uri())
243 #If Doing a local install, check for valid file:/// uri
244 if code == DLG_OK:
245 if stage_tarball:
246 if not GLIUtility.is_uri(stage_tarball, checklocal=local_install):
247 d.msgbox("The specified URI is invalid. It was not saved. Please go back and try again.");
248 else: install_profile.set_stage_tarball_uri(None, stage_tarball, None)
249 else: d.msgbox("No URI was specified!")
250 #if d.yesno("The specified URI is invalid. Use it anyway?") == DLG_YES: install_profile.set_stage_tarball_uri(None, stage_tarball, None)
251
252 def set_portage_tree():
253 # This section will ask whether to sync the tree, whether to use a snapshot, etc.
254 menulist = ["Normal 'emerge sync'", "Webrsync (rsync is firewalled)", "Snapshot (using a portage snapshot)", "None (NFS mount)"]
255 code, portage_tree_sync = d.menu("How do you want to sync the portage tree?", choices=dmenu_list_to_choices(menulist))
256 if code != DLG_OK: return
257 portage_tree_sync = menulist[int(portage_tree_sync)-1]
258 #FIX ME when python 2.4 comes out.
259 if portage_tree_sync == "Normal 'emerge sync'": install_profile.set_portage_tree_sync_type(None, "sync", None)
260 if portage_tree_sync == "Webrsync (rsync is firewalled)": install_profile.set_portage_tree_sync_type(None, "webrsync", None)
261 if portage_tree_sync == "None (NFS mount)": install_profile.set_portage_tree_sync_type(None, "none", None)
262 if portage_tree_sync == "Snapshot (using a portage snapshot)":
263 install_profile.set_portage_tree_sync_type(None, "snapshot", None)
264 snapshot_options = ("Use Local", "Specify URI")
265 code, snapshot_option = d.menu("Select a local portage snapshot or manually specify a location:", choices=dmenu_list_to_choices(snapshot_options))
266 snapshot_option = snapshot_options[int(snapshot_option)-1]
267 if snapshot_option == "Use Local":
268 snapshot_dir = "/mnt/cdrom/snapshots"
269 if os.path.isdir(snapshot_dir) and os.listdir(stages_dir):
270 local_snapshots = glob.glob(snapshot_dir + "/portage*.bz2")
271 if len(local_snapshots) == 1:
272 snapshot = local_snapshots[0]
273 else:
274 local_snapshots.sort()
275 code, snapshot = d.menu("Select a local portage snapshot:", choices=dmenu_list_to_choices(local_snapshots))
276 if code != DLG_OK: return
277 snapshot = local_snapshots[int(snapshot)-1]
278 else:
279 d.msgbox("There don't seem to be any local portage snapshots available. Hit OK to manually specify a URI.")
280 snapshot_option = "Specify URI"
281 if snapshot_option != "Use Local":
282 code, snapshot = d.inputbox("Enter portage tree snapshot URI", init=install_profile.get_portage_tree_snapshot_uri())
283 if code == DLG_OK:
284 if snapshot:
285 if not GLIUtility.is_uri(snapshot, checklocal=local_install):
286 d.msgbox("The specified URI is invalid. It was not saved. Please go back and try again.");
287 else: install_profile.set_portage_tree_snapshot_uri(None, snapshot, None)
288
289 else: d.msgbox("No URI was specified!")
290 #if d.yesno("The specified URI is invalid. Use it anyway?") == DLG_YES: install_profile.set_stage_tarball_uri(None, stage_tarball, None)
291
292 def set_make_conf():
293 # This section will be for setting things like CFLAGS, ACCEPT_KEYWORDS, and USE
294 make_conf = install_profile.get_make_conf()
295 while 1:
296 menulist = ["ACCEPT_KEYWORDS", "CFLAGS", "CHOST", "MAKEOPTS", "FEATURES", "USE", "GENTOO_MIRRORS", "SYNC"]
297 code, menuitem = d.menu("Choose a variable to edit", choices=dmenu_list_to_choices(menulist), cancel="Done")
298 if code != DLG_OK: break
299 menuitem = menulist[int(menuitem)-1]
300 oldval = ""
301 if make_conf.has_key(menuitem): oldval = make_conf[menuitem]
302 code, newval = d.inputbox("Enter new value for " + menuitem, init=oldval)
303 if code == DLG_OK:
304 make_conf[menuitem] = newval
305 install_profile.set_make_conf(make_conf)
306
307 def set_kernel():
308 # This section will be for choosing kernel sources, choosing (and specifying) a custom config or genkernel, modules to load at startup, etc.
309 kernel_sources = ("vanilla-sources", "gentoo-sources", "development-sources", "gentoo-dev-sources", "hardened-sources", "livecd-kernel")
310 code, menuitem = d.menu("Choose a kernel sources package", choices=dmenu_list_to_choices(kernel_sources))
311 if code != DLG_OK: return
312 menuitem = kernel_sources[int(menuitem)-1]
313 install_profile.set_kernel_source_pkg(None, menuitem, None)
314 if not menuitem == "livecd-kernel":
315 if d.yesno("Do you want to use genkernel to automatically generate your kernel?") == DLG_NO:
316 code, custom_kernel_uri = d.inputbox("Enter the custom kernel uri")
317 if code == DLG_OK:
318 if custom_kernel_uri:
319 if not GLIUtility.is_uri(custom_kernel_uri, checklocal=local_install):
320 d.msgbox("The specified URI is invalid. It was not saved. Please go back and try again.");
321 else: install_profile.set_kernel_config_uri(None, custom_kernel_uri, None)
322 else: d.msgbox("No URI was specified!")
323 else:
324 if d.yesno("Do you want the bootsplash?") == DLG_YES:
325 install_profile.set_kernel_bootsplash(None, True, None)
326 else:
327 install_profile.set_kernel_bootsplash(None, False, None)
328
329 def set_boot_loader():
330 boot_loaders = ("grub", "lilo")
331 code, menuitem = d.menu("Choose a boot loader", choices=dmenu_list_to_choices(boot_loaders))
332 if code != DLG_OK: return
333 menuitem = boot_loaders[int(menuitem)-1]
334 install_profile.set_boot_loader_pkg(None, menuitem, None)
335 if d.yesno("Do you want the boot loader installed in the MBR?") == DLG_YES:
336 install_profile.set_boot_loader_mbr(None, True, None)
337 else:
338 install_profile.set_boot_loader_mbr(None, False, None)
339 code, bootloader_kernel_args = d.inputbox("Add any optional arguments to pass to the kernel at boot here:")
340 if code == DLG_OK: install_profile.set_bootloader_kernel_args(None, bootloader_kernel_args, None)
341
342 def set_timezone():
343 # This section will be for setting the timezone.
344 zonepath = "/usr/share/zoneinfo"
345 skiplist = ["zone.tab","iso3166.tab","posixrules"]
346 while 1:
347 tzlist = []
348 for entry in os.listdir(zonepath):
349 if entry not in skiplist:
350 if os.path.isdir(zonepath + "/" + entry): entry += "/"
351 tzlist.append(entry)
352 tzlist.sort()
353 code, tznum = d.menu("Select a timezone", choices=dmenu_list_to_choices(tzlist), cancel="Back")
354 if code == DLG_OK:
355 zonepath = os.path.join(zonepath,tzlist[int(tznum)-1])
356 if tzlist[int(tznum)-1][-1:] != "/": break
357 else:
358 if zonepath == "/usr/share/zoneinfo": return
359 slashloc = zonepath[:-1].rfind("/")
360 zonepath = zonepath[:slashloc]
361 install_profile.set_time_zone(None, zonepath[20:], None)
362
363 def set_networking():
364 # This section will be for setting up network interfaces, defining DNS servers, default routes/gateways, etc.
365 while 1:
366 menulist = ["Edit Interfaces", "DNS Servers", "Default Gateway", "Hostname", "Domain Name", "HTTP Proxy", "FTP Proxy", "RSYNC Proxy", "NIS Domain Name"]
367 code, menuitem = d.menu("Choose an option", choices=dmenu_list_to_choices(menulist), cancel="Done")
368 if code != DLG_OK: break
369 menuitem = menulist[int(menuitem)-1]
370 if menuitem == "Edit Interfaces":
371 while 1:
372 interfaces = install_profile.get_network_interfaces()
373 menu_list = interfaces.keys()
374 menu_list.sort()
375 menu_list.append("Add new interface")
376 code, menuitem = d.menu("Select an interface", choices=dmenu_list_to_choices(menu_list), cancel="Back")
377 if code != DLG_OK: break
378 menuitem = menu_list[int(menuitem)-1]
379 newnic = None
380 if menuitem == "Add new interface":
381 code, newnic = d.inputbox("Enter name for new interface (eth0, ppp0, etc.)")
382 if code != DLG_OK: continue
383 if newnic in interfaces:
384 d.msgbox("An interface with the name is already defined.")
385 continue
386 interfaces[newnic] = ("", "", "")
387 menuitem = newnic
388 menuitem2 = ""
389 menulist = ["Edit", "Rename", "Delete"]
390 if newnic == None:
391 menuitem2 = d.menu("What do you want to do with interface " + menuitem + "?", choices=dmenu_list_to_choices(menulist), cancel="Back")
392 if code != DLG_OK: continue
393 else:
394 menuitem2 = "1"
395 menuitem2 = menulist[int(menuitem2)-1]
396 if menuitem2 == "Edit":
397 tmpnic = [interfaces[menuitem][0], interfaces[menuitem][1], interfaces[menuitem][2]]
398 code, ip = d.inputbox("Enter an IP address for " + menuitem + " or 'dhcp' for DHCP", init=tmpnic[0])
399 if code != DLG_OK: continue
400 tmpnic[0] = ip
401 if ip == "dhcp" or ip == "DHCP":
402 tmpnic[1] = ""
403 tmpnic[2] = ""
404 else:
405 code, netmask = d.inputbox("Enter the netmask", init=tmpnic[2])
406 if code == DLG_OK: tmpnic[2] = netmask
407 code, broadcast = d.inputbox("Enter a broadcast", init=tmpnic[1])
408 if code == DLG_OK: tmpnic[1] = broadcast
409 interfaces[menuitem] = (tmpnic[0], tmpnic[1], tmpnic[2])
410 elif menuitem2 == "Rename":
411 d.msgbox("Not implimented yet")
412 elif menuitem2 == "Delete":
413 if d.yesno("Are you sure you want to remove the interface " + menuitem + "?") == DLG_YES:
414 del interfaces[menuitem]
415 install_profile.set_network_interfaces(interfaces)
416 elif menuitem == "DNS Servers":
417 code, dnsservers = d.inputbox("Enter a space-separated list of DNS servers")
418 if code == DLG_OK: install_profile.set_dns_servers(None, dnsservers, None)
419
420 elif menuitem == "Default Gateway":
421 while 1:
422 interfaces = install_profile.get_network_interfaces()
423 if not interfaces: break
424 menu_list = interfaces.keys()
425 menu_list.sort()
426 code, menuitem = d.menu("Which interface is the default gateway?", choices=dmenu_list_to_choices(menu_list), cancel="Back")
427 if code != DLG_OK: break
428 menuitem = menu_list[int(menuitem)-1]
429 code, ip = d.inputbox("Enter an IP address for " + menuitem , init=interfaces[menuitem][0])
430 if code != DLG_OK: continue
431 install_profile.set_default_gateway(None, ip,{'interface': menuitem})
432 break
433 elif menuitem == "Hostname":
434 code, hostname = d.inputbox("Enter the desired hostname")
435 if type(hostname) != str:
436 d.msgbox("Incorrect hostname! It must be a string. Not saved.")
437 if code == DLG_OK: install_profile.set_hostname(None, hostname, None)
438 elif menuitem == "Domain Name":
439 code, domain = d.inputbox("Enter the desired domain name")
440 if type(domain) != str:
441 d.msgbox("Incorrect domain name! It must be a string. Not saved.")
442 if code == DLG_OK: install_profile.set_domainname(None, domain, None)
443 elif menuitem == "HTTP Proxy":
444 code, http_proxy = d.inputbox("Enter a HTTP Proxy if you have one.")
445 if not GLIUtility.is_uri(http_proxy):
446 d.msgbox("Incorrect HTTP Proxy! It must be a uri. Not saved.")
447 if code == DLG_OK: install_profile.set_http_proxy(None, http_proxy, None)
448 elif menuitem == "FTP Proxy":
449 code, ftp_proxy = d.inputbox("Enter a FTP Proxy if you have one.")
450 if not GLIUtility.is_uri(ftp_proxy):
451 d.msgbox("Incorrect FTP Proxy! It must be a uri. Not saved.")
452 if code == DLG_OK: install_profile.set_ftp_proxy(None, ftp_proxy, None)
453 elif menuitem == "RSYNC Proxy":
454 code, rsync_proxy = d.inputbox("Enter a RSYNC Proxy if you have one.")
455 if not GLIUtility.is_uri(rsync_proxy):
456 d.msgbox("Incorrect RSYNC Proxy! It must be a uri. Not saved.")
457 if code == DLG_OK: install_profile.set_rsync_proxy(None, rsync_proxy, None)
458 elif menuitem == "NIS Domain Name":
459 code, nisdomain = d.inputbox("Enter the desired NIS domain name (if you don't know what this is, don't enter one.)")
460 if type(nisdomain) != str:
461 d.msgbox("Incorrect NIS domain name! It must be a string. Not saved.")
462 if code == DLG_OK: install_profile.set_nisdomainname(None, nisdomain, None)
463
464 def set_cron_daemon():
465 cron_daemons = ("vixie-cron", "fcron", "dcron", "None")
466 code, menuitem = d.menu("Choose a cron daemon", choices=dmenu_list_to_choices(cron_daemons))
467 if code == DLG_OK:
468 menuitem = cron_daemons[int(menuitem)-1]
469 if menuitem == "None": menuitem == ""
470 install_profile.set_cron_daemon_pkg(None, menuitem, None)
471
472 def set_logger():
473 loggers = ("syslog-ng", "metalog", "syslogkd")
474 code, menuitem = d.menu("Choose a system logger", choices=dmenu_list_to_choices(loggers))
475 if code == DLG_OK:
476 menuitem = loggers[int(menuitem)-1]
477 install_profile.set_logging_daemon_pkg(None, menuitem, None)
478
479 def set_extra_packages():
480 #d.msgbox("This section is for selecting extra packages (pcmcia-cs, rp-pppoe, xorg-x11, etc.) and setting them up")
481 code, install_packages = d.inputbox("Enter a space-separated list of extra packages to install on the system")
482 if code == DLG_OK: install_profile.set_install_packages(None, install_packages, None)
483
484 def set_rc_conf():
485 # This section is for editing /etc/rc.conf
486 rc_conf = install_profile.get_rc_conf()
487 menulist = ["KEYMAP", "SET_WINDOWSKEYS", "EXTENDED_KEYMAPS", "CONSOLEFONT", "CONSOLETRANSLATION", "CLOCK", "EDITOR", "PROTOCOLS", "DISPLAYMANAGER", "XSESSION"]
488 while 1:
489 code, menuitem = d.menu("Choose a variable to edit", choices=dmenu_list_to_choices(menulist), cancel="Done")
490 if code != DLG_OK: break
491 menuitem = menulist[int(menuitem)-1]
492 oldval = ""
493 if rc_conf.has_key(menuitem): oldval = rc_conf[menuitem]
494 code, newval = d.inputbox("Enter new value for " + menuitem, init=oldval)
495 if code == DLG_OK:
496 rc_conf[menuitem] = newval
497 install_profile.set_rc_conf(rc_conf)
498
499 def set_root_password():
500 # The root password will be set here
501 code, passwd1 = d.passwordbox("Enter the new root password")
502 if code != DLG_OK: return
503 code, passwd2 = d.passwordbox("Enter the new root password again")
504 if code != DLG_OK: return
505 if passwd1 != passwd2:
506 d.msgbox("The passwords do not match")
507 return
508 install_profile.set_root_pass_hash(None, GLIUtility.hash_password(passwd1), None)
509
510 def set_additional_users():
511 # This section will be for adding non-root users
512 users = {}
513 for user in install_profile.get_users():
514 users[user[0]] = (user[0], user[1], user[2], user[3], user[4], user[5], user[6])
515 while 1:
516 menu_list = []
517 for user in users:
518 menu_list.append(user)
519 menu_list.sort()
520 menu_list.append("Add user")
521 code, menuitem = d.menu("Choose a user to edit", choices=dmenu_list_to_choices(menu_list), cancel="Done")
522 if code != DLG_OK:
523 if d.yesno("Do you want to save changes?") == DLG_YES:
524 tmpusers = []
525 for user in users:
526 tmpusers.append(users[user])
527 install_profile.set_users(tmpusers)
528 break
529 menuitem = menu_list[int(menuitem)-1]
530 if menuitem == "Add user":
531 code, newuser = d.inputbox("Enter the username for the new user")
532 if code != DLG_OK: continue
533 if newuser in users:
534 d.msgbox("A user with that name already exists")
535 continue
536 new_user = [newuser, '', ('users',), '/bin/bash', '/home/' + newuser, '', '']
537 users[newuser] = new_user
538 menuitem = newuser
539 while 1:
540 menulist = ["Password", "Group Membership", "Shell", "Home Directory", "UID", "Comment", "Delete"]
541 code, menuitem2 = d.menu("Choose an option for user " + menuitem, choices=dmenu_list_to_choices(menulist), cancel="Back")
542 if code != DLG_OK: break
543 menuitem2 = menulist[int(menuitem2)-1]
544 if menuitem2 == "Password":
545 code, passwd1 = d.passwordbox("Enter the new password")
546 if code != DLG_OK: continue
547 code, passwd2 = d.passwordbox("Enter the new password again")
548 if code != DLG_OK: continue
549 if passwd1 != passwd2:
550 d.msgbox("The passwords do not match")
551 continue
552 users[menuitem][1] = GLIUtility.hash_password(passwd1)
553 elif menuitem2 == "Group Membership":
554 code, groups = d.inputbox("Enter a space-separated list of groups the user is to be in", init=",".join(users[menuitem][2]))
555 if code != DLG_OK: continue
556 # new_groups = []
557 # groups = string.split(groups)
558 # for group in groups:
559 # new_groups.append(group)
560 users[menuitem][2] = string.split(groups, ",")
561 elif menuitem2 == "Shell":
562 code, shell = d.inputbox("Enter the shell you want the user to use. default is /bin/bash. Get it right b/c there's no error checking!", init=users[menuitem][3])
563 if code != DLG_OK: continue
564 users[menuitem][3] = shell
565 elif menuitem2 == "Home Directory":
566 code, homedir = d.inputbox("Enter the user's home directory. default is /home/username. Get it right b/c there's no error checking!", init=users[menuitem][4])
567 if code != DLG_OK: continue
568 users[menuitem][4] = homedir
569 elif menuitem2 == "UID":
570 code, uid = d.inputbox("Enter the user's UID. ", init=users[menuitem][5])
571 if code != DLG_OK: continue
572 if type(uid) != int: continue
573 users[menuitem][5] = uid
574 elif menuitem2 == "Comment":
575 code, comment = d.inputbox("Enter the user's comment.", init=users[menuitem][6])
576 if code != DLG_OK: continue
577 users[menuitem][6] = comment
578 elif menuitem2 == "Delete":
579 if d.yesno("Are you sure you want to delete the user " + menuitem + "?") == DLG_YES:
580 del users[menuitem]
581 break
582
583 def set_services():
584 code, services = d.inputbox("Enter a space-separated list of services to start on boot")
585 if code == DLG_OK: install_profile.set_services(None, services, None)
586
587 def save_install_profile(xmlfilename="", askforfilename=True):
588 code = 0
589 filename = xmlfilename
590 if askforfilename:
591 code, filename = d.inputbox("Enter a filename for the XML file", init=xmlfilename)
592 if code != DLG_OK: return None
593 if GLIUtility.is_file(filename):
594 if not d.yesno("The file " + filename + " already exists. Do you want to overwrite it?") == DLG_YES:
595 return None
596 configuration = open(filename ,"w")
597 configuration.write(install_profile.serialize())
598 configuration.close()
599 return filename
600
601
602 #----------------------------Now for the client_config functions
603 def set_arch_template():
604 subarches = { 'i386': 'x86', 'i486': 'x86', 'i586': 'x86', 'i686': 'x86', 'x86_64': 'amd64', 'parisc': 'hppa' }
605 arch = platform.machine()
606 if arch in subarches: arch = subarches[arch]
607 template_choices = ["x86", "amd64", "sparc", "alpha", "hppa", "ppc"]
608 code, menuitem = d.menu("Please Select Architecture Template:",choices=dmenu_list_to_choices(template_choices), default_item=str(template_choices.index(arch)+1))
609 if code == DLG_OK:
610 menuitem = template_choices[int(menuitem)-1]
611 client_profile.set_architecture_template(None, menuitem, None)
612
613 def set_logfile():
614 code, logfile = d.inputbox("Enter the desired path for the install log:", init="/var/log/install.log")
615 if code == DLG_OK: client_profile.set_log_file(None, logfile, None)
616
617 def set_root_mount_point():
618 code, rootmountpoint = d.inputbox("Enter the mount point for the chroot enviornment:", init="/mnt/gentoo")
619 if code == DLG_OK: client_profile.set_root_mount_point(None, rootmountpoint, None)
620
621 def set_client_networking():
622 network_type = ""
623 interface = ""
624 ip_address = ""
625 broadcast = ""
626 netmask = ""
627 gateway = ""
628 code, interface = d.inputbox("Enter the interface (NIC) you would like to use for installation (e.g. eth0):")
629 if code != DLG_OK: return
630
631 network_choices = ('DHCP', 'Static IP');
632 code, menuitem = d.menu("Please select networking configuration:", choices=dmenu_list_to_choices(network_choices))
633
634 if code != DLG_OK:
635 return
636
637 menuitem = network_choices[int(menuitem)-1]
638 if menuitem == 'Static IP':
639 code, ip_address = d.inputbox("Enter your IP address:")
640 if code != DLG_OK: return
641 code, broadcast = d.inputbox("Enter your Broadcast address:")
642 if code != DLG_OK: return
643 code, netmask = d.inputbox("Enter your Netmask:")
644 if code != DLG_OK: return
645 code, gateway = d.inputbox("Enter your default gateway:")
646 if code != DLG_OK: return
647 network_type = 'static'
648 else:
649 network_type = 'dhcp'
650
651 try:
652 client_profile.set_network_type(None, network_type, None)
653 client_profile.set_network_interface(None, interface, None)
654 if not network_type == 'dhcp':
655 client_profile.set_network_ip(None, ip_address, None)
656 client_profile.set_network_broadcast(None, broadcast, None)
657 client_profile.set_network_netmask(None, netmask, None)
658 client_profile.set_network_gateway(None, gateway, None)
659 except GLIException, e:
660 d.msgbox(e)
661
662
663 def set_livecd_password():
664 # The root password will be set here
665 code, passwd1 = d.passwordbox("Enter the new LIVECD root password")
666 if code != DLG_OK: return
667 code, passwd2 = d.passwordbox("Enter the new LIVECD root password again")
668 if code != DLG_OK: return
669 if passwd1 != passwd2:
670 d.msgbox("The passwords do not match")
671 return
672 client_profile.set_root_passwd(None, GLIUtility.hash_password(passwd1), None)
673
674 def set_enable_ssh():
675 if d.yesno("Do you want SSH enabled during the install?") == DLG_YES:
676 client_profile.set_enable_ssh(None, True, None)
677 else:
678 client_profile.set_enable_ssh(None, False, None)
679
680 def set_client_kernel_modules():
681 code, kernel_modules_list = d.inputbox("Enter a list of kernel modules you want loaded before installation:", init="")
682 if code == DLG_OK: client_profile.set_kernel_modules(None, kernel_modules_list, None)
683
684 def save_client_profile(xmlfilename="", askforfilename=True):
685 code = 0
686 filename = xmlfilename
687 if askforfilename:
688 code, filename = d.inputbox("Enter a filename for the XML file", init=xmlfilename)
689 if code != DLG_OK: return None
690 if GLIUtility.is_file(filename):
691 if not d.yesno("The file " + filename + " already exists. Do you want to overwrite it?") == DLG_YES:
692 return None
693 configuration = open(filename ,"w")
694 configuration.write(client_profile.serialize())
695 configuration.close()
696 return filename
697 # ------------------------------------------------------------------
698 d.setBackgroundTitle("Gentoo Linux Installer")
699 d.msgbox("Welcome to The Gentoo Linux Installer. This is a TESTING release. If your system dies a horrible, horrible death, don't come crying to us (okay, you can cry to klieber).", height=10, width=50, title="Welcome")
700
701 if d.yesno("Are we running in Pretend mode? Yes means safe, No means actually install!") == DLG_NO:
702 cc._pretend = False
703 else:
704 cc._pretend = True
705
706 if d.yesno("Are the profiles being generated to be used for an install on the current computer?") == DLG_NO:
707 local_install = False
708
709
710 if d.yesno("Do you want to use the ClientController? (if doing an install, say YES)") == DLG_YES:
711 client_config_xml_file = None
712 while 1:
713 if d.yesno("Do you have a previously generated XML file for the ClientConfiguration?") == DLG_YES:
714 code, client_config_xml_file = d.inputbox("Enter the filename of the XML file")
715 if code != DLG_OK: break
716 if GLIUtility.is_file(client_config_xml_file): break
717 d.msgbox("Cannot open file " + client_config_xml_file, height=7, width=50)
718 client_config_xml_file = None
719 continue
720 break
721 if client_config_xml_file != None:
722 client_profile.parse(client_config_xml_file)
723 # code to actually run the client_controller functions
724 else:
725 set_arch_template()
726 set_logfile()
727 set_root_mount_point()
728 set_client_networking()
729 set_livecd_password()
730 set_enable_ssh()
731 set_client_kernel_modules()
732 if d.yesno("Do you want to save the ClientConfiguration XML file?") == DLG_YES:
733 if client_config_xml_file == None: client_config_xml_file = ""
734 client_config_xml_file = save_client_profile(xmlfilename=client_config_xml_file)
735
736 d.msgbox("ClientController done")
737
738 client_profile.set_interactive(None, True, None)
739 cc.set_configuration(client_profile)
740
741 cc.start_pre_install()
742
743 install_profile_xml_file = None
744 fn = (
745 { 'text': "Partitioning", 'fn': set_partitions },
746 { 'text': "Network mounts", 'fn': set_network_mounts },
747 { 'text': "Install Stage", 'fn': set_install_stage },
748 { 'text': "Portage Tree", 'fn': set_portage_tree },
749 { 'text': "make.conf", 'fn': set_make_conf },
750 { 'text': "Kernel", 'fn': set_kernel },
751 { 'text': "Bootloader", 'fn': set_boot_loader },
752 { 'text': "Timezone", 'fn': set_timezone },
753 { 'text': "Networking", 'fn': set_networking },
754 { 'text': "Cron daemon", 'fn': set_cron_daemon },
755 { 'text': "Logging daemon", 'fn': set_logger },
756 { 'text': "Extra packages", 'fn': set_extra_packages },
757 { 'text': "Services", 'fn': set_services },
758 { 'text': "rc.conf", 'fn': set_rc_conf },
759 { 'text': "Root password", 'fn': set_root_password },
760 { 'text': "Additional Users", 'fn': set_additional_users },
761 )
762 while 1:
763 if d.yesno("Do you have a previously generated InstallProfile XML file?") == DLG_YES:
764 code, install_profile_xml_file = d.inputbox("Enter the filename of the XML file")
765 if code != DLG_OK: break
766 if GLIUtility.is_file(install_profile_xml_file): break
767 d.msgbox("Cannot open file " + install_profile_xml_file, height=7, width=50)
768 install_profile_xml_file = None
769 continue
770 break
771 if install_profile_xml_file != None:
772 install_profile.parse(install_profile_xml_file)
773 current_item = 0
774 while 1:
775 menu_list = []
776 for item in fn:
777 menu_list.append(item['text'])
778 menu_list.append("Install!")
779 code, menuitem = d.menu("Choose an option", choices=dmenu_list_to_choices(menu_list), height=20, menu_height=13, default_item=str(current_item), cancel="Exit")
780 if code != DLG_OK:
781 if d.yesno("Do you really want to exit before the install is complete?") == DLG_YES:
782 if d.yesno("Do you want to save the InstallProfile XML file?") == DLG_YES:
783 if install_profile_xml_file == None: install_profile_xml_file = ""
784 install_profile_xml_file = save_install_profile(xmlfilename=install_profile_xml_file)
785 sys.exit()
786 current_item = int(menuitem)
787 menuitem = menu_list[int(menuitem)-1]
788 for item in fn:
789 if menuitem == item['text']:
790 item['fn']()
791 current_item += 1
792 if menuitem == "Install!":
793 if install_profile_xml_file == None or install_profile_xml_file == "":
794 install_profile_xml_file = "tmp_install_profile.xml"
795 save_install_profile(xmlfilename=install_profile_xml_file, askforfilename=False)
796 cc.set_install_profile(install_profile)
797 cc.start_install()
798 d.gauge_start("Installation Started!", title="Installation progress")
799 num_steps_completed = 1
800 while 1:
801 notification = cc.getNotification()
802 if notification == None:
803 time.sleep(1)
804 continue
805 type = notification.get_type()
806 data = notification.get_data()
807 if type == "exception":
808 print "Exception received:"
809 print data
810 elif type == "int":
811 if data == GLIClientController.NEXT_STEP_READY:
812 next_step_waiting = False
813 next_step = cc.get_next_step_info()
814 num_steps = cc.get_num_steps()
815 i = (num_steps_completed*100)/num_steps
816 d.gauge_update(i, "On step %d of %d. Current step: %s" % (num_steps_completed, num_steps, next_step), update_text=1)
817 num_steps_completed += 1
818 #print "Next step: " + next_step
819 if cc.has_more_steps():
820 cc.next_step()
821 continue
822 if data == GLIClientController.INSTALL_DONE:
823 d.gauge_update(100, "Install completed!", update_text=1)
824 d.gauge_stop()
825 print "Install done!"
826 sys.exit(0)

Properties

Name Value
svn:eol-style native
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20