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