Merge branch 'vendor/XZ'
[dragonfly.git] / usr.sbin / installer / dfuibe_installer / flow.c
1 /*
2  * Copyright (c)2004 The DragonFly Project.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  *   Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  *
11  *   Redistributions in binary form must reproduce the above copyright
12  *   notice, this list of conditions and the following disclaimer in
13  *   the documentation and/or other materials provided with the
14  *   distribution.
15  *
16  *   Neither the name of the DragonFly Project nor the names of its
17  *   contributors may be used to endorse or promote products derived
18  *   from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 /*
35  * flow.c
36  * Workflow logic for installer.
37  * $Id: flow.c,v 1.67 2005/04/08 08:09:23 cpressey Exp $
38  */
39
40 #include <stdarg.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44
45 #ifdef ENABLE_NLS
46 #include <libintl.h>
47 #include <locale.h>
48 #include "libdfui/lang.h"
49 #define _(String) gettext (String)
50 extern int _nl_msg_cat_cntr;
51 #else
52 #define _(String) (String)
53 #endif
54
55 #include "libaura/mem.h"
56 #include "libaura/dict.h"
57 #include "libaura/fspred.h"
58
59 #include "libdfui/dfui.h"
60 #ifdef DEBUG
61 #include "libdfui/dump.h"
62 #endif
63 #include "libdfui/system.h"
64
65 #include "libinstaller/commands.h"
66 #include "libinstaller/confed.h"
67 #include "libinstaller/diskutil.h"
68 #include "libinstaller/functions.h"
69 #include "libinstaller/package.h"
70 #include "libinstaller/uiutil.h"
71
72 #include "flow.h"
73 #include "fn.h"
74 #include "pathnames.h"
75
76 /*** GLOBALS ***/
77
78 void (*state)(struct i_fn_args *) = NULL;
79 int do_reboot;
80
81 /*** STATES ***/
82
83 /*
84  * The installer works like a big state machine.  Each major form is
85  * a state.  When the user has filled out the form satisfactorily,
86  * and selects "OK", there is a transition to the next state, in a
87  * mostly-linear order towards the final, "successfully installed"
88  * state.  The user may also "Cancel", which generally causes a
89  * transition to the previous state (but may also take them back to
90  * the very first state in some cases.)
91  *
92  * Installer States:
93  * - Select localization        optional
94  * - Welcome to DragonFly       required
95  * - Begin Installation         required
96  * - Select Disk                required
97  * - Format Disk                optional        dd, fdisk
98  * - Select Partition           required        dd, disklabel
99  * - Create Subpartitions       required        disklabel, newfs
100  * - Install DragonFly          required        swapon, mkdir, mount, cpdup
101  * - Install Bootstrap          optional        boot0cfg
102  * - Reboot                     optional        reboot
103  */
104
105 #ifdef ENABLE_NLS
106 void
107 state_lang_menu(struct i_fn_args *a)
108 {
109         struct dfui_form *f;
110         struct dfui_response *r;
111         int done = 0;
112         char *id;
113         int cancelled = 0;
114
115         while (!done) {
116                 f = dfui_form_create(
117                         "main_menu",
118                         _("Select Language"),
119                         _("Please select the language you wish you use."),
120                         "",
121
122                         "p", "role", "menu",
123
124                         "a", "default", "English",
125                         "English Standard Default", "",
126                         "a", "ru", "Russian",
127                         "Russian KOI8-R", "",
128                         NULL
129                 );
130
131                 if (!dfui_be_present(a->c, f, &r))
132                         abort_backend();
133
134                 id = aura_strdup(dfui_response_get_action_id(r));
135
136                 if (strcmp(id, "default") == 0) {
137                         state = state_welcome;
138                         return;
139                 } else {
140                         state = state_welcome;
141                         done = 1;
142                 }
143
144                 dfui_form_free(f);
145                 dfui_response_free(r);
146         }
147
148         /* set keymap, scrnmap, fonts */
149         if (!set_lang_syscons(id))
150                 return;
151
152         /* set envars */
153         if (!set_lang_envars(id))
154                 return;
155
156         dfui_be_set_global_setting(a->c, "lang", id, &cancelled);
157
158         /* XXX if (!cancelled) ... ? */
159
160         /* let gettext know about changes */
161         ++_nl_msg_cat_cntr;
162 }
163 #endif
164
165 /*
166  * state_welcome_livecd: the start state of the installer state machine,
167  * when run from the Live CD.  Briefly describe DragonFly to the user,
168  * and present them with a set of reasonable options of how to proceed.
169  */
170 void
171 state_welcome(struct i_fn_args *a)
172 {
173         struct dfui_form *f;
174         struct dfui_response *r;
175         char msg_buf[2][1024];
176
177         snprintf(msg_buf[0], sizeof(msg_buf[0]),
178             _("Welcome to %s"), OPERATING_SYSTEM_NAME);
179
180         snprintf(msg_buf[1], sizeof(msg_buf[1]),
181             _("Welcome to the %s Live CD."
182             "\n\n"
183             "%s is an efficient and elegant BSD "
184             "Unix-derived operating system.  For more information, see %s"
185             "\n\n"
186             "From this CD, you can boot into %s ``live'' "
187             "(without installing it) to evaluate it, to install it "
188             "manually, or to troubleshoot problems with an "
189             "existing installation, using either a command prompt "
190             "or menu-driven utilities."
191             "\n\n"
192             "Also, you can use this automated application to assist "
193             "you in installing %s on this computer and "
194             "configuring it once it is installed."
195             ""),
196             OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_URL,
197             OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_NAME);
198
199         if (!a->booted_from_livecd) {
200                 state = state_welcome_system;
201                 return;
202         }
203
204         f = dfui_form_create(
205             "welcome",
206             msg_buf[0],
207
208             msg_buf[1],
209
210             "",
211
212             "p",        "special",      "dfinstaller_welcome",
213
214             NULL
215         );
216
217         if (a->upgrade_menu_toggle) {
218                 snprintf(msg_buf[0], sizeof(msg_buf[0]),
219                     _("Upgrade a FreeBSD 4.X system to %s"),
220                     OPERATING_SYSTEM_NAME);
221                 dfui_form_action_add(f, "upgrade",
222                     dfui_info_new(_("Upgrade"),
223                     msg_buf[0], ""));
224         } else {
225                 snprintf(msg_buf[0], sizeof(msg_buf[0]),
226                     _("Install %s"), OPERATING_SYSTEM_NAME);
227                 snprintf(msg_buf[1], sizeof(msg_buf[1]),
228                     _("Install %s on a HDD or HDD partition on this computer"),
229                     OPERATING_SYSTEM_NAME);
230                 dfui_form_action_add(f, "install",
231                     dfui_info_new(msg_buf[0],
232                     msg_buf[1], ""));
233         }
234
235         snprintf(msg_buf[0], sizeof(msg_buf[0]),
236             _("Configure a %s system once it has been installed on HDD"),
237             OPERATING_SYSTEM_NAME);
238         dfui_form_action_add(f, "configure",
239             dfui_info_new(_("Configure an Installed System"),
240             msg_buf[0], ""));
241
242         dfui_form_action_add(f, "utilities",
243             dfui_info_new(_("Live CD Utilities"),
244             _("Utilities to work with disks, diagnostics, and the LiveCD Environment"), ""));
245
246         dfui_form_action_add(f, "exit",
247             dfui_info_new(_("Exit to Live CD"),
248             _("Exit this program to a login prompt with access to the LiveCD"), ""));
249
250         dfui_form_action_add(f, "reboot",
251             dfui_info_new(_("Reboot this Computer"),
252             _("Reboot this computer (e.g. to boot into a newly installed system)"), ""));
253
254         dfui_form_action_add(f, "configure_netboot",
255             dfui_info_new(_("Setup NetBoot Install Services"),
256             _("Setup machine as remote installation server"), ""));
257
258         if (!dfui_be_present(a->c, f, &r))
259                 abort_backend();
260
261         if (strcmp(dfui_response_get_action_id(r), "install") == 0) {
262                 state = state_begin_install;
263         } else if (strcmp(dfui_response_get_action_id(r), "upgrade") == 0) {
264                 state = state_begin_upgrade;
265         } else if (strcmp(dfui_response_get_action_id(r), "configure") == 0) {
266                 storage_set_selected_disk(a->s, NULL);
267                 storage_set_selected_slice(a->s, NULL);
268                 state = state_configure_menu;
269         } else if (strcmp(dfui_response_get_action_id(r), "utilities") == 0) {
270                 state = state_utilities_menu;
271         } else if (strcmp(dfui_response_get_action_id(r), "exit") == 0) {
272                 state = NULL;
273         } else if (strcmp(dfui_response_get_action_id(r), "configure_netboot") == 0) {
274                 state = state_setup_remote_installation_server;
275         } else if (strcmp(dfui_response_get_action_id(r), "reboot") == 0) {
276                 state = state_reboot;
277         }
278
279         dfui_form_free(f);
280         dfui_response_free(r);
281 }
282
283 /*
284  * state_welcome_system: the start state of the installer state machine,
285  * when run from the installed system.  Allow the user to configure the
286  * system.
287  */
288 void
289 state_welcome_system(struct i_fn_args *a)
290 {
291         struct dfui_form *f;
292         struct dfui_response *r;
293         char msg_buf[2][1024];
294
295         snprintf(msg_buf[0], sizeof(msg_buf[0]),
296             _("Configure this %s System"), OPERATING_SYSTEM_NAME);
297
298         snprintf(msg_buf[1], sizeof(msg_buf[1]),
299             _("Thank you for choosing %s."
300             "\n\n"
301             "For up-to-date news and information on %s, "
302             "make sure to check out"
303             "\n\n"
304             "%s"
305             "\n\n"
306             "You can use this automated application to assist "
307             "you in setting up this %s system."
308             ""),
309             OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_NAME,
310             OPERATING_SYSTEM_URL, OPERATING_SYSTEM_NAME);
311
312
313         f = dfui_form_create(
314             "welcome",
315             msg_buf[0],
316
317             msg_buf[1],
318
319             "",
320
321             "p",        "special",      "dfinstaller_welcome",
322
323             NULL
324         );
325
326         snprintf(msg_buf[0], sizeof(msg_buf[0]),
327             _("Configure this %s system"), OPERATING_SYSTEM_NAME);
328
329         dfui_form_action_add(f, "environment",
330             dfui_info_new(_("Configure this System"),
331             msg_buf[0], ""));
332
333         dfui_form_action_add(f, "utilities",
334             dfui_info_new(_("Utilities"),
335             _("Utilities to work with and diagnose disks and other subsystems"), ""));
336
337         dfui_form_action_add(f, "exit",
338             dfui_info_new(_("Exit Installer"),
339             _("Exit this program and return to the system"), ""));
340
341         if (!dfui_be_present(a->c, f, &r))
342                 abort_backend();
343
344         if (strcmp(dfui_response_get_action_id(r), "environment") == 0) {
345                 state = state_environment_menu;
346         } else if (strcmp(dfui_response_get_action_id(r), "utilities") == 0) {
347                 state = state_utilities_menu;
348         } else if (strcmp(dfui_response_get_action_id(r), "exit") == 0) {
349                 state = NULL;
350         } else if (strcmp(dfui_response_get_action_id(r), "reboot") == 0) {
351                 state = state_reboot;
352         }
353
354         dfui_form_free(f);
355         dfui_response_free(r);
356 }
357
358 void
359 state_configure_menu(struct i_fn_args *a)
360 {
361         struct dfui_form *f = NULL;
362         struct dfui_response *r = NULL;
363         struct commands *cmds;
364         int done = 0;
365         char msg_buf[2][1024];
366
367         if (storage_get_selected_disk(a->s) == NULL || storage_get_selected_slice(a->s) == NULL) {
368                 if (!survey_storage(a)) {
369                         inform(a->c, _("Errors occurred while probing "
370                             "the system for its storage capabilities."));
371                 }
372
373                 a->short_desc = _("Select the disk containing the installation.");
374                 a->cancel_desc = _("Return to Welcome Menu");
375                 fn_select_disk(a);
376                 if (!a->result || storage_get_selected_disk(a->s) == NULL) {
377                         state = state_welcome;
378                         return;
379                 }
380
381                 a->short_desc = _("Select the primary partition containing the installation.");
382                 a->cancel_desc = _("Return to Welcome Menu");
383                 fn_select_slice(a);
384
385                 if (!a->result || storage_get_selected_slice(a->s) == NULL) {
386                         state = state_welcome;
387                         return;
388                 }
389         }
390
391         a->cfg_root = "mnt";
392
393         if (during_install == 0) {
394                 switch (dfui_be_present_dialog(a->c, _("Select file system"),
395                     _("HAMMER|UFS|Return to Welcome Menu"),
396                     _("Please select the file system installed on the disk.\n\n")))
397                 {
398                 case 1:
399                         /* HAMMER */
400                         use_hammer = 1;
401                         break;
402                 case 2:
403                         /* UFS */
404                         use_hammer = 0;
405                         break;
406                 case 3:
407                         state = state_welcome;
408                         return;
409                         /* NOTREACHED */
410                         break;
411                 default:
412                         abort_backend();
413                         break;
414                 }
415         }
416
417         if (!mount_target_system(a)) {
418                 inform(a->c, _("Target system could not be mounted."));
419                 state = state_welcome;
420                 return;
421         }
422
423         snprintf(msg_buf[0], sizeof(msg_buf[0]),
424             _("The options on this menu allow you to configure a "
425             "%s system after it has already been "
426             "installed."), OPERATING_SYSTEM_NAME);
427
428         while (!done) {
429                 f = dfui_form_create(
430                     "configure_menu",
431                     _("Configure an Installed System"),
432                     msg_buf[0],
433                     "",
434                     "p", "role", "menu",
435
436                     "a", "set_timezone",
437                     _("Select timezone"),
438                     _("Set the Time Zone of your physical location"), "",
439                     "a", "set_datetime",
440                     _("Set date and time"),
441                     _("Set the Time and Date of your machine"), "",
442
443                     "a", "set_kbdmap",
444                     _("Set keyboard map"),
445                     _("Set what kind of keyboard layout you have"), "",
446                     "a", "root_passwd", _("Set root password"),
447                     _("Set the password that the root (superuser) account will use"), "",
448                     "a", "add_user", _("Add a user"),
449                     _("Add a user to the system"), "",
450                     "a", "assign_ip", _("Configure network interfaces"),
451                     _("Set up network interfaces (NICs, ethernet, TCP/IP, etc)"), "",
452                     "a", "assign_hostname_domain",
453                     _("Configure hostname and domain"),
454                     _("Configure the hostname and domain for this system"), "",
455                     /*
456                     "a", "select_services", "Select Services",
457                     "Enable/Disable system services (servers, daemons, etc.)", "",
458                     */
459                     "a", "set_vidfont",
460                     _("Set console font"),
461                     _("Set how the characters on your video console look"), "",
462                     "a", "set_scrnmap",
463                     _("Set screen map"),
464                     _("Set how characters are translated before console display"), "",
465                     /*
466                     "a", "install_pkgs", _("Install extra software packages"),
467                     _("Install third-party software packages from the LiveCD"), "",
468                     */
469                     "a", "remove_pkgs", _("Remove software packages"),
470                     _("Remove third-party software packages from the installed system"), "",
471
472                     "a", "cancel", _("Return to Welcome Menu"), "", "",
473                     "p", "accelerator", "ESC",
474
475                     NULL
476                 );
477
478                 if (!dfui_be_present(a->c, f, &r))
479                         abort_backend();
480
481                 /* XXX set up a */
482                 a->cfg_root = "mnt/";
483                 if (strcmp(dfui_response_get_action_id(r), "root_passwd") == 0) {
484                         fn_root_passwd(a);
485                 } else if (strcmp(dfui_response_get_action_id(r), "add_user") == 0) {
486                         fn_add_user(a);
487                 } else if (strcmp(dfui_response_get_action_id(r), "install_pkgs") == 0) {
488                         fn_install_packages(a);
489                 } else if (strcmp(dfui_response_get_action_id(r), "remove_pkgs") == 0) {
490                         fn_remove_packages(a);
491                 } else if (strcmp(dfui_response_get_action_id(r), "assign_ip") == 0) {
492                         fn_assign_ip(a);
493                 } else if (strcmp(dfui_response_get_action_id(r), "assign_hostname_domain") == 0) {
494                         fn_assign_hostname_domain(a);
495                 } else if (strcmp(dfui_response_get_action_id(r), "select_services") == 0) {
496                         fn_select_services(a);
497                 } else if (strcmp(dfui_response_get_action_id(r), "set_kbdmap") == 0) {
498                         fn_set_kbdmap(a);
499                 } else if (strcmp(dfui_response_get_action_id(r), "set_vidfont") == 0) {
500                         fn_set_vidfont(a);
501                 } else if (strcmp(dfui_response_get_action_id(r), "set_scrnmap") == 0) {
502                         fn_set_scrnmap(a);
503                 } else if (strcmp(dfui_response_get_action_id(r), "set_timezone") == 0) {
504                         fn_set_timezone(a);
505                 } else if (strcmp(dfui_response_get_action_id(r), "set_datetime") == 0) {
506                         fn_assign_datetime(a);
507                 } else if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
508                         state = state_welcome;
509                         done = 1;
510                 }
511
512                 dfui_form_free(f);
513                 dfui_response_free(r);
514         }
515
516         /*
517          * Before unmounting the system, write out any changes to rc.conf.
518          */
519         config_vars_write(rc_conf, CONFIG_TYPE_SH,
520             "%s%setc/rc.conf", a->os_root, a->cfg_root);
521
522         /*
523          * Clear out configuration variable table in memory.
524          */
525         config_vars_free(rc_conf);
526         rc_conf = config_vars_new();
527
528         /*
529          * Finally, unmount the system we mounted on /mnt and remove mappings.
530          */
531         cmds = commands_new();
532         unmount_all_under(a, cmds, "%smnt", a->os_root);
533         commands_execute(a, cmds);
534         commands_free(cmds);
535
536         if (remove_all_mappings(a) == NULL)
537                 inform(a->c, _("Warning: mappings could not be removed."));
538 }
539
540 void
541 state_utilities_menu(struct i_fn_args *a)
542 {
543         struct dfui_form *f;
544         struct dfui_response *r;
545
546         if (!survey_storage(a)) {
547                 inform(a->c, _("Errors occurred while probing "
548                     "the system for its storage capabilities."));
549         }
550
551         f = dfui_form_create(
552             "utilities_menu",
553             _("Live CD Utilities Menu"),
554             _("On these submenus you will find utilities to help "
555             "you set up your Live CD environment, diagnose "
556             "and analyse this system, and work with "
557             "the devices attached to this computer."),
558             "",
559             "p", "role", "menu",
560             "a", "environment", _("LiveCD Environment"),
561             _("Configure the LiveCD Environment"), "",
562             "a", "diagnostics", _("System Diagnostics"),
563             _("Probe and display detailed information about this system"), "",
564             "a", "diskutil", _("Disk Utilities"),
565             _("Format and check hard drives and floppy disks"), "",
566             "a", "livecd", _("Exit to Live CD"),
567             _("Exit this program to a login prompt with access to the LiveCD"), "",
568             "a", "reboot",
569             _("Reboot this Computer"), "", "",
570             "a", "cancel",
571             _("Return to Welcome Menu"), "", "",
572             "p", "accelerator", "ESC",
573             NULL
574         );
575
576         if (!dfui_be_present(a->c, f, &r))
577                 abort_backend();
578
579         if (strcmp(dfui_response_get_action_id(r), "environment") == 0)
580                 state = state_environment_menu;
581         else if (strcmp(dfui_response_get_action_id(r), "diagnostics") == 0)
582                 state = state_diagnostics_menu;
583         else if (strcmp(dfui_response_get_action_id(r), "diskutil") == 0)
584                 state = state_diskutil_menu;
585         else if (strcmp(dfui_response_get_action_id(r), "livecd") == 0)
586                 state = NULL;
587         else if (strcmp(dfui_response_get_action_id(r), "reboot") == 0)
588                 state = state_reboot;
589         else if (strcmp(dfui_response_get_action_id(r), "cancel") == 0)
590                 state = state_welcome;
591
592         dfui_form_free(f);
593         dfui_response_free(r);
594 }
595
596 void
597 state_environment_menu(struct i_fn_args *a)
598 {
599         struct dfui_form *f;
600         struct dfui_response *r;
601         int done = 0;
602         char msg_buf[2][1024];
603
604         snprintf(msg_buf[0], sizeof(msg_buf[0]),
605             _("On this menu you will find utilities to help you "
606             "set up your Live CD environment.\n\nNote "
607             "that these functions affect only the LiveCD "
608             "environment you are currently using, and they will "
609             "not affect any system that may be installed on "
610             "this computer UNLESS you subsequently choose to "
611             "install %s from this environment, in which "
612             "case they will be copied to the newly installed "
613             "system."), OPERATING_SYSTEM_NAME);
614
615         while (!done) {
616                 f = dfui_form_create(
617                     "environment_menu",
618                     _("Live CD Environment Menu"),
619                     msg_buf[0],
620                     "",
621                     "p", "role", "menu",
622
623                     "a", "set_timezone",
624                     _("Select timezone"),
625                     _("Set the Time Zone of your physical location"), "",
626                     "a", "set_datetime",
627                     _("Set date and time"),
628                     _("Set the Time and Date of your machine"), "",
629
630                     "a", "set_kbdmap",
631                     _("Set keyboard map"),
632                     _("Set what kind of keyboard layout you have"), "",
633                     "a", "set_vidfont",
634                     _("Set console font"),
635                     _("Set how the characters on your video console look"), "",
636                     "a", "set_scrnmap",
637                     _("Set screen map"),
638                     _("Set how characters are translated before console display"), "",
639
640                     "a", "assign_hostname_domain",
641                     _("Configure hostname and domain"),
642                     _("Configure the hostname and domain for this system"), "",
643                     "a", "assign_ip",
644                     _("Configure network interfaces"),
645                     _("Set up network interfaces (NICs, ethernet, TCP/IP, etc)"), "",
646
647                     "a", "cancel",
648                     _("Return to Utilities Menu"), "", "",
649                     "p", "accelerator", "ESC",
650
651                     NULL
652                 );
653
654                 if (!dfui_be_present(a->c, f, &r))
655                         abort_backend();
656
657                 /* Set up a */
658                 a->cfg_root = "";
659                 if (strcmp(dfui_response_get_action_id(r), "set_kbdmap") == 0) {
660                         fn_set_kbdmap(a);
661                 } else if (strcmp(dfui_response_get_action_id(r), "set_vidfont") == 0) {
662                         fn_set_vidfont(a);
663                 } else if (strcmp(dfui_response_get_action_id(r), "set_scrnmap") == 0) {
664                         fn_set_scrnmap(a);
665                 } else if (strcmp(dfui_response_get_action_id(r), "assign_hostname_domain") == 0) {
666                         fn_assign_hostname_domain(a);
667                 } else if (strcmp(dfui_response_get_action_id(r), "assign_ip") == 0) {
668                         fn_assign_ip(a);
669                 } else if (strcmp(dfui_response_get_action_id(r), "set_timezone") == 0) {
670                         fn_set_timezone(a);
671                 } else if (strcmp(dfui_response_get_action_id(r), "set_datetime") == 0) {
672                         fn_assign_datetime(a);
673                 } else if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
674                         state = state_utilities_menu;
675                         done = 1;
676                 }
677
678                 dfui_form_free(f);
679                 dfui_response_free(r);
680         }
681 }
682
683 void
684 state_diagnostics_menu(struct i_fn_args *a)
685 {
686         struct dfui_form *f;
687         struct dfui_action *k;
688         struct dfui_response *r;
689         int done = 0;
690
691         while (!done) {
692                 f = dfui_form_create(
693                     "utilities_menu",
694                     _("Live CD Diagnostics Menu"),
695                     _("These functions can help you diagnose this system."),
696                     "",
697                     "p", "role", "menu",
698
699                     "a", "show_dmesg",
700                     _("Display system startup messages"),
701                     _("Display system startup messages (dmesg)"), "",
702                     "a", "pciconf",
703                     _("Display PCI devices"),
704                     _("Display PCI devices (pciconf)"), "",
705                     "a", "natacontrol",
706                     _("Display ATA devices"),
707                     _("Display ATA devices (natacontrol)"), "",
708                     NULL
709                 );
710
711                 k = dfui_form_action_add(f, "cancel",
712                     dfui_info_new(_("Return to Utilities Menu"), "", ""));
713                 dfui_action_property_set(k, "accelerator", "ESC");
714
715                 if (!dfui_be_present(a->c, f, &r))
716                         abort_backend();
717
718                 /* XXX set up a */
719                 if (strcmp(dfui_response_get_action_id(r), "show_dmesg") == 0) {
720                         fn_show_dmesg(a);
721                 } else if (strcmp(dfui_response_get_action_id(r), "pciconf") == 0) {
722                         fn_show_pciconf(a);
723                 } else if (strcmp(dfui_response_get_action_id(r), "natacontrol") == 0) {
724                         fn_show_natacontrol(a);
725                 } else if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
726                         state = state_utilities_menu;
727                         done = 1;
728                 }
729
730                 dfui_form_free(f);
731                 dfui_response_free(r);
732         }
733 }
734
735 void
736 state_diskutil_menu(struct i_fn_args *a)
737 {
738         struct dfui_form *f;
739         struct dfui_action *k;
740         struct dfui_response *r;
741         int done = 0;
742
743         while (!done) {
744                 f = dfui_form_create(
745                     "utilities_menu",
746                     _("Disk Utilities Menu"),
747                     _("These functions let you manipulate the storage devices "
748                     "attached to this computer."),
749                     "",
750
751                     "p", "role", "menu",
752
753                     "a", "format_hdd",
754                     _("Format a hard disk drive"), "", "",
755                     "a", "wipe_start_of_disk",
756                     _("Wipe out the start of a disk"), "", "",
757                     "a", "wipe_start_of_slice",
758                     _("Wipe out the start of a primary partition"), "", "",
759                     "a", "install_bootblocks",
760                     _("Install bootblocks on disks"), "", "",
761                     "a", "format_msdos_floppy",
762                     _("Format an MSDOS floppy"), "", "",
763                     NULL
764                 );
765
766                 if (is_file("%sboot/cdboot.flp.bz2", a->os_root)) {
767                         dfui_form_action_add(f, "create_cdboot_floppy",
768                             dfui_info_new(_("Create a CDBoot floppy"),
769                             "",
770                             ""));
771                 }
772
773                 k = dfui_form_action_add(f, "cancel",
774                     dfui_info_new(_("Return to Utilities Menu"), "", ""));
775                 dfui_action_property_set(k, "accelerator", "ESC");
776
777                 if (!dfui_be_present(a->c, f, &r))
778                         abort_backend();
779
780                 /* XXX set up a */
781                 if (strcmp(dfui_response_get_action_id(r), "format_hdd") == 0) {
782                         storage_set_selected_disk(a->s, NULL);
783                         storage_set_selected_slice(a->s, NULL);
784                         fn_format_disk(a);
785                 } else if (strcmp(dfui_response_get_action_id(r), "wipe_start_of_disk") == 0) {
786                         fn_wipe_start_of_disk(a);
787                 } else if (strcmp(dfui_response_get_action_id(r), "wipe_start_of_slice") == 0) {
788                         fn_wipe_start_of_slice(a);
789                 } else if (strcmp(dfui_response_get_action_id(r), "install_bootblocks") == 0) {
790                         a->short_desc = _("Select the disks on which "
791                             "you wish to install bootblocks.");
792                         a->cancel_desc = _("Return to Utilities Menu");
793                         fn_install_bootblocks(a, NULL);
794                 } else if (strcmp(dfui_response_get_action_id(r), "format_msdos_floppy") == 0) {
795                         fn_format_msdos_floppy(a);
796                 } else if (strcmp(dfui_response_get_action_id(r), "create_cdboot_floppy") == 0) {
797                         fn_create_cdboot_floppy(a);
798                 } else if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
799                         state = state_utilities_menu;
800                         done = 1;
801                 }
802
803                 dfui_form_free(f);
804                 dfui_response_free(r);
805         }
806 }
807
808 /** INSTALLER STATES **/
809
810 /*
811  * state_begin_upgrade: Ask the user where the freebsd
812  * 4.X install is and make sure its safe to proceed.
813  *
814  */
815 void
816 state_begin_upgrade(struct i_fn_args *a)
817 {
818         //struct dfui_form *f = NULL;
819         //struct dfui_response *r = NULL;
820         //int done = 0;
821
822         if (storage_get_selected_disk(a->s) == NULL || storage_get_selected_slice(a->s) == NULL) {
823                 if (!survey_storage(a)) {
824                         inform(a->c, _("Errors occurred while probing "
825                             "the system for its storage capabilities."));
826                 }
827
828                 a->short_desc = _("Select the disk containing the installation that you would like to upgrade.");
829                 a->cancel_desc = _("Return to Welcome Menu");
830                 fn_select_disk(a);
831                 if (!a->result || storage_get_selected_disk(a->s) == NULL) {
832                         state = state_welcome;
833                         return;
834                 }
835
836                 a->short_desc = _("Select the primary partition containing the installation you would like to upgrade.");
837                 a->cancel_desc = _("Return to Welcome Menu");
838                 fn_select_slice(a);
839
840                 if (!a->result || storage_get_selected_slice(a->s) == NULL) {
841                         state = state_welcome;
842                         return;
843                 }
844         }
845
846         a->cfg_root = "mnt";
847         if (!mount_target_system(a)) {
848                 inform(a->c, _("Target system could not be mounted."));
849                 state = state_welcome;
850                 return;
851         }
852 }
853
854 /*
855  * state_begin_install: Briefly describe the install process
856  * to the user, and let them proceed (or not.)
857  */
858 void
859 state_begin_install(struct i_fn_args *a)
860 {
861         struct dfui_form *f;
862         struct dfui_response *r;
863         char msg_buf[3][1024];
864
865         snprintf(msg_buf[0], sizeof(msg_buf[0]),
866             _("This application will install %s"
867             " on one of the hard disk drives attached to this computer. "
868             "It has been designed to make it easy to install "
869             "%s in the typical case. "
870             "If you have special requirements that are not addressed "
871             "by this installer, or if you have problems using it, you "
872             "are welcome to install %s manually. "
873             "To do so select Exit to Live CD, login as root, and follow "
874             "the instructions given in the file /README ."
875             "\n\n"
876             "NOTE! As with any installation process, YOU ARE "
877             "STRONGLY ENCOURAGED TO BACK UP ANY IMPORTANT DATA ON THIS "
878             "COMPUTER BEFORE PROCEEDING!"
879             ""),
880             OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_NAME,
881             OPERATING_SYSTEM_NAME);
882
883         snprintf(msg_buf[1], sizeof(msg_buf[1]),
884             _("Some situations in which you might not wish to use this "
885             "installer are:\n\n"
886             "- you want to install %s onto a "
887             "logical/extended partition;\n"
888             "- you want to install %s "
889             "onto a ``dangerously dedicated'' disk; or\n"
890             "- you want full and utter control over the install process."
891             ""),
892             OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_NAME);
893
894         snprintf(msg_buf[2], sizeof(msg_buf[2]),
895             _("Install %s"), OPERATING_SYSTEM_NAME);
896
897         f = dfui_form_create(
898             "begin_install",
899             _("Begin Installation"),
900             msg_buf[0],
901
902             msg_buf[1],
903             "p", "special", "dfinstaller_begin_install",
904             "p", "minimum_width", "76",
905
906             "a", "proceed", msg_buf[2],
907             "", "",
908             "a", "cancel", _("Return to Welcome Menu"),
909             "", "",
910             "p", "accelerator", "ESC",
911             "a", "livecd", _("Exit to Live CD"),
912             "", "",
913             NULL
914         );
915
916         if (!dfui_be_present(a->c, f, &r))
917                 abort_backend();
918
919         if (strcmp(dfui_response_get_action_id(r), "proceed") == 0) {
920                 if (!survey_storage(a)) {
921                         inform(a->c, _("Errors occurred while probing "
922                             "the system for its storage capabilities."));
923                 }
924                 state = state_select_disk;
925         } else if (strcmp(dfui_response_get_action_id(r), "livecd") == 0) {
926                 state = NULL;
927         } else if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
928                 state = state_welcome;
929         }
930
931         dfui_form_free(f);
932         dfui_response_free(r);
933 }
934
935 /*
936  * state_select_disk: ask the user on which physical disk they wish
937  * to install DragonFly.
938  */
939 void
940 state_select_disk(struct i_fn_args *a)
941 {
942         struct disk *d;
943         int num_disks = 0;
944         char msg_buf[1][1024];
945
946         for (d = storage_disk_first(a->s); d != NULL; d = disk_next(d))
947                 num_disks++;
948
949         if (num_disks == 0) {
950                 inform(a->c, _("The installer could not find any disks suitable "
951                     "for installation (IDE or SCSI) attached to this "
952                     "computer.  If you wish to install %s"
953                     " on an unorthodox storage device, you will have to "
954                     "exit to a LiveCD command prompt and install it "
955                     "manually, using the file /README as a guide."),
956                     OPERATING_SYSTEM_NAME);
957                 state = state_welcome;
958                 return;
959         }
960
961         snprintf(msg_buf[0], sizeof(msg_buf[0]),
962             _("Select a disk on which to install %s"),
963             OPERATING_SYSTEM_NAME);
964         a->short_desc = msg_buf[0];
965         a->cancel_desc = _("Return to Begin Installation");
966         fn_select_disk(a);
967         if (!a->result || storage_get_selected_disk(a->s) == NULL) {
968                 state = state_begin_install;
969         } else {
970 #if 0
971                 if (disk_get_capacity(storage_get_selected_disk(a->s)) < DISK_MIN) {
972                         inform(a->c, _("WARNING: you should have a disk "
973                             "at least %dM in size, or "
974                             "you may encounter problems trying to "
975                             "install %s."), DISK_MIN, OPERATING_SYSTEM_NAME);
976                 }
977 #endif
978                 state = state_format_disk;
979         }
980 }
981
982 void
983 state_ask_fs(struct i_fn_args *a)
984 {
985         use_hammer = 0;
986
987         switch (dfui_be_present_dialog(a->c, _("Select file system"),
988             _("Use HAMMER|Use UFS|Return to Select Disk"),
989             _("Please select the file system you want to use with %s.\n\n"
990               "HAMMER is the new %s file system.  UFS is the traditional BSD file system."),
991             OPERATING_SYSTEM_NAME,
992             OPERATING_SYSTEM_NAME))
993         {
994         case 1:
995                 /* HAMMER */
996                 use_hammer = 1;
997                 break;
998         case 2:
999                 /* UFS */
1000                 break;
1001         case 3:
1002                 state = state_select_disk;
1003                 return;
1004                 /* NOTREACHED */
1005                 break;
1006         default:
1007                 abort_backend();
1008                 break;
1009         }
1010         state = state_create_subpartitions;
1011 }
1012
1013 /*
1014  * state_format_disk: ask the user if they wish to format the disk they
1015  * selected.
1016  */
1017 void
1018 state_format_disk(struct i_fn_args *a)
1019 {
1020         switch (dfui_be_present_dialog(a->c, _("How Much Disk?"),
1021             _("Use Entire Disk|Use Part of Disk|Return to Select Disk"),
1022             _("Select how much of this disk you want to use for %s.\n\n%s"),
1023             OPERATING_SYSTEM_NAME,
1024             disk_get_desc(storage_get_selected_disk(a->s)))) {
1025         case 1:
1026                 /* Entire Disk */
1027                 if (measure_activated_swap_from_disk(a, storage_get_selected_disk(a->s)) > 0) {
1028                         if (swapoff_all(a) == NULL) {
1029                                 inform(a->c, _("Warning: swap could not be turned off."));
1030                                 state = state_select_disk;
1031                                 return;
1032                         }
1033                 }
1034
1035                 fn_format_disk(a);
1036                 if (a->result)
1037                         state = state_ask_fs;
1038                 else
1039                         state = state_format_disk;
1040                 break;
1041         case 2:
1042                 /* Part of Disk */
1043                 state = state_select_slice;
1044                 break;
1045         case 3:
1046                 /* Return */
1047                 state = state_select_disk;
1048                 break;
1049         default:
1050                 abort_backend();
1051                 break;
1052         }
1053 }
1054
1055 /*
1056  * state_select_slice: ask the user which slice they wish to install
1057  * DragonFly on.  In order to avoid confusing them, refer to it as
1058  * a primary partition, but tell them what BSD has traditionally called
1059  * it, too.
1060  */
1061 void
1062 state_select_slice(struct i_fn_args *a)
1063 {
1064         char msg_buf[1][1024];
1065
1066         snprintf(msg_buf[0], sizeof(msg_buf[0]),
1067             _("Select the existing primary partition (also "
1068             "known as a `slice' in the BSD tradition) on "
1069             "which to install %s.\n\n"
1070             "Note that if you do not have any existing "
1071             "primary partitions on this disk, you must "
1072             "first create some. This installer does not "
1073             "currently have the ability to do this, so "
1074             "you will have to exit and run fdisk (in "
1075             "DOS or *BSD) or parted (in Linux) to do so."),
1076             OPERATING_SYSTEM_NAME);
1077
1078         a->short_desc = msg_buf[0];
1079         a->cancel_desc = _("Return to Select Disk");
1080         fn_select_slice(a);
1081         if (!a->result || storage_get_selected_slice(a->s) == NULL) {
1082                 state = state_select_disk;
1083         } else {
1084                 if (measure_activated_swap_from_slice(a, storage_get_selected_disk(a->s),
1085                     storage_get_selected_slice(a->s)) > 0) {
1086                         if (swapoff_all(a) == NULL) {
1087                                 inform(a->c, _("Warning: swap could not be turned off."));
1088                                 state = state_select_slice;
1089                                 return;
1090                         }
1091                 }
1092
1093                 if (slice_get_capacity(storage_get_selected_slice(a->s)) < DISK_MIN) {
1094                         inform(a->c, _("WARNING: you should have a primary "
1095                             "partition at least %dM in size, or "
1096                             "you may encounter problems trying to "
1097                             "install %s."), DISK_MIN, OPERATING_SYSTEM_NAME);
1098                 }
1099
1100                 if (confirm_dangerous_action(a->c,
1101                     _("WARNING!  ALL data in primary partition #%d,\n\n%s\n\non the "
1102                     "disk\n\n%s\n\n will be IRREVOCABLY ERASED!\n\nAre you "
1103                     "ABSOLUTELY SURE you wish to take this action?  This is "
1104                     "your LAST CHANCE to cancel!"),
1105                     slice_get_number(storage_get_selected_slice(a->s)),
1106                     slice_get_desc(storage_get_selected_slice(a->s)),
1107                     disk_get_desc(storage_get_selected_disk(a->s)))) {
1108                         if (!format_slice(a)) {
1109                                 inform(a->c, _("Primary partition #%d was "
1110                                     "not correctly formatted, and may "
1111                                     "now be in an inconsistent state. "
1112                                     "We recommend re-formatting it "
1113                                     "before proceeding."),
1114                                     slice_get_number(storage_get_selected_slice(a->s)));
1115                         } else {
1116                                 inform(a->c, _("Primary partition #%d was formatted."),
1117                                     slice_get_number(storage_get_selected_slice(a->s)));
1118                                 state = state_ask_fs;
1119                         }
1120                 } else {
1121                         inform(a->c, _("Action cancelled - no primary partitions were formatted."));
1122                         state = state_select_slice;
1123                 }
1124         }
1125 }
1126
1127 /*
1128  * state_create_subpartitions: let the user specify what subpartitions they
1129  * want on the disk, how large each should be, and where it should be mounted.
1130  */
1131 void
1132 state_create_subpartitions(struct i_fn_args *a)
1133 {
1134         struct commands *cmds;
1135
1136         if (measure_activated_swap_from_slice(a, storage_get_selected_disk(a->s),
1137             storage_get_selected_slice(a->s)) > 0) {
1138                 if (swapoff_all(a) == NULL) {
1139                         inform(a->c, _("Warning: swap could not be turned off."));
1140                         state = disk_get_formatted(storage_get_selected_disk(a->s)) ?
1141                             state_select_disk : state_select_slice;
1142                         return;
1143                 }
1144         }
1145
1146         cmds = commands_new();
1147
1148         /*
1149          * Auto-disklabel the slice.
1150          * NB: one cannot use "/dev/adXsY" here -
1151          * it must be in the form "adXsY".
1152          */
1153         command_add(cmds, "%s%s -W %s",
1154             a->os_root, cmd_name(a, "DISKLABEL64"),
1155             slice_get_device_name(storage_get_selected_slice(a->s)));
1156         command_add(cmds, "%s%s if=/dev/zero of=/dev/%s bs=32k count=16",
1157             a->os_root, cmd_name(a, "DD"),
1158             slice_get_device_name(storage_get_selected_slice(a->s)));
1159         command_add(cmds, "%s%s -B -r -w %s auto",
1160             a->os_root, cmd_name(a, "DISKLABEL64"),
1161             slice_get_device_name(storage_get_selected_slice(a->s)));
1162         commands_execute(a, cmds);
1163         commands_free(cmds);
1164
1165         if (use_hammer)
1166                 fn_create_subpartitions_hammer(a);
1167         else
1168                 fn_create_subpartitions_ufs(a);
1169
1170         if (a->result) {
1171                 state = state_install_os;
1172         } else {
1173                 state = disk_get_formatted(storage_get_selected_disk(a->s)) ?
1174                     state_select_disk : state_select_slice;
1175         }
1176 }
1177
1178 /*
1179  * state_install_os: actually put DragonFly on the disk.
1180  */
1181 void
1182 state_install_os(struct i_fn_args *a)
1183 {
1184         struct dfui_form *f;
1185         struct dfui_response *r;
1186         char msg_buf[1][1024];
1187
1188         snprintf(msg_buf[0], sizeof(msg_buf[0]),
1189             _("Everything is now ready to install the actual files which "
1190             "comprise the %s operating system "
1191             "on the selected partition of the selected disk.\n\n"
1192             "Note that this process will take quite a while to finish. "
1193             "You may wish to take a break now and come back to the "
1194             "computer in a short while."),
1195             OPERATING_SYSTEM_NAME);
1196
1197         f = dfui_form_create(
1198             "install_os",
1199             _("Install OS"),
1200             msg_buf[0],
1201
1202             "",
1203
1204             "p", "role", "confirm",
1205             "p", "special", "dfinstaller_install_os",
1206
1207             "a", "ok", _("Begin Installing Files"), "", "",
1208             "a", "cancel", _("Return to Create Subpartitions"), "", "",
1209             "p", "accelerator", "ESC",
1210
1211             NULL
1212         );
1213
1214         if (!dfui_be_present(a->c, f, &r))
1215                 abort_backend();
1216
1217         if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
1218                 state = state_create_subpartitions;
1219         } else {
1220                 fn_install_os(a);
1221                 if (a->result)
1222                         state = state_install_bootstrap;
1223         }
1224
1225         dfui_form_free(f);
1226         dfui_response_free(r);
1227 }
1228
1229 /*
1230  * state_install_bootstrap: put boot0 bootblocks on selected disks.
1231  */
1232 void
1233 state_install_bootstrap(struct i_fn_args *a)
1234 {
1235         char msg_buf[1][1024];
1236
1237         snprintf(msg_buf[0], sizeof(msg_buf[0]),
1238             _("You may now wish to install bootblocks on one or more disks. "
1239             "If you already have a boot manager installed, you can skip "
1240             "this step (but you may have to configure your boot manager "
1241             "separately.)  If you installed %s on a disk other "
1242             "than your first disk, you will need to put the bootblock "
1243             "on at least your first disk and the %s disk."),
1244             OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_NAME);
1245
1246         a->short_desc = msg_buf[0];
1247         a->cancel_desc = _("Skip this Step");
1248         fn_install_bootblocks(a,
1249             disk_get_device_name(storage_get_selected_disk(a->s)));
1250         state = state_finish_install;
1251 }
1252
1253 /*
1254  * Finish up the install.
1255  */
1256 void
1257 state_finish_install(struct i_fn_args *a)
1258 {
1259         char msg_buf[1][1024];
1260         during_install = 1;
1261
1262         snprintf(msg_buf[0], sizeof(msg_buf[0]),
1263             "%s is Installed!",
1264             OPERATING_SYSTEM_NAME);
1265
1266         switch (dfui_be_present_dialog(a->c, msg_buf[0],
1267             _("Configure this System|Reboot|Return to Welcome Menu"),
1268             _("Congratulations!\n\n"
1269             "%s has successfully been installed on "
1270             "this computer. You may now proceed to configure "
1271             "the installation. Alternately, you may wish to "
1272             "reboot the computer and boot into the installed "
1273             "system to confirm that it works."),
1274             OPERATING_SYSTEM_NAME)) {
1275         case 1:
1276                 state = state_configure_menu;
1277                 break;
1278         case 2:
1279                 state = state_reboot;
1280                 break;
1281         case 3:
1282                 state = state_welcome;
1283                 break;
1284         default:
1285                 abort_backend();
1286         }
1287 }
1288
1289 /*
1290  * state_reboot: reboot the machine.
1291  */
1292 void
1293 state_reboot(struct i_fn_args *a)
1294 {
1295         struct dfui_form *f;
1296         struct dfui_response *r;
1297
1298         f = dfui_form_create(
1299             "reboot",
1300             _("Reboot"),
1301             _("This machine is about to be shut down. "
1302             "After the machine has reached its shutdown state, "
1303             "you may remove the CD from the CD-ROM drive tray "
1304             "and press Enter to reboot from the HDD."),
1305
1306             "",
1307
1308             "p", "role", "confirm",
1309
1310             "a", "ok", _("Reboot"), "", "",
1311             "a", "cancel", _("Return to Welcome Menu"), "", "",
1312             "p", "accelerator", "ESC",
1313             NULL
1314         );
1315
1316         if (!dfui_be_present(a->c, f, &r))
1317                 abort_backend();
1318
1319         if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
1320                 state = state_welcome;
1321         } else {
1322                 do_reboot = 1;
1323                 state = NULL;
1324         }
1325
1326         dfui_form_free(f);
1327         dfui_response_free(r);
1328 }
1329
1330 /*
1331  *
1332  *  state_setup_remote_installation_server:
1333  *  Setup a remote boot installation environment where a machine
1334  *  can boot via DHCP/TFTP/NFS and have a running environment
1335  *  where the installer can setup the machine.
1336  *
1337  */
1338 void
1339 state_setup_remote_installation_server(struct i_fn_args *a)
1340 {
1341         FILE *p;
1342         struct commands *cmds;
1343         struct dfui_form *f;
1344         struct dfui_action *k;
1345         struct dfui_response *r;
1346         char *word;
1347         char interface[256];
1348         char line[256];
1349
1350         switch (dfui_be_present_dialog(a->c, _("Enable Netboot Installation Services?"),
1351             _("Enable NetBoot Installation Services|No thanks"),
1352             _("NetBoot Installation Services allows this machine to become "
1353             "a Installation Server that will allow the clients to boot over the network "
1354             "via PXE and start the Installation Environment."
1355             "\n\n*NOTE!*  This will assign the IP Address of 10.1.0.1/24 to the selected interface."
1356             "\n\nWould you like to provision this machine to serve up the LiveCD/Installer?"))) {
1357                 case 1:
1358                         /*
1359                          * Get interface list.
1360                          */
1361                         p = popen("/sbin/ifconfig -l", "r");
1362                         /* XXX it's possible (though extremely unlikely) this will fail. */
1363                         while (fgets(line, 255, p) != NULL)
1364                                 line[strlen(line) - 1] = '\0';
1365                         pclose(p);
1366
1367                         f = dfui_form_create(
1368                             "assign_ip",
1369                             _("Setup NetBoot Installation Environment"),
1370                             _("Please select which interface you would like to configure:"),
1371                             "",
1372                             "p",        "role", "menu",
1373                             NULL
1374                         );
1375
1376                         /* Loop through array. */
1377                         word = strtok(line, " \t");
1378                         while (word != NULL) {
1379                                 dfui_form_action_add(f, word,
1380                                     dfui_info_new(word, "", ""));
1381                                 word = strtok(NULL, " ");
1382                         }
1383
1384                         k = dfui_form_action_add(f, "cancel",
1385                             dfui_info_new("Cancel", "", ""));
1386                         dfui_action_property_set(k, "accelerator", "ESC");
1387
1388                         if (!dfui_be_present(a->c, f, &r))
1389                                 abort_backend();
1390
1391                         strlcpy(interface, dfui_response_get_action_id(r), 256);
1392
1393                         if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
1394                                 dfui_form_free(f);
1395                                 dfui_response_free(r);
1396                                 return;
1397                         }
1398
1399                         /*
1400                          *
1401                          * Issues the necessary commands to setup the remote boot environment
1402                          *
1403                          */
1404                         cmds = commands_new();
1405                         command_add(cmds, "%s%s %s 10.1.0.1 netmask 255.255.255.0",
1406                             a->os_root, cmd_name(a, "IFCONFIG"), interface);
1407                         command_add(cmds, "%s%s -p %stftpdroot",
1408                             a->os_root, cmd_name(a, "MKDIR"), a->tmp);
1409                         command_add(cmds, "%s%s %sboot/pxeboot %stftpdroot",
1410                             a->os_root, cmd_name(a, "CP"), a->os_root, a->tmp);
1411                         command_add(cmds, "%s%s %s -ro -alldirs -maproot=root: -network 10.1.0.0 -mask 255.255.255.0 >> %setc/exports",
1412                             a->os_root, cmd_name(a, "ECHO"), a->os_root, a->os_root);
1413                         command_add(cmds, "%s%s tftp dgram udp wait root %s%s tftpd -l -s %stftpdroot >> %setc/inetd.conf",
1414                             a->os_root, cmd_name(a, "ECHO"),
1415                             a->os_root, cmd_name(a, "TFTPD"),
1416                             a->tmp, a->os_root);
1417                         command_add(cmds, "%s%s",
1418                             a->os_root, cmd_name(a, "INETD"));
1419                         command_add(cmds, "%s%s %svar/db/dhcpd.leases",
1420                             a->os_root, cmd_name(a, "TOUCH"), a->os_root);
1421                         command_add(cmds, "%s%s -cf /etc/dhcpd.conf >/dev/null 2>&1",
1422                             a->os_root, cmd_name(a, "DHCPD"));
1423                         command_add(cmds, "%s%s >/dev/null 2>&1",
1424                             a->os_root, cmd_name(a, "RPCBIND"));
1425                         command_add(cmds, "%s%s -ln >/dev/null 2>&1",
1426                             a->os_root, cmd_name(a, "MOUNTD"));
1427                         command_add(cmds, "%s%s -u -t -n 6 >/dev/null 2>&1",
1428                             a->os_root, cmd_name(a, "NFSD"));
1429
1430                         if (commands_execute(a, cmds)) {
1431                                 inform(a->c, _("NetBoot installation services are now started."));
1432                         } else {
1433                                 inform(a->c, _("A failure occurred while provisioning the NetBoot environment.  Please check the logs."));
1434                         }
1435
1436                         commands_free(cmds);
1437                         dfui_form_free(f);
1438                         dfui_response_free(r);
1439
1440                         break;
1441                 case 2:
1442
1443                         break;
1444
1445         }
1446
1447         state = state_welcome;
1448
1449 }
1450
1451 /*** MAIN ***/
1452
1453 int
1454 flow(int transport, char *rendezvous, char *os_root,
1455      int booted_from_livecd __unused, int upgrade_menu_toggle __unused)
1456 {
1457         struct i_fn_args *a;
1458
1459         rc_conf = config_vars_new();
1460
1461         if ((a = i_fn_args_new(os_root, DEFAULT_INSTALLER_TEMP,
1462                                transport, rendezvous)) == NULL) {
1463                 return(0);
1464         }
1465
1466         /*
1467          * XXX We can't handle this yet.
1468          *
1469            a->booted_from_livecd = booted_from_livecd;
1470            a->upgrade_menu_toggle = upgrade_menu_toggle;
1471         */
1472         a->booted_from_livecd = 1;
1473         a->upgrade_menu_toggle = 0;
1474
1475         /*
1476          * Execute the state machine here.  The global function pointer
1477          * variable `state' points to the next state_* function to execute.
1478          * Before it exits, this function should set `state' to the next
1479          * state to make a transition to, or NULL to indicate that the
1480          * state machine is finished.
1481          */
1482 #ifdef ENABLE_NLS
1483         state = state_lang_menu;
1484 #else
1485         state = state_welcome;
1486 #endif
1487         for (; state != NULL; )
1488                 state(a);
1489
1490         config_vars_free(rc_conf);
1491
1492         i_fn_args_free(a);
1493
1494         return(do_reboot);
1495 }