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 <sys/ioctl.h>
38 #include <sys/consio.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
42 #include <netinet/in.h>
48 #include "sysinstall.h"
55 return (cp = variable_get(VAR_DEBUG)) && strcmp(cp, "no");
61 if (!(RunningAsInit) ||
62 (variable_check("NETWORK_CONFIGURED=NO")) != TRUE) {
70 msgSyslog(const char *errstr)
72 struct sockaddr_in server;
80 if (!(host = variable_get(VAR_SYSLOG_SERVER)))
83 if (!(hp = gethostbyname2(host, AF_INET)))
86 if (!(sock = socket(AF_INET, SOCK_DGRAM, 0)))
89 bzero(&server, sizeof(struct sockaddr_in));
90 server.sin_family = AF_INET;
91 server.sin_port = htons(514);
92 bcopy((char *)hp->h_addr, (char *)&server.sin_addr, hp->h_length);
94 asprintf(&line, "<%d>%s", LOG_NOTICE, errstr);
95 sendto(sock, line, strlen(line), 0, (struct sockaddr *)&server,
96 sizeof(struct sockaddr_in));
102 /* Whack up an informational message on the status line, in stand-out */
104 msgYap(char *fmt, ...)
110 errstr = (char *)alloca(FILENAME_MAX);
112 vsnprintf(errstr, FILENAME_MAX, fmt, args);
114 attrs = getattrs(stdscr);
116 mvaddstr(StatusLine, 0, errstr);
121 /* Whack up an informational message on the status line */
123 msgInfo(char *fmt, ...)
130 attrs = getattrs(stdscr);
131 /* NULL is a special convention meaning "erase the old stuff" */
137 errstr = (char *)alloca(FILENAME_MAX);
139 vsnprintf(errstr, FILENAME_MAX, fmt, args);
141 memset(line, ' ', 80);
142 for (i = 0; i < 80; i++) {
150 mvaddstr(StatusLine, 0, line);
152 move(StatusLine, 79);
158 /* Whack up a warning on the status line */
160 msgWarn(char *fmt, ...)
166 errstr = (char *)alloca(FILENAME_MAX);
167 strcpy(errstr, "Warning: ");
169 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
171 attrs = getattrs(stdscr);
174 mvaddstr(StatusLine, 0, errstr);
178 /* we don't want this hitting syslog twice */
181 msgDebug("Warning message `%s'\n", errstr);
188 /* Whack up an error on the status line */
190 msgError(char *fmt, ...)
196 errstr = (char *)alloca(FILENAME_MAX);
197 strcpy(errstr, "Error: ");
199 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
202 attrs = getattrs(stdscr);
204 mvaddstr(StatusLine, 0, errstr);
208 /* we don't want this hitting syslog twice */
211 msgDebug("Error message `%s'\n", errstr);
217 /* Whack up a fatal error on the status line */
219 msgFatal(char *fmt, ...)
225 errstr = (char *)alloca(FILENAME_MAX);
226 strcpy(errstr, "Fatal Error: ");
228 vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
231 attrs = getattrs(stdscr);
233 mvaddstr(StatusLine, 0, errstr);
235 addstr("PRESS ANY KEY TO ");
243 msgDebug("Fatal error `%s'!\n", errstr);
250 /* Put up a message in a popup confirmation box */
252 msgConfirm(char *fmt, ...)
256 WINDOW *w = savescr();
258 errstr = (char *)alloca(FILENAME_MAX);
260 vsnprintf(errstr, FILENAME_MAX, fmt, args);
265 ioctl(0, VT_ACTIVATE, 1);
268 dialog_notify(errstr);
272 /* Put up a message in a popup information box */
274 msgNotify(char *fmt, ...)
279 errstr = (char *)alloca(FILENAME_MAX);
281 vsnprintf(errstr, FILENAME_MAX, fmt, args);
286 msgDebug("Notify: %s\n", errstr);
287 dialog_msgbox(NULL, errstr, -1, -1, 0);
290 /* Put up a message in a popup yes/no box and return 0 for YES, 1 for NO */
292 msgYesNo(char *fmt, ...)
297 WINDOW *w = savescr();
299 errstr = (char *)alloca(FILENAME_MAX);
301 vsnprintf(errstr, FILENAME_MAX, fmt, args);
306 ioctl(0, VT_ACTIVATE, 1); /* Switch back */
309 if (variable_get(VAR_NONINTERACTIVE))
310 return 0; /* If non-interactive, return YES all the time */
311 ret = dialog_yesno("User Confirmation Requested", errstr, -1, -1);
316 /* Put up a message in a popup no/yes box and return 0 for YES, 1 for NO */
318 msgNoYes(char *fmt, ...)
323 WINDOW *w = savescr();
325 errstr = (char *)alloca(FILENAME_MAX);
327 vsnprintf(errstr, FILENAME_MAX, fmt, args);
332 ioctl(0, VT_ACTIVATE, 1); /* Switch back */
335 if (variable_get(VAR_NONINTERACTIVE))
336 return 1; /* If non-interactive, return NO all the time */
337 ret = dialog_noyes("User Confirmation Requested", errstr, -1, -1);
342 /* Put up a message in an input box and return the value */
344 msgGetInput(char *buf, char *fmt, ...)
348 static char input_buffer[256];
350 WINDOW *w = savescr();
352 errstr = (char *)alloca(FILENAME_MAX);
354 vsnprintf(errstr, FILENAME_MAX, fmt, args);
359 SAFE_STRCPY(input_buffer, buf);
361 input_buffer[0] = '\0';
363 ioctl(0, VT_ACTIVATE, 1); /* Switch back */
366 rval = dialog_inputbox("Value Required", errstr, -1, -1, input_buffer);
374 /* Write something to the debugging port */
376 msgDebug(char *fmt, ...)
383 dbg = (char *)alloca(FILENAME_MAX);
384 strcpy(dbg, "DEBUG: ");
386 vsnprintf((char *)(dbg + strlen(dbg)), FILENAME_MAX, fmt, args);
391 write(DebugFD, dbg, strlen(dbg));
394 /* Tell the user there's some output to go look at */
396 msgWeHaveOutput(char *fmt, ...)
400 WINDOW *w = savescr();
402 errstr = (char *)alloca(FILENAME_MAX);
404 vsnprintf(errstr, FILENAME_MAX, fmt, args);
408 msgDebug("Notify: %s\n", errstr);
409 dialog_clear_norefresh();
411 dialog_msgbox(NULL, errstr, -1, -1, 0);
415 /* Simple versions of msgConfirm() and msgNotify() for calling from scripts */
417 msgSimpleConfirm(char *str)
419 msgConfirm("%s", str);
420 return DITEM_SUCCESS;
424 msgSimpleNotify(char *str)
426 msgNotify("%s", str);
427 return DITEM_SUCCESS;