2 * The new sysinstall program.
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
10 * Jordan Hubbard. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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
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.
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
37 #include "sysinstall.h"
40 #include <sys/signal.h>
41 #include <sys/fcntl.h>
45 static int dispatch_shutdown(dialogMenuItem *unused);
46 static int dispatch_systemExecute(dialogMenuItem *unused);
47 static int dispatch_msgConfirm(dialogMenuItem *unused);
51 int (*handler)(dialogMenuItem *self);
53 { "configAnonFTP", configAnonFTP },
54 { "configRouter", configRouter },
55 { "configInetd", configInetd },
56 { "configNFSServer", configNFSServer },
57 { "configNTP", configNTP },
58 { "configPCNFSD", configPCNFSD },
59 { "configPackages", configPackages },
60 { "configUsers", configUsers },
61 { "configXSetup", configXSetup },
62 { "configXDesktop", configXDesktop },
63 { "diskPartitionEditor", diskPartitionEditor },
64 { "diskPartitionWrite", diskPartitionWrite },
65 { "diskLabelEditor", diskLabelEditor },
66 { "diskLabelCommit", diskLabelCommit },
67 { "distReset", distReset },
68 { "distSetCustom", distSetCustom },
69 { "distUnsetCustom", distUnsetCustom },
70 { "distSetDeveloper", distSetDeveloper },
71 { "distSetXDeveloper", distSetXDeveloper },
72 { "distSetKernDeveloper", distSetKernDeveloper },
73 { "distSetUser", distSetUser },
74 { "distSetXUser", distSetXUser },
75 { "distSetMinimum", distSetMinimum },
76 { "distSetEverything", distSetEverything },
77 { "distSetSrc", distSetSrc },
78 { "distSetXF86", distSetXF86 },
79 { "distExtractAll", distExtractAll },
80 { "docBrowser", docBrowser },
81 { "docShowDocument", docShowDocument },
82 { "installCommit", installCommit },
83 { "installExpress", installExpress },
84 { "installStandard", installStandard },
85 { "installUpgrade", installUpgrade },
86 { "installFixupBin", installFixupBin },
88 { "installFixupXFree", installFixupXFree },
90 { "installFixitHoloShell", installFixitHoloShell },
91 { "installFixitCDROM", installFixitCDROM },
92 { "installFixitFloppy", installFixitFloppy },
93 { "installFilesystems", installFilesystems },
94 { "installVarDefaults", installVarDefaults },
95 { "loadConfig", dispatch_load_file },
96 { "loadFloppyConfig", dispatch_load_floppy },
97 { "mediaSetCDROM", mediaSetCDROM },
98 { "mediaSetFloppy", mediaSetFloppy },
99 { "mediaSetDOS", mediaSetDOS },
100 { "mediaSetTape", mediaSetTape },
101 { "mediaSetFTP", mediaSetFTP },
102 { "mediaSetFTPActive", mediaSetFTPActive },
103 { "mediaSetFTPPassive", mediaSetFTPPassive },
104 { "mediaSetHTTP", mediaSetHTTP },
105 { "mediaSetUFS", mediaSetUFS },
106 { "mediaSetNFS", mediaSetNFS },
107 { "mediaSetFTPUserPass", mediaSetFTPUserPass },
108 { "mediaSetCPIOVerbosity", mediaSetCPIOVerbosity },
109 { "mediaGetType", mediaGetType },
110 { "msgConfirm", dispatch_msgConfirm },
111 { "optionsEditor", optionsEditor },
112 { "packageAdd", packageAdd },
113 { "addGroup", userAddGroup },
114 { "addUser", userAddUser },
115 { "shutdown", dispatch_shutdown },
116 { "system", dispatch_systemExecute },
117 { "dumpVariables", dump_variables },
118 { "tcpMenuSelect", tcpMenuSelect },
123 * Helper routines for buffering data.
125 * We read an entire configuration into memory before executing it
126 * so that we are truely standalone and can do things like nuke the
127 * file or disk we're working on.
130 typedef struct command_buffer_ {
136 dispatch_free_command(command_buffer *item)
144 dispatch_free_all(qelement *head)
146 command_buffer *item;
148 while (!EMPTYQUE(*head)) {
149 item = (command_buffer *) head->q_forw;
150 dispatch_free_command(item);
154 static command_buffer *
155 dispatch_add_command(qelement *head, char *string)
159 new = malloc(sizeof(command_buffer));
164 new->string = strdup(string);
165 INSQUEUE(new, head->q_back);
174 /* Just convenience */
176 dispatch_shutdown(dialogMenuItem *unused)
179 return DITEM_FAILURE;
183 dispatch_systemExecute(dialogMenuItem *unused)
185 char *cmd = variable_get(VAR_COMMAND);
188 return systemExecute(cmd) ? DITEM_FAILURE : DITEM_SUCCESS;
190 msgDebug("_systemExecute: No command passed in `command' variable.\n");
191 return DITEM_FAILURE;
195 dispatch_msgConfirm(dialogMenuItem *unused)
197 char *msg = variable_get(VAR_COMMAND);
200 msgConfirm("%s", msg);
201 return DITEM_SUCCESS;
204 msgDebug("_msgConfirm: No message passed in `command' variable.\n");
205 return DITEM_FAILURE;
209 call_possible_resword(char *name, dialogMenuItem *value, int *status)
214 for (i = 0; resWords[i].name; i++) {
215 if (!strcmp(name, resWords[i].name)) {
216 *status = resWords[i].handler(value);
224 /* For a given string, call it or spit out an undefined command diagnostic */
226 dispatchCommand(char *str)
232 msgConfirm("Null or zero-length string passed to dispatchCommand");
233 return DITEM_FAILURE;
235 /* If it's got a newline, trim it */
236 if ((cp = index(str, '\n')) != NULL)
239 /* If it's got a `=' sign in there, assume it's a variable setting */
240 if (index(str, '=')) {
242 msgDebug("dispatch: setting variable `%s'\n", str);
243 variable_set(str, 0);
247 /* A command might be a pathname if it's encoded in argv[0], which
249 if ((cp = rindex(str, '/')) != NULL)
252 msgDebug("dispatch: calling resword `%s'\n", str);
253 if (!call_possible_resword(str, NULL, &i)) {
254 msgNotify("Warning: No such command ``%s''", str);
267 dispatch_load_fp(FILE *fp)
270 char buf[BUFSIZ], *cp;
272 head = malloc(sizeof(qelement));
279 while (fgets(buf, sizeof buf, fp)) {
281 if ((cp = strchr(buf, '\n')) != NULL)
283 if (*buf == '\0' || *buf == '#')
286 if (!dispatch_add_command(head, buf))
294 dispatch_execute(qelement *head)
296 int result = DITEM_SUCCESS;
297 command_buffer *item;
298 char *old_interactive;
301 return result | DITEM_FAILURE;
303 old_interactive = variable_get(VAR_NONINTERACTIVE);
305 old_interactive = strdup(old_interactive); /* save copy */
307 /* Hint to others that we're running from a script, should they care */
308 variable_set2(VAR_NONINTERACTIVE, "yes", 0);
310 while (!EMPTYQUE(*head)) {
311 item = (command_buffer *) head->q_forw;
313 if (DITEM_STATUS(dispatchCommand(item->string)) != DITEM_SUCCESS) {
315 * Allow a user to prefix a command with "noError" to cause
316 * us to ignore any errors for that one command.
318 if (variable_get(VAR_NO_ERROR))
319 variable_unset(VAR_NO_ERROR);
321 msgConfirm("Command `%s' failed - rest of script aborted.\n",
323 result |= DITEM_FAILURE;
327 dispatch_free_command(item);
330 dispatch_free_all(head);
332 if (!old_interactive)
333 variable_unset(VAR_NONINTERACTIVE);
335 variable_set2(VAR_NONINTERACTIVE, old_interactive, 0);
336 free(old_interactive);
343 dispatch_load_file_int(int quiet)
350 static const char *names[] = {
352 "/stand/install.cfg",
358 cp = variable_get(VAR_CONFIG_FILE);
360 for (i = 0; names[i]; i++)
361 if ((fp = fopen(names[i], "r")) != NULL)
368 msgConfirm("Unable to open %s: %s", cp, strerror(errno));
369 return DITEM_FAILURE;
372 list = dispatch_load_fp(fp);
375 return dispatch_execute(list);
379 dispatch_load_file(dialogMenuItem *self)
381 return dispatch_load_file_int(FALSE);
385 dispatch_load_floppy(dialogMenuItem *self)
387 int what = DITEM_SUCCESS;
388 extern char *distWanted;
394 cp = variable_get_value(VAR_INSTALL_CFG,
395 "Specify the name of a configuration file\n"
396 "residing on a MSDOS or UFS floppy.", 0);
398 variable_unset(VAR_INSTALL_CFG);
399 what |= DITEM_FAILURE;
404 /* Try to open the floppy drive */
405 if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE) {
406 msgConfirm("Unable to set media device to floppy.");
407 what |= DITEM_FAILURE;
412 if (!DEVICE_INIT(mediaDevice)) {
413 msgConfirm("Unable to mount floppy filesystem.");
414 what |= DITEM_FAILURE;
419 fp = DEVICE_GET(mediaDevice, cp, TRUE);
421 list = dispatch_load_fp(fp);
425 what |= dispatch_execute(list);
428 if (!variable_get(VAR_NO_ERROR))
429 msgConfirm("Configuration file '%s' not found.", cp);
430 variable_unset(VAR_INSTALL_CFG);
431 what |= DITEM_FAILURE;