]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/sysinstall/options.c
IPv6 support.
[FreeBSD/FreeBSD.git] / release / sysinstall / options.c
1 /*
2  * The new sysinstall program.
3  *
4  * This is probably the last attempt in the `sysinstall' line, the next
5  * generation being slated for what's essentially a complete rewrite.
6  *
7  * $FreeBSD$
8  *
9  * Copyright (c) 1995
10  *      Jordan Hubbard.  All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer,
17  *    verbatim and that no modifications are made prior to this
18  *    point in the file.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36
37 #include "sysinstall.h"
38 #include <ctype.h>
39
40 int fixitTtyWhich(dialogMenuItem *);
41
42 static char *
43 varCheck(Option opt)
44 {
45     char *cp = NULL;
46
47     if (opt.aux)
48         cp = variable_get((char *)opt.aux);
49     if (!cp)
50         return "NO";
51     return cp;
52 }
53
54 /* Show our little logo */
55 static char *
56 resetLogo(char *str)
57 {
58     return "[RESET!]";
59 }
60
61 static char *
62 mediaCheck(Option opt)
63 {
64     if (mediaDevice) {
65         switch(mediaDevice->type) {
66         case DEVICE_TYPE_UFS:
67         case DEVICE_TYPE_DISK:
68             return "File system";
69
70         case DEVICE_TYPE_FLOPPY:
71             return "Floppy";
72
73         case DEVICE_TYPE_FTP:
74             return "FTP";
75
76         case DEVICE_TYPE_CDROM:
77             return "CDROM";
78
79         case DEVICE_TYPE_TAPE:
80             return "Tape";
81
82         case DEVICE_TYPE_DOS:
83             return "DOS";
84
85         case DEVICE_TYPE_NFS:
86             return "NFS";
87
88         case DEVICE_TYPE_NONE:
89         case DEVICE_TYPE_NETWORK:
90         case DEVICE_TYPE_ANY:
91         default:
92             return "<unknown>";
93         }
94     }
95     return "<not yet set>";
96 }
97
98 #define TAPE_PROMPT     "Please enter the tape block size in 512 byte blocks:"
99 #define NEWFS_PROMPT    "Please enter newfs(8) parameters:"
100 #define RELNAME_PROMPT  "Please specify the release you wish to load or\n\"none\" for a generic release install:"
101 #define BPKG_PROMPT     "Please specify the name of the HTML browser package:"
102 #define BBIN_PROMPT     "Please specify a full pathname to the HTML browser binary:"
103 #define EDITOR_PROMPT   "Please specify the name of the text editor you wish to use:"
104 #define PKG_PROMPT      "Please specify a temporary directory with lots of free space:"
105 #define INSTROOT_PROMPT "Please specify a root directory if installing somewhere other than /"
106 #define TIMEOUT_PROMPT  "Please specify the number of seconds to wait for slow media:"
107
108 static Option Options[] = {
109 { "NFS Secure",         "NFS server talks only on a secure port",
110       OPT_IS_VAR,       NULL,                   VAR_NFS_SECURE,         varCheck        },
111 { "NFS Slow",           "User is using a slow PC or ethernet card",
112       OPT_IS_VAR,       NULL,                   VAR_SLOW_ETHER,         varCheck        },
113 { "Debugging",          "Emit extra debugging output on VTY2 (ALT-F2)",
114       OPT_IS_VAR,       NULL,                   VAR_DEBUG,              varCheck        },
115 { "No Warnings",        "Don't Warn the user when a setting seems incorrect",
116       OPT_IS_VAR,       NULL,                   VAR_NO_WARN,            varCheck        },
117 { "Yes to All",         "Assume \"Yes\" answers to all non-critical dialogs",
118       OPT_IS_VAR,       NULL,                   VAR_NO_CONFIRM,         varCheck        },
119 { "DHCP",               "Attempt automatic DHCP configuration of interfaces",
120       OPT_IS_VAR,       NULL,                   VAR_TRY_DHCP,           varCheck        },
121 { "IPv6",               "Attempt IPv6 configuration of interfaces",
122       OPT_IS_VAR,       NULL,                   VAR_TRY_RTSOL,          varCheck        },
123 { "FTP username",       "Username and password to use instead of anonymous",
124       OPT_IS_FUNC,      mediaSetFTPUserPass,    VAR_FTP_USER,           varCheck        },
125 { "Editor",             "Which text editor to use during installation",
126       OPT_IS_VAR,       EDITOR_PROMPT,          VAR_EDITOR,             varCheck        },
127 { "Tape Blocksize",     "Tape media block size in 512 byte blocks",
128       OPT_IS_VAR,       TAPE_PROMPT,            VAR_TAPE_BLOCKSIZE,     varCheck        },
129 { "Extract Detail",     "How verbosely to display file name information during extractions",
130       OPT_IS_FUNC,      mediaSetCPIOVerbosity,  VAR_CPIO_VERBOSITY,     varCheck        },
131 { "Release Name",       "Which release to attempt to load from installation media",
132       OPT_IS_VAR,       RELNAME_PROMPT,         VAR_RELNAME,            varCheck        },
133 { "Install Root",       "Which directory to unpack distributions or packages relative to",
134       OPT_IS_VAR,       INSTROOT_PROMPT,        VAR_INSTALL_ROOT,       varCheck        },
135 { "Browser package",    "This is the browser package that will be used for viewing HTML docs",
136       OPT_IS_VAR,       BPKG_PROMPT,            VAR_BROWSER_PACKAGE,    varCheck        },
137 { "Browser Exec",       "This is the path to the main binary of the browser package",
138       OPT_IS_VAR,       BBIN_PROMPT,            VAR_BROWSER_BINARY,     varCheck        },
139 { "Media Type",         "The current installation media type.",
140       OPT_IS_FUNC,      mediaGetType,           VAR_MEDIA_TYPE,         mediaCheck      },
141 { "Media Timeout",      "Timeout value in seconds for slow media.",
142       OPT_IS_VAR,       TIMEOUT_PROMPT,         VAR_MEDIA_TIMEOUT,      varCheck        },
143 { "Package Temp",       "The directory where package temporary files should go",
144       OPT_IS_VAR,       PKG_PROMPT,             VAR_PKG_TMPDIR,         varCheck        },
145 { "Newfs Args",         "Default parameters for newfs(8)",
146       OPT_IS_VAR,       NEWFS_PROMPT,           VAR_NEWFS_ARGS,         varCheck        },
147 { "Fixit Console",      "Which tty to use for the Fixit action.",
148       OPT_IS_FUNC,      fixitTtyWhich,          VAR_FIXIT_TTY,          varCheck        },
149 { "Config save",        "Whether or not to save installation kernel config changes",
150       OPT_IS_VAR,       NULL,                   VAR_KGET,               varCheck        },
151 { "Re-scan Devices",    "Re-run sysinstall's initial device probe",
152       OPT_IS_FUNC,      deviceRescan },
153 { "Use Defaults",       "Reset all values to startup defaults",
154       OPT_IS_FUNC,      installVarDefaults,     0,                      resetLogo       },
155 { NULL },
156 };
157
158 #define OPT_START_ROW   4
159 #define OPT_END_ROW     19
160 #define OPT_NAME_COL    0
161 #define OPT_VALUE_COL   16
162 #define GROUP_OFFSET    40
163
164 static char *
165 value_of(Option opt)
166 {
167     static char ival[40];
168
169     switch (opt.type) {
170     case OPT_IS_STRING:
171         return (char *)opt.data;
172
173     case OPT_IS_INT:
174         sprintf(ival, "%d", (int)opt.data);
175         return ival;
176
177     case OPT_IS_FUNC:
178     case OPT_IS_VAR:
179         if (opt.check)
180             return opt.check(opt);
181         else
182             return "<*>";
183     }
184     return "<unknown>";
185 }
186
187 static int
188 fire(Option opt)
189 {
190     int status = 0;
191
192     if (opt.type == OPT_IS_FUNC) {
193         int (*cp)(char *) = opt.data, rcode;
194
195         rcode = cp(NULL);
196         status = 1;
197     }
198     else if (opt.type == OPT_IS_VAR) {
199         if (opt.data) {
200             (void)variable_get_value(opt.aux, opt.data, -1);
201             status = 1;
202         }
203         else if (variable_get(opt.aux)) {
204             if (!variable_cmp(opt.aux, "YES"))
205                 variable_set2(opt.aux, "NO", -1);
206             else
207                 variable_set2(opt.aux, "YES", -1);
208         }
209         else
210             variable_set2(opt.aux, "YES", 0);
211     }
212     if (opt.check)
213         opt.check(opt);
214     refresh();
215     return status;
216 }
217
218 int
219 optionsEditor(dialogMenuItem *self)
220 {
221     int i, optcol, optrow, key;
222     static int currOpt = 0;
223     WINDOW *w = savescr();
224     
225     dialog_clear();
226     clear();
227
228     while (1) {
229         /* Whap up the header */
230         attrset(A_REVERSE); mvaddstr(0, 0, "Options Editor"); attrset(A_NORMAL);
231         for (i = 0; i < 2; i++) {
232             mvaddstr(OPT_START_ROW - 2, OPT_NAME_COL + (i * GROUP_OFFSET), "Name");
233             mvaddstr(OPT_START_ROW - 1, OPT_NAME_COL + (i * GROUP_OFFSET), "----");
234
235             mvaddstr(OPT_START_ROW - 2, OPT_VALUE_COL + (i * GROUP_OFFSET), "Value");
236             mvaddstr(OPT_START_ROW - 1, OPT_VALUE_COL + (i * GROUP_OFFSET), "-----");
237         }
238         /* And the footer */
239         mvprintw(OPT_END_ROW + 1, 0, "Use SPACE to select/toggle an option, arrow keys to move,");
240         mvprintw(OPT_END_ROW + 2, 0, "? or F1 for more help.  When you're done, type Q to Quit.");
241
242         optrow = OPT_START_ROW;
243         optcol = OPT_NAME_COL;
244         for (i = 0; Options[i].name; i++) {
245             /* Names are painted somewhat gratuitously each time, but it's easier this way */
246             mvprintw(optrow, OPT_NAME_COL + optcol, Options[i].name);
247             if (currOpt == i)
248                 attrset(ATTR_SELECTED);
249             mvprintw(optrow++, OPT_VALUE_COL + optcol, value_of(Options[i]));
250             if (currOpt == i)
251                 attrset(A_NORMAL);
252             if (optrow == OPT_END_ROW) {
253                 optrow = OPT_START_ROW;
254                 optcol += GROUP_OFFSET;
255             }
256             clrtoeol();
257         }
258         attrset(ATTR_TITLE);
259         mvaddstr(OPT_END_ROW + 4, 0, Options[currOpt].desc);
260         attrset(A_NORMAL);
261         clrtoeol();
262         move(0, 14);
263         refresh();
264
265         /* Start the edit loop */
266         key = toupper(getch());
267         switch (key) {
268         case KEY_F(1):
269         case '?':
270             systemDisplayHelp("options");
271             clear();
272             break;
273
274         case '\020':    /* ^P */
275         case KEY_UP:
276             if (currOpt)
277                 --currOpt;
278             else
279                 for (currOpt = 0; Options[currOpt + 1].name; currOpt++);
280             continue;
281
282         case '\016':    /* ^N */
283         case KEY_DOWN:
284             if (Options[currOpt + 1].name)
285                 ++currOpt;
286             else
287                 currOpt = 0;
288             continue;
289
290         case KEY_HOME:
291             currOpt = 0;
292             continue;
293
294         case KEY_END:
295             while (Options[currOpt + 1].name)
296                 ++currOpt;
297             continue;
298
299         case ' ':
300             if (fire(Options[currOpt]))
301                 clear();
302             continue;
303
304         case '\033':    /* ESC */
305         case 'Q':
306             clear();
307             dialog_clear();
308             restorescr(w);
309             return DITEM_SUCCESS;
310
311         default:
312             beep();
313         }
314     }
315     /* NOTREACHED */
316     return DITEM_SUCCESS;
317 }
318
319 int
320 fixitTtyWhich(dialogMenuItem *self)
321 {
322     char *cp = variable_get(VAR_FIXIT_TTY);
323
324     if (!cp) {
325         msgConfirm("The Fix-it TTY setting is not set to anything!");
326         return DITEM_FAILURE;
327     }
328     else {
329         if (!strcmp(cp, "standard"))
330             variable_set2(VAR_FIXIT_TTY, "serial", 0);
331         else /* must be "serial" - wrap around */
332             variable_set2(VAR_FIXIT_TTY, "standard", 0);
333     }
334     return DITEM_SUCCESS;
335 }