/[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 457 - (show annotations) (download) (as text)
Wed Mar 30 00:10:50 2005 UTC (15 years, 8 months ago) by agaffney
File MIME type: text/x-python
File size: 33523 byte(s)
Patch from zahna for extra arguments to the kernel.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20