]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - usr.sbin/sysinstall/options.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / usr.sbin / 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 #include <curses.h>
40 #include <term.h>
41
42 int fixitTtyWhich(dialogMenuItem *);
43
44 static char *
45 varCheck(Option *opt)
46 {
47     char *cp = NULL;
48
49     if (opt->aux)
50         cp = variable_get((char *)opt->aux);
51     if (!cp)
52         return "NO";
53     return cp;
54 }
55
56 /* Show our little logo */
57 static char *
58 resetLogo(Option *opt)
59 {
60     return "[RESET!]";
61 }
62
63 static char *
64 mediaCheck(Option *opt)
65 {
66     if (mediaDevice) {
67         switch(mediaDevice->type) {
68         case DEVICE_TYPE_UFS:
69         case DEVICE_TYPE_DISK:
70             return "File system";
71
72         case DEVICE_TYPE_FLOPPY:
73             return "Floppy";
74
75         case DEVICE_TYPE_FTP:
76             return "FTP";
77
78         case DEVICE_TYPE_CDROM:
79             return "CDROM";
80
81         case DEVICE_TYPE_TAPE:
82             return "Tape";
83
84         case DEVICE_TYPE_DOS:
85             return "DOS";
86
87         case DEVICE_TYPE_NFS:
88             return "NFS";
89
90         case DEVICE_TYPE_NONE:
91         case DEVICE_TYPE_NETWORK:
92         case DEVICE_TYPE_ANY:
93         default:
94             return "<unknown>";
95         }
96     }
97     return "<not yet set>";
98 }
99
100 #define TAPE_PROMPT     "Please enter the tape block size in 512 byte blocks:"
101 #define NEWFS_PROMPT    "Please enter newfs(8) parameters:"
102 #define RELNAME_PROMPT  "Please specify the release you wish to load or\n\"any\" for a generic release install:"
103 #define BPKG_PROMPT     "Please specify the name of the HTML browser package:"
104 #define BBIN_PROMPT     "Please specify a full pathname to the HTML browser binary:"
105 #define EDITOR_PROMPT   "Please specify the name of the text editor you wish to use:"
106 #define PKG_PROMPT      "Please specify a temporary directory with lots of free space:"
107 #define INSTROOT_PROMPT "Please specify a root directory if installing somewhere other than /"
108 #define TIMEOUT_PROMPT  "Please specify the number of seconds to wait for slow media:"
109
110 static Option Options[] = {
111 { "NFS Secure",         "NFS server talks only on a secure port",
112       OPT_IS_VAR,       NULL,                   VAR_NFS_SECURE,         varCheck        },
113 { "NFS Slow",           "User is using a slow PC or ethernet card",
114       OPT_IS_VAR,       NULL,                   VAR_SLOW_ETHER,         varCheck        },
115 { "NFS TCP",            "Use TCP protocol for NFS",
116       OPT_IS_VAR,       NULL,                   VAR_NFS_TCP,            varCheck        },
117 { "NFS version 3",      "Use NFS version 3",
118       OPT_IS_VAR,       NULL,                   VAR_NFS_V3,             varCheck        },
119 { "Debugging",          "Emit extra debugging output on VTY2 (ALT-F2)",
120       OPT_IS_VAR,       NULL,                   VAR_DEBUG,              varCheck        },
121 { "No Warnings",        "Don't Warn the user when a setting seems incorrect",
122       OPT_IS_VAR,       NULL,                   VAR_NO_WARN,            varCheck        },
123 { "Yes to All",         "Assume \"Yes\" answers to all non-critical dialogs",
124       OPT_IS_VAR,       NULL,                   VAR_NO_CONFIRM,         varCheck        },
125 { "DHCP",               "Attempt automatic DHCP configuration of interfaces",
126       OPT_IS_VAR,       NULL,                   VAR_TRY_DHCP,           varCheck        },
127 { "IPv6",               "Attempt IPv6 configuration of interfaces",
128       OPT_IS_VAR,       NULL,                   VAR_TRY_RTSOL,          varCheck        },
129 { "Skip PCCARD",        "Skip PC Card probing, do not use PC Card devices for installation",
130       OPT_IS_VAR,       NULL,                   VAR_SKIP_PCCARD,        varCheck        },
131 { "FTP username",       "Username and password to use instead of anonymous",
132       OPT_IS_FUNC,      mediaSetFTPUserPass,    VAR_FTP_USER,           varCheck        },
133 { "Editor",             "Which text editor to use during installation",
134       OPT_IS_VAR,       EDITOR_PROMPT,          VAR_EDITOR,             varCheck        },
135 { "Tape Blocksize",     "Tape media block size in 512 byte blocks",
136       OPT_IS_VAR,       TAPE_PROMPT,            VAR_TAPE_BLOCKSIZE,     varCheck        },
137 { "Extract Detail",     "How verbosely to display file name information during extractions",
138       OPT_IS_FUNC,      mediaSetCPIOVerbosity,  VAR_CPIO_VERBOSITY,     varCheck        },
139 { "Release Name",       "Which release to attempt to load from installation media",
140       OPT_IS_VAR,       RELNAME_PROMPT,         VAR_RELNAME,            varCheck        },
141 { "Install Root",       "Which directory to unpack distributions or packages relative to",
142       OPT_IS_VAR,       INSTROOT_PROMPT,        VAR_INSTALL_ROOT,       varCheck        },
143 { "Browser package",    "This is the browser package that will be used for viewing HTML docs",
144       OPT_IS_VAR,       BPKG_PROMPT,            VAR_BROWSER_PACKAGE,    varCheck        },
145 { "Browser Exec",       "This is the path to the main binary of the browser package",
146       OPT_IS_VAR,       BBIN_PROMPT,            VAR_BROWSER_BINARY,     varCheck        },
147 { "Media Type",         "The current installation media type.",
148       OPT_IS_FUNC,      mediaGetType,           VAR_MEDIA_TYPE,         mediaCheck      },
149 { "Media Timeout",      "Timeout value in seconds for slow media.",
150       OPT_IS_VAR,       TIMEOUT_PROMPT,         VAR_MEDIA_TIMEOUT,      varCheck        },
151 { "Package Temp",       "The directory where package temporary files should go",
152       OPT_IS_VAR,       PKG_PROMPT,             VAR_PKG_TMPDIR,         varCheck        },
153 { "Newfs Args",         "Default parameters for newfs(8)",
154       OPT_IS_VAR,       NEWFS_PROMPT,           VAR_NEWFS_ARGS,         varCheck        },
155 { "Fixit Console",      "Which tty to use for the Fixit action.",
156       OPT_IS_FUNC,      fixitTtyWhich,          VAR_FIXIT_TTY,          varCheck        },
157 { "Re-scan Devices",    "Re-run sysinstall's initial device probe",
158       OPT_IS_FUNC,      deviceRescan,           NULL,                   NULL            },
159 { "Use Defaults",       "Reset all values to startup defaults",
160       OPT_IS_FUNC,      installVarDefaults,     NULL,                   resetLogo       },
161 { NULL, NULL, 0, NULL, NULL, NULL },
162 };
163
164 #define OPT_START_ROW   4
165 #define OPT_END_ROW     19
166 #define OPT_NAME_COL    0
167 #define OPT_VALUE_COL   16
168 #define GROUP_OFFSET    40
169
170 static char *
171 value_of(Option opt)
172 {
173     static char ival[40];
174
175     switch (opt.type) {
176     case OPT_IS_STRING:
177         return (char *)opt.data;
178
179     case OPT_IS_INT:
180         sprintf(ival, "%lu", (long)opt.data);
181         return ival;
182
183     case OPT_IS_FUNC:
184     case OPT_IS_VAR:
185         if (opt.check)
186             return opt.check(&opt);
187         else
188             return "<*>";
189     }
190     return "<unknown>";
191 }
192
193 static int
194 fire(Option opt)
195 {
196     int status = 0;
197
198     if (opt.type == OPT_IS_FUNC) {
199         int (*cp)(char *) = opt.data, rcode;
200
201         rcode = cp(NULL);
202         status = 1;
203     }
204     else if (opt.type == OPT_IS_VAR) {
205         if (opt.data) {
206             (void)variable_get_value(opt.aux, opt.data, -1);
207             status = 1;
208         }
209         else if (variable_get(opt.aux)) {
210             if (!variable_cmp(opt.aux, "YES"))
211                 variable_set2(opt.aux, "NO", -1);
212             else
213                 variable_set2(opt.aux, "YES", -1);
214         }
215         else
216             variable_set2(opt.aux, "YES", 0);
217     }
218     if (opt.check)
219         opt.check(&opt);
220     refresh();
221     return status;
222 }
223
224 int
225 optionsEditor(dialogMenuItem *self)
226 {
227     int i, optcol, optrow, key;
228     static int currOpt = 0;
229     WINDOW *w = savescr();
230     
231     dialog_clear();
232     clear();
233
234     while (1) {
235         /* Whap up the header */
236         attrset(A_REVERSE); mvaddstr(0, 0, "Options Editor"); attrset(A_NORMAL);
237         for (i = 0; i < 2; i++) {
238             mvaddstr(OPT_START_ROW - 2, OPT_NAME_COL + (i * GROUP_OFFSET), "Name");
239             mvaddstr(OPT_START_ROW - 1, OPT_NAME_COL + (i * GROUP_OFFSET), "----");
240
241             mvaddstr(OPT_START_ROW - 2, OPT_VALUE_COL + (i * GROUP_OFFSET), "Value");
242             mvaddstr(OPT_START_ROW - 1, OPT_VALUE_COL + (i * GROUP_OFFSET), "-----");
243         }
244         /* And the footer */
245         mvprintw(OPT_END_ROW + 1, 0, "Use SPACE to select/toggle an option, arrow keys to move,");
246         mvprintw(OPT_END_ROW + 2, 0, "? or F1 for more help.  When you're done, type Q to Quit.");
247
248         optrow = OPT_START_ROW;
249         optcol = OPT_NAME_COL;
250         for (i = 0; Options[i].name; i++) {
251             /* Names are painted somewhat gratuitously each time, but it's easier this way */
252             mvprintw(optrow, OPT_NAME_COL + optcol, Options[i].name);
253             if (currOpt == i)
254                 attrset(ATTR_SELECTED);
255             mvprintw(optrow++, OPT_VALUE_COL + optcol, value_of(Options[i]));
256             if (currOpt == i)
257                 attrset(A_NORMAL);
258             if (optrow == OPT_END_ROW) {
259                 optrow = OPT_START_ROW;
260                 optcol += GROUP_OFFSET;
261             }
262             clrtoeol();
263         }
264         attrset(ATTR_TITLE);
265         mvaddstr(OPT_END_ROW + 4, 0, Options[currOpt].desc);
266         attrset(A_NORMAL);
267         clrtoeol();
268         move(0, 14);
269         refresh();
270
271         /* Start the edit loop */
272         key = toupper(getch());
273         switch (key) {
274         case KEY_F(1):
275         case '?':
276             systemDisplayHelp("options");
277             clear();
278             break;
279
280         case '\020':    /* ^P */
281         case KEY_UP:
282             if (currOpt)
283                 --currOpt;
284             else
285                 for (currOpt = 0; Options[currOpt + 1].name; currOpt++);
286             continue;
287
288         case '\016':    /* ^N */
289         case KEY_DOWN:
290             if (Options[currOpt + 1].name)
291                 ++currOpt;
292             else
293                 currOpt = 0;
294             continue;
295
296         case KEY_HOME:
297             currOpt = 0;
298             continue;
299
300         case KEY_END:
301             while (Options[currOpt + 1].name)
302                 ++currOpt;
303             continue;
304
305         case ' ':
306             if (fire(Options[currOpt]))
307                 clear();
308             continue;
309
310         case '\033':    /* ESC */
311         case 'Q':
312             clear();
313             dialog_clear();
314             restorescr(w);
315             return DITEM_SUCCESS | DITEM_CONTINUE;
316
317         default:
318             beep();
319         }
320     }
321     /* NOTREACHED */
322     return DITEM_SUCCESS;
323 }
324
325 int
326 fixitTtyWhich(dialogMenuItem *self)
327 {
328     char *cp = variable_get(VAR_FIXIT_TTY);
329
330     if (!cp) {
331         msgConfirm("The Fix-it TTY setting is not set to anything!");
332         return DITEM_FAILURE;
333     }
334     else {
335         if (!strcmp(cp, "standard"))
336             variable_set2(VAR_FIXIT_TTY, "serial", 0);
337         else /* must be "serial" - wrap around */
338             variable_set2(VAR_FIXIT_TTY, "standard", 0);
339     }
340     return DITEM_SUCCESS;
341 }