1995-04-27 14:50:35 +02: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-01 23:56:32 +02:00
|
|
|
* $Id: system.c,v 1.2 1995/04/29 19:33:06 jkh Exp $
|
1995-04-27 14:50:35 +02:00
|
|
|
*
|
|
|
|
* Jordan Hubbard
|
|
|
|
*
|
|
|
|
* My contributions are in the public domain.
|
|
|
|
*
|
|
|
|
* Parts of this file are also blatently stolen from Poul-Henning Kamp's
|
|
|
|
* 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!
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysinstall.h"
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
1995-04-29 21:33:06 +02:00
|
|
|
#include <sys/wait.h>
|
1995-04-27 14:50:35 +02:00
|
|
|
|
|
|
|
/* Handle interrupt signals (duh!) */
|
|
|
|
static void
|
|
|
|
handle_intr(int sig)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Welcome the user to the system */
|
|
|
|
void
|
|
|
|
systemWelcome(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize system defaults */
|
|
|
|
void
|
|
|
|
systemInitialize(int argc, char **argv)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
msgInfo("%s running as init", argv[0]);
|
|
|
|
|
|
|
|
ioctl(0, TIOCSCTTY, (char *)NULL);
|
|
|
|
setlogin("root");
|
|
|
|
setbuf(stdin, 0);
|
|
|
|
setbuf(stdout, 0);
|
|
|
|
setbuf(stderr, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set_termcap() == -1)
|
|
|
|
msgFatal("Can't find terminal entry");
|
|
|
|
|
|
|
|
/* 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 21:33:06 +02:00
|
|
|
else
|
|
|
|
exit(1);
|
1995-04-27 14:50:35 +02:00
|
|
|
}
|
|
|
|
|
1995-04-29 21:33:06 +02:00
|
|
|
/* Run some general command */
|
1995-04-27 14:50:35 +02: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 21:33:06 +02: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 23:56:32 +02:00
|
|
|
addstr("Type `exit' to leave this shell and continue installation");
|
1995-04-29 21:33:06 +02: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 23:56:32 +02:00
|
|
|
char *fname = NULL;
|
|
|
|
char buf[FILENAME_MAX];
|
1995-04-29 21:33:06 +02:00
|
|
|
|
1995-05-01 23:56:32 +02:00
|
|
|
fname = systemHelpFile(file, buf);
|
1995-04-29 21:33:06 +02:00
|
|
|
if (!fname) {
|
|
|
|
snprintf(buf, FILENAME_MAX, "The %s file is not provided on this particular floppy image.", file);
|
1995-05-01 23:56:32 +02:00
|
|
|
use_helpfile(NULL);
|
|
|
|
use_helpline(NULL);
|
|
|
|
dialog_mesgbox("Sorry!", buf, -1, -1);
|
1995-04-29 21:33:06 +02:00
|
|
|
dialog_clear_norefresh();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dialog_clear_norefresh();
|
1995-05-01 23:56:32 +02:00
|
|
|
use_helpfile(NULL);
|
|
|
|
use_helpline(NULL);
|
1995-04-29 21:33:06 +02:00
|
|
|
dialog_textbox(file, fname, LINES, COLS);
|
|
|
|
dialog_clear_norefresh();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1995-05-01 23:56:32 +02: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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;
|
|
|
|
}
|