1995-04-27 12:50:35 +00:00
|
|
|
/*
|
|
|
|
* The new sysinstall program.
|
|
|
|
*
|
|
|
|
* This is probably the last program in the `sysinstall' line - the next
|
|
|
|
* generation being essentially a complete rewrite.
|
|
|
|
*
|
1995-05-20 13:24:35 +00:00
|
|
|
* $Id: system.c,v 1.21 1995/05/20 08:31:43 jkh Exp $
|
1995-04-27 12:50:35 +00:00
|
|
|
*
|
|
|
|
* Jordan Hubbard
|
|
|
|
*
|
|
|
|
* My contributions are in the public domain.
|
|
|
|
*
|
|
|
|
* Parts of this file are also blatently stolen from Poul-Henning Kamp's
|
1995-05-19 16:58:58 +00:00
|
|
|
* previous version of sysinstall, and as such fall under his "BEERWARE license"
|
|
|
|
* so buy him a beer if you like it! Buy him a beer for me, too!
|
|
|
|
* Heck, get him completely drunk and send me pictures! :-)
|
1995-04-27 12:50:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysinstall.h"
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/reboot.h>
|
1995-05-05 23:47:47 +00:00
|
|
|
#include <machine/console.h>
|
1995-04-27 12:50:35 +00:00
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
1995-04-29 19:33:06 +00:00
|
|
|
#include <sys/wait.h>
|
1995-04-27 12:50:35 +00:00
|
|
|
|
1995-05-05 23:47:47 +00:00
|
|
|
/*
|
|
|
|
* Handle interrupt signals - this probably won't work in all cases
|
|
|
|
* due to our having bogotified the internal state of dialog or curses,
|
|
|
|
* but we'll give it a try.
|
|
|
|
*/
|
1995-04-27 12:50:35 +00:00
|
|
|
static void
|
|
|
|
handle_intr(int sig)
|
|
|
|
{
|
1995-05-05 23:47:47 +00:00
|
|
|
if (!msgYesNo("Are you sure you want to abort the installation?"))
|
|
|
|
systemShutdown();
|
1995-04-27 12:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Welcome the user to the system */
|
|
|
|
void
|
|
|
|
systemWelcome(void)
|
|
|
|
{
|
1995-05-05 23:47:47 +00:00
|
|
|
printf("Installation system initializing..\n");
|
1995-04-27 12:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize system defaults */
|
|
|
|
void
|
|
|
|
systemInitialize(int argc, char **argv)
|
|
|
|
{
|
1995-05-19 16:58:58 +00:00
|
|
|
int i;
|
|
|
|
|
1995-04-27 12:50:35 +00:00
|
|
|
signal(SIGINT, SIG_IGN);
|
|
|
|
globalsInit();
|
|
|
|
|
|
|
|
/* Are we running as init? */
|
|
|
|
if (getpid() == 1) {
|
|
|
|
setsid();
|
|
|
|
if (argc > 1 && strchr(argv[1],'C')) {
|
|
|
|
/* Kernel told us that we are on a CDROM root */
|
|
|
|
close(0); open("/bootcd/dev/console", O_RDWR);
|
|
|
|
close(1); dup(0);
|
|
|
|
close(2); dup(0);
|
|
|
|
CpioFD = open("/floppies/cpio.flp", O_RDONLY);
|
|
|
|
OnCDROM = TRUE;
|
|
|
|
chroot("/bootcd");
|
|
|
|
} else {
|
|
|
|
close(0); open("/dev/console", O_RDWR);
|
|
|
|
close(1); dup(0);
|
|
|
|
close(2); dup(0);
|
|
|
|
}
|
1995-05-10 18:59:51 +00:00
|
|
|
printf("%s running as init\n", argv[0]);
|
1995-04-27 12:50:35 +00:00
|
|
|
|
|
|
|
ioctl(0, TIOCSCTTY, (char *)NULL);
|
|
|
|
setlogin("root");
|
1995-05-17 16:16:10 +00:00
|
|
|
setenv("PATH", "/stand:/mnt/bin:/mnt/sbin:/mnt/usr/sbin:/mnt/usr/bin", 1);
|
1995-04-27 12:50:35 +00:00
|
|
|
setbuf(stdin, 0);
|
|
|
|
setbuf(stdout, 0);
|
|
|
|
setbuf(stderr, 0);
|
|
|
|
}
|
|
|
|
|
1995-05-19 16:58:58 +00:00
|
|
|
for(i = 0; i < 256; i++)
|
|
|
|
default_scrnmap[i] = i;
|
|
|
|
|
1995-05-10 18:59:51 +00:00
|
|
|
if (set_termcap() == -1) {
|
|
|
|
printf("Can't find terminal entry\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
1995-04-27 12:50:35 +00:00
|
|
|
|
|
|
|
/* XXX - libdialog has particularly bad return value checking */
|
|
|
|
init_dialog();
|
|
|
|
/* If we haven't crashed I guess dialog is running ! */
|
|
|
|
DialogActive = TRUE;
|
|
|
|
|
|
|
|
signal(SIGINT, handle_intr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close down and prepare to exit */
|
|
|
|
void
|
|
|
|
systemShutdown(void)
|
|
|
|
{
|
|
|
|
if (DialogActive) {
|
|
|
|
end_dialog();
|
|
|
|
DialogActive = FALSE;
|
|
|
|
}
|
|
|
|
/* REALLY exit! */
|
|
|
|
if (getpid() == 1)
|
|
|
|
reboot(RB_HALT);
|
1995-04-29 19:33:06 +00:00
|
|
|
else
|
|
|
|
exit(1);
|
1995-04-27 12:50:35 +00:00
|
|
|
}
|
|
|
|
|
1995-04-29 19:33:06 +00:00
|
|
|
/* Run some general command */
|
1995-04-27 12:50:35 +00:00
|
|
|
int
|
|
|
|
systemExecute(char *command)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
dialog_clear();
|
|
|
|
dialog_update();
|
|
|
|
end_dialog();
|
|
|
|
DialogActive = FALSE;
|
|
|
|
status = system(command);
|
|
|
|
DialogActive = TRUE;
|
|
|
|
dialog_clear();
|
|
|
|
dialog_update();
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1995-04-29 19:33:06 +00:00
|
|
|
/* Find and execute a shell */
|
|
|
|
int
|
|
|
|
systemShellEscape(void)
|
|
|
|
{
|
|
|
|
char *sh = NULL;
|
|
|
|
|
|
|
|
if (file_executable("/bin/sh"))
|
|
|
|
sh = "/bin/sh";
|
|
|
|
else if (file_executable("/stand/sh"))
|
|
|
|
sh = "/stand/sh";
|
|
|
|
else {
|
|
|
|
msgWarn("No shell available, sorry!");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
setenv("PS1", "freebsd% ", 1);
|
|
|
|
dialog_clear();
|
|
|
|
dialog_update();
|
|
|
|
move(0, 0);
|
|
|
|
standout();
|
1995-05-01 21:56:32 +00:00
|
|
|
addstr("Type `exit' to leave this shell and continue installation");
|
1995-04-29 19:33:06 +00:00
|
|
|
standend();
|
|
|
|
refresh();
|
|
|
|
end_dialog();
|
|
|
|
DialogActive = FALSE;
|
|
|
|
if (fork() == 0)
|
|
|
|
execlp(sh, "-sh", 0);
|
|
|
|
else
|
|
|
|
wait(NULL);
|
|
|
|
dialog_clear();
|
|
|
|
DialogActive = TRUE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Display a file in a filebox */
|
|
|
|
int
|
|
|
|
systemDisplayFile(char *file)
|
|
|
|
{
|
1995-05-01 21:56:32 +00:00
|
|
|
char *fname = NULL;
|
|
|
|
char buf[FILENAME_MAX];
|
1995-05-16 11:37:27 +00:00
|
|
|
WINDOW *w;
|
1995-04-29 19:33:06 +00:00
|
|
|
|
1995-05-01 21:56:32 +00:00
|
|
|
fname = systemHelpFile(file, buf);
|
1995-04-29 19:33:06 +00:00
|
|
|
if (!fname) {
|
|
|
|
snprintf(buf, FILENAME_MAX, "The %s file is not provided on this particular floppy image.", file);
|
1995-05-01 21:56:32 +00:00
|
|
|
use_helpfile(NULL);
|
|
|
|
use_helpline(NULL);
|
1995-05-16 11:37:27 +00:00
|
|
|
w = dupwin(newscr);
|
1995-05-01 21:56:32 +00:00
|
|
|
dialog_mesgbox("Sorry!", buf, -1, -1);
|
1995-05-16 11:37:27 +00:00
|
|
|
touchwin(w);
|
|
|
|
wrefresh(w);
|
|
|
|
delwin(w);
|
1995-04-29 19:33:06 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
1995-05-01 21:56:32 +00:00
|
|
|
use_helpfile(NULL);
|
|
|
|
use_helpline(NULL);
|
1995-05-16 11:37:27 +00:00
|
|
|
w = dupwin(newscr);
|
1995-04-29 19:33:06 +00:00
|
|
|
dialog_textbox(file, fname, LINES, COLS);
|
1995-05-16 11:37:27 +00:00
|
|
|
touchwin(w);
|
|
|
|
wrefresh(w);
|
|
|
|
delwin(w);
|
1995-04-29 19:33:06 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1995-05-01 21:56:32 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
systemHelpFile(char *file, char *buf)
|
|
|
|
{
|
|
|
|
char *cp, *fname = NULL;
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((cp = getenv("LANG")) != NULL) {
|
|
|
|
snprintf(buf, FILENAME_MAX, "help/%s/%s", cp, file);
|
|
|
|
if (file_readable(buf))
|
|
|
|
fname = buf;
|
|
|
|
else {
|
|
|
|
snprintf(buf, FILENAME_MAX, "/stand/help/%s/%s", cp, file);
|
|
|
|
if (file_readable(buf))
|
|
|
|
fname = buf;
|
|
|
|
}
|
|
|
|
}
|
1995-05-07 03:38:03 +00:00
|
|
|
if (!fname) {
|
1995-05-01 21:56:32 +00:00
|
|
|
snprintf(buf, FILENAME_MAX, "help/en_US.ISO8859-1/%s", file);
|
|
|
|
if (file_readable(buf))
|
|
|
|
fname = buf;
|
|
|
|
else {
|
|
|
|
snprintf(buf, FILENAME_MAX, "/stand/help/en_US.ISO8859-1/%s",
|
|
|
|
file);
|
|
|
|
if (file_readable(buf))
|
|
|
|
fname = buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fname;
|
|
|
|
}
|
1995-05-04 19:48:19 +00:00
|
|
|
|
|
|
|
void
|
1995-05-05 23:47:47 +00:00
|
|
|
systemChangeFont(const u_char font[])
|
1995-05-04 19:48:19 +00:00
|
|
|
{
|
1995-05-18 17:49:09 +00:00
|
|
|
if (OnVTY && ColorDisplay) {
|
1995-05-18 15:29:47 +00:00
|
|
|
if (ioctl(0, PIO_FONT8x16, font) < 0)
|
1995-05-05 23:47:47 +00:00
|
|
|
msgConfirm("Sorry! Unable to load font for %s", getenv("LANG"));
|
|
|
|
}
|
1995-05-04 19:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
systemChangeLang(char *lang)
|
|
|
|
{
|
|
|
|
variable_set2("LANG", lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1995-05-05 23:47:47 +00:00
|
|
|
systemChangeTerminal(char *color, const u_char c_term[],
|
|
|
|
char *mono, const u_char m_term[])
|
1995-05-04 19:48:19 +00:00
|
|
|
{
|
1995-05-19 16:58:58 +00:00
|
|
|
extern void init_acs(void);
|
|
|
|
|
1995-05-18 15:29:47 +00:00
|
|
|
if (OnVTY) {
|
1995-05-05 23:47:47 +00:00
|
|
|
if (ColorDisplay) {
|
|
|
|
setenv("TERM", color, 1);
|
|
|
|
setenv("TERMCAP", c_term, 1);
|
1995-05-18 15:29:47 +00:00
|
|
|
reset_shell_mode();
|
|
|
|
setterm(color);
|
|
|
|
init_acs();
|
|
|
|
cbreak(); noecho();
|
1995-05-18 15:58:32 +00:00
|
|
|
dialog_clear();
|
1995-05-05 23:47:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
setenv("TERM", mono, 1);
|
|
|
|
setenv("TERMCAP", m_term, 1);
|
1995-05-18 15:29:47 +00:00
|
|
|
reset_shell_mode();
|
|
|
|
setterm(mono);
|
|
|
|
init_acs();
|
|
|
|
cbreak(); noecho();
|
1995-05-18 15:58:32 +00:00
|
|
|
dialog_clear();
|
1995-05-05 23:47:47 +00:00
|
|
|
}
|
|
|
|
}
|
1995-05-04 19:48:19 +00:00
|
|
|
}
|
|
|
|
|
1995-05-19 16:58:58 +00:00
|
|
|
void
|
|
|
|
systemChangeScreenmap(const u_char newmap[])
|
|
|
|
{
|
|
|
|
if (OnVTY) {
|
|
|
|
if (ioctl(0, PIO_SCRNMAP, newmap) < 0)
|
|
|
|
msgConfirm("Sorry! Unable to load the screenmap for %s",
|
|
|
|
getenv("LANG"));
|
1995-05-19 21:30:35 +00:00
|
|
|
dialog_clear();
|
1995-05-19 16:58:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-05-06 09:34:24 +00:00
|
|
|
/* Execute a system command, with varargs */
|
|
|
|
int
|
|
|
|
vsystem(char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
1995-05-18 02:42:33 +00:00
|
|
|
union wait pstat;
|
|
|
|
pid_t pid;
|
|
|
|
int omask;
|
|
|
|
sig_t intsave, quitsave;
|
1995-05-06 09:34:24 +00:00
|
|
|
char *cmd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cmd = (char *)malloc(FILENAME_MAX);
|
|
|
|
cmd[0] = '\0';
|
|
|
|
va_start(args, fmt);
|
1995-05-08 06:06:30 +00:00
|
|
|
vsnprintf(cmd, FILENAME_MAX, fmt, args);
|
1995-05-06 09:34:24 +00:00
|
|
|
va_end(args);
|
1995-05-18 02:42:33 +00:00
|
|
|
omask = sigblock(sigmask(SIGCHLD));
|
1995-05-20 13:24:35 +00:00
|
|
|
msgDebug("Executing command `%s'", cmd);
|
1995-05-18 02:42:33 +00:00
|
|
|
switch(pid = vfork()) {
|
|
|
|
case -1: /* error */
|
|
|
|
(void)sigsetmask(omask);
|
|
|
|
i = 127;
|
|
|
|
|
|
|
|
case 0: /* child */
|
|
|
|
(void)sigsetmask(omask);
|
1995-05-18 09:02:06 +00:00
|
|
|
if (DebugFD != -1) {
|
1995-05-20 08:31:43 +00:00
|
|
|
if (OnVTY)
|
|
|
|
msgInfo("Command output is on debugging screen - type ALT-F2 to see it");
|
1995-05-18 09:02:06 +00:00
|
|
|
dup2(DebugFD, 0);
|
|
|
|
dup2(DebugFD, 1);
|
|
|
|
dup2(DebugFD, 2);
|
|
|
|
}
|
1995-05-18 02:42:33 +00:00
|
|
|
execl("/stand/sh", "sh", "-c", cmd, (char *)NULL);
|
|
|
|
i = 127;
|
|
|
|
}
|
|
|
|
intsave = signal(SIGINT, SIG_IGN);
|
|
|
|
quitsave = signal(SIGQUIT, SIG_IGN);
|
|
|
|
pid = waitpid(pid, (int *)&pstat, 0);
|
|
|
|
(void)sigsetmask(omask);
|
|
|
|
(void)signal(SIGINT, intsave);
|
|
|
|
(void)signal(SIGQUIT, quitsave);
|
|
|
|
i = (pid == -1) ? -1 : pstat.w_status;
|
1995-05-08 06:06:30 +00:00
|
|
|
msgDebug("Command `%s' returns status of %d\n", cmd, i);
|
1995-05-06 09:34:24 +00:00
|
|
|
free(cmd);
|
|
|
|
return i;
|
|
|
|
}
|