Integrate my code a lot more with Pauls. (I have left sysinstall.c
here, even though it isn't used in the Makefile for Paul not to have an heart-attack when he wakes up. :-) Way to go still...
This commit is contained in:
parent
fc7c4debd9
commit
700c220c35
@ -4,9 +4,9 @@ NOMAN= yet
|
||||
|
||||
.PATH: /usr/src/sbin/disklabel
|
||||
|
||||
SRCS = sysinstall.c \
|
||||
dkcksum.c bootarea.c mbr.c \
|
||||
utils.c stage0.c stage3.c main.c
|
||||
SRCS = stage1.c dkcksum.c bootarea.c mbr.c \
|
||||
utils.c termcap.c \
|
||||
stage0.c stage2.c stage3.c main.c
|
||||
|
||||
CFLAGS += -Wall
|
||||
LDADD = -ldialog -lncurses -lmytinfo
|
||||
|
@ -10,9 +10,97 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <setjmp.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <dialog.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#define EXTERN /* only in main.c */
|
||||
|
||||
#include "sysinstall.h"
|
||||
|
||||
jmp_buf jmp_restart;
|
||||
|
||||
/*
|
||||
* This is the overall plan: (phk's version)
|
||||
*
|
||||
* If (pid == 1)
|
||||
* reopen stdin, stdout, stderr, and do various other magic.
|
||||
*
|
||||
* If (file exists /this_is_boot.flp)
|
||||
* stage0:
|
||||
* present /README
|
||||
* stage1:
|
||||
* Ask about diskallocation and do the fdisk/disklabel stunt.
|
||||
* stage2:
|
||||
* Do newfs, mount and copy over a minimal world.
|
||||
* make /mnt/etc/fstab. Install ourself as /mnt/sbin/init
|
||||
* Else
|
||||
* stage3:
|
||||
* Read cpio.flp and fiddle around with the bits a bit.
|
||||
* stage4:
|
||||
* Read bin-tarballs:
|
||||
* Using ftp
|
||||
* Using NFS (?)
|
||||
* Using floppy
|
||||
* Using tape
|
||||
* Using shell-prompt
|
||||
* stage5:
|
||||
* Extract bin-tarballs
|
||||
* stage6:
|
||||
* Ask various questions and collect answers into system-config
|
||||
* files.
|
||||
* stage7:
|
||||
* execl("/sbin/init");
|
||||
*/
|
||||
|
||||
int
|
||||
Xmain(int argc, char **argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
stage0();
|
||||
int i;
|
||||
|
||||
/* Are we running as init? */
|
||||
if (getpid() == 1) {
|
||||
close(0); open("/dev/console",O_RDWR);
|
||||
close(1); dup(0);
|
||||
close(2); dup(0);
|
||||
i = 1;
|
||||
ioctl(0,TIOCSPGRP,&i);
|
||||
setlogin("root");
|
||||
}
|
||||
|
||||
if (set_termcap() == -1) {
|
||||
Fatal("Can't find terminal entry\n");
|
||||
}
|
||||
/* XXX too early to use fatal ! */
|
||||
|
||||
/* XXX - libdialog has particularly bad return value checking */
|
||||
init_dialog();
|
||||
/* If we haven't crashed I guess dialog is running ! */
|
||||
dialog_active = 1;
|
||||
|
||||
setjmp(jmp_restart);
|
||||
|
||||
if (getenv("PAUL") || !access("/this_is_boot_flp",R_OK)) {
|
||||
stage0();
|
||||
stage1();
|
||||
/* XXX This is how stage one should output: */
|
||||
devicename[0] = StrAlloc("wd0a");
|
||||
mountpoint[0] = StrAlloc("/");
|
||||
devicename[1] = StrAlloc("wd0e");
|
||||
mountpoint[1] = StrAlloc("/usr");
|
||||
|
||||
stage2();
|
||||
} else {
|
||||
stage3();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,12 +23,12 @@
|
||||
void
|
||||
stage0()
|
||||
{
|
||||
if (!access(COPYRIGHT_FILE, R_OK)) {
|
||||
clear();
|
||||
dialog_textbox("COPYRIGHT", COPYRIGHT_FILE, 25, 80);
|
||||
}
|
||||
if (!access(README_FILE, R_OK)) {
|
||||
clear();
|
||||
dialog_textbox("READ ME FIRST", README_FILE, 25, 80);
|
||||
}
|
||||
if (!access(COPYRIGHT_FILE, R_OK)) {
|
||||
clear();
|
||||
dialog_textbox("COPYRIGHT", COPYRIGHT_FILE, 25, 80);
|
||||
}
|
||||
}
|
||||
|
327
sbin/sysinstall/stage1.c
Normal file
327
sbin/sysinstall/stage1.c
Normal file
@ -0,0 +1,327 @@
|
||||
/*
|
||||
#define DEBUG
|
||||
* Copyright (c) 1994, Paul Richards.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software may be used, modified, copied, distributed, and
|
||||
* sold, in both source and binary form provided that the above
|
||||
* copyright and these terms are retained, verbatim, as the first
|
||||
* lines of this file. Under no circumstances is the author
|
||||
* responsible for the proper functioning of this software, nor does
|
||||
* the author assume any responsibility for damages incurred with
|
||||
* its use.
|
||||
*/
|
||||
|
||||
#include <dialog.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <ufs/ffs/fs.h>
|
||||
#include <machine/console.h>
|
||||
|
||||
#include "mbr.h"
|
||||
#include "bootarea.h"
|
||||
#include "sysinstall.h"
|
||||
|
||||
struct disklabel *avail_disklabels;
|
||||
int *avail_fds;
|
||||
unsigned char **options;
|
||||
unsigned char **avail_disknames;
|
||||
unsigned char *scratch;
|
||||
unsigned char *errmsg;
|
||||
unsigned char *bootblocks;
|
||||
struct mbr *mbr;
|
||||
|
||||
int no_disks = 0;
|
||||
int inst_disk = 0;
|
||||
int inst_part = 0;
|
||||
int custom_install;
|
||||
int dialog_active = 0;
|
||||
|
||||
void exit_sysinstall();
|
||||
void exit_prompt();
|
||||
extern char *part_type(int);
|
||||
extern int disk_size(int);
|
||||
|
||||
/* To make the binary as small as possible these should be malloc'd */
|
||||
char selection[30];
|
||||
|
||||
int
|
||||
alloc_memory()
|
||||
{
|
||||
int i;
|
||||
|
||||
scratch = (char *) calloc(SCRATCHSIZE, sizeof(char));
|
||||
if (!scratch)
|
||||
return(-1);
|
||||
|
||||
errmsg = (char *) calloc(ERRMSGSIZE, sizeof(char));
|
||||
if (!errmsg)
|
||||
return(-1);
|
||||
|
||||
avail_disklabels = (struct disklabel *) calloc(MAX_NO_DISKS, sizeof(struct disklabel));
|
||||
if (!avail_disklabels)
|
||||
return(-1);
|
||||
|
||||
avail_fds = (int *) calloc(MAX_NO_DISKS, sizeof(int));
|
||||
if (!avail_fds)
|
||||
return(-1);
|
||||
|
||||
avail_disknames = (unsigned char **) calloc(MAX_NO_DISKS, sizeof(char *));
|
||||
if (!avail_disknames)
|
||||
return(-1);
|
||||
for (i=0;i<MAX_NO_DISKS;i++) {
|
||||
avail_disknames[i] = (char *) calloc(15, sizeof(char));
|
||||
if (!avail_disknames[i])
|
||||
return(-1);
|
||||
}
|
||||
|
||||
options = (unsigned char **) calloc(MAX_NO_DISKS, sizeof(char *));
|
||||
if (!options)
|
||||
return(-1);
|
||||
for (i=0;i<MAX_NO_DISKS;i++) {
|
||||
options[i] = (char *) calloc(100, sizeof(char));
|
||||
if (!options[i])
|
||||
return(-1);
|
||||
}
|
||||
|
||||
mbr = (struct mbr *) malloc(sizeof(struct mbr));
|
||||
if (!mbr)
|
||||
return(-1);
|
||||
|
||||
bootblocks = (char *) malloc(BBSIZE);
|
||||
if (!bootblocks)
|
||||
return(-1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
free_memory()
|
||||
{
|
||||
int i;
|
||||
|
||||
free(scratch);
|
||||
free(errmsg);
|
||||
free(avail_disklabels);
|
||||
free(avail_fds);
|
||||
|
||||
for (i=0;i<MAX_NO_DISKS;i++)
|
||||
free(avail_disknames[i]);
|
||||
free(avail_disknames);
|
||||
|
||||
for (i=0;i<MAX_NO_DISKS;i++)
|
||||
free(options[i]);
|
||||
free(options);
|
||||
|
||||
free(mbr);
|
||||
free(bootblocks);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
query_disks()
|
||||
{
|
||||
int i;
|
||||
char disk[15];
|
||||
char diskname[5];
|
||||
struct stat st;
|
||||
int fd;
|
||||
|
||||
no_disks = 0;
|
||||
for (i=0;i<10;i++) {
|
||||
sprintf(diskname,"wd%d",i);
|
||||
sprintf(disk,"/dev/r%sd",diskname);
|
||||
if ((stat(disk, &st) == 0) && (st.st_mode & S_IFCHR))
|
||||
if ((fd = open(disk, O_RDWR)) != -1) {
|
||||
avail_fds[no_disks] = fd;
|
||||
bcopy(diskname, avail_disknames[no_disks], strlen(diskname));
|
||||
if (ioctl(fd, DIOCGDINFO, &avail_disklabels[no_disks++]) == -1)
|
||||
no_disks--;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0;i<10;i++) {
|
||||
sprintf(diskname,"sd%d",i);
|
||||
sprintf(disk,"/dev/r%sd",diskname);
|
||||
if ((stat(disk, &st) == 0) && (st.st_mode & S_IFCHR))
|
||||
if ((fd = open(disk, O_RDWR)) != -1) {
|
||||
avail_fds[no_disks] = fd;
|
||||
bcopy(diskname, avail_disknames[no_disks], strlen(diskname));
|
||||
if (ioctl(fd, DIOCGDINFO, &avail_disklabels[no_disks++]) == -1)
|
||||
no_disks--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
select_disk()
|
||||
{
|
||||
int i;
|
||||
int valid;
|
||||
|
||||
do {
|
||||
valid = 1;
|
||||
sprintf(scratch,"There are %d disks available for installation: ",no_disks);
|
||||
|
||||
for (i=0;i<no_disks;i++) {
|
||||
sprintf(options[(i*2)], "%d",i+1);
|
||||
sprintf(options[(i*2)+1], "%s, (%dMb) -> %s",avail_disklabels[i].d_typename,disk_size(i),avail_disknames[i]);
|
||||
}
|
||||
|
||||
if (dialog_menu("FreeBSD Installation", scratch, 10, 75, 5, no_disks, options, selection)) {
|
||||
sprintf(scratch,"You did not select a valid disk");
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
}
|
||||
clear();
|
||||
} while (!valid);
|
||||
return(atoi(selection) - 1);
|
||||
}
|
||||
|
||||
int
|
||||
select_partition(int disk)
|
||||
{
|
||||
int valid;
|
||||
int i;
|
||||
int choice;
|
||||
|
||||
do {
|
||||
valid = 1;
|
||||
|
||||
sprintf(scratch,"Select one of the following areas to install to:");
|
||||
sprintf(options[0], "%d", 0);
|
||||
sprintf(options[1], "%s, (%dMb)", "Install to entire disk",
|
||||
disk_size(disk));
|
||||
for (i=0; i < NDOSPART; i++) {
|
||||
sprintf(options[(i*2)+2], "%d",i+1);
|
||||
sprintf(options[(i*2)+3], "%s, (%ldMb)",
|
||||
part_type(mbr->dospart[i].dp_typ),
|
||||
mbr->dospart[i].dp_size * 512 / (1024 * 1024));
|
||||
}
|
||||
if (dialog_menu(TITLE,
|
||||
scratch, 10, 75, 5, 5, options, selection)) {
|
||||
sprintf(scratch,"You did not select a valid partition");
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
}
|
||||
clear();
|
||||
choice = atoi(selection);
|
||||
if (!choice)
|
||||
if (dialog_yesno(TITLE, "Installing to the whole disk will erase all its present data.\n\nAre you sure you want to do this?", 10, 75))
|
||||
valid = 0;
|
||||
clear();
|
||||
} while (!valid);
|
||||
|
||||
return(atoi(selection) - 1);
|
||||
}
|
||||
|
||||
void
|
||||
stage1()
|
||||
{
|
||||
int i;
|
||||
int ok = 0;
|
||||
int ready = 0;
|
||||
|
||||
alloc_memory();
|
||||
while (!ready) {
|
||||
ready = 1;
|
||||
|
||||
query_disks();
|
||||
inst_disk = select_disk();
|
||||
|
||||
#ifdef DEBUG
|
||||
read_mbr(avail_fds[inst_disk], mbr);
|
||||
show_mbr(mbr);
|
||||
#endif
|
||||
|
||||
if (read_mbr(avail_fds[inst_disk], mbr) == -1) {
|
||||
sprintf(scratch, "The following error occured will trying to read the master boot record:\n\n%s\n\nIn order to install FreeBSD a new master boot record will have to be written which will mean all current data on the hard disk will be lost.", errmsg);
|
||||
ok = 0;
|
||||
while (!ok) {
|
||||
AskAbort(scratch);
|
||||
if (!dialog_yesno(TITLE, "Are you sure you wish to proceed?",
|
||||
10, 75)) {
|
||||
clear();
|
||||
clear_mbr(mbr);
|
||||
ok = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (custom_install)
|
||||
if (!dialog_yesno(TITLE, "Do you wish to edit the DOS partition table?",
|
||||
10, 75)) {
|
||||
clear();
|
||||
edit_mbr(mbr, &avail_disklabels[inst_disk]);
|
||||
}
|
||||
|
||||
inst_part = select_partition(inst_disk);
|
||||
|
||||
ok = 0;
|
||||
while (!ok) {
|
||||
if (build_mbr(mbr, &avail_disklabels[inst_disk]))
|
||||
ok = 1;
|
||||
else {
|
||||
sprintf(scratch, "The DOS partition table is inconsistent.\n\n%s\n\nDo you wish to edit it by hand?", errmsg);
|
||||
if (!dialog_yesno(TITLE, scratch, 10, 75)) {
|
||||
edit_mbr(mbr, &avail_disklabels[inst_disk]);
|
||||
clear();
|
||||
} else {
|
||||
AskAbort("");
|
||||
ok = 1;
|
||||
ready = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default_disklabel(&avail_disklabels[inst_disk],
|
||||
mbr->dospart[inst_part].dp_size,
|
||||
mbr->dospart[inst_part].dp_start);
|
||||
build_bootblocks(&avail_disklabels[inst_disk]);
|
||||
|
||||
if (ready) {
|
||||
if (dialog_yesno(TITLE, "We are now ready to format the hard disk for FreeBSD.\n\nSome or all of the disk will be overwritten during this process.\n\nAre you sure you wish to proceed ?", 10, 75)) {
|
||||
AskAbort("");
|
||||
ready = 0;
|
||||
}
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
/* Write master boot record and bootblocks */
|
||||
write_mbr(avail_fds[inst_disk], mbr);
|
||||
write_bootblocks(avail_fds[inst_disk],
|
||||
mbr->dospart[inst_part].dp_start,
|
||||
avail_disklabels[inst_disk].d_bbsize);
|
||||
|
||||
#ifdef DEBUG
|
||||
read_mbr(avail_fds[inst_disk], mbr);
|
||||
show_mbr(mbr);
|
||||
#endif
|
||||
|
||||
/* close all the open disks */
|
||||
for (i=0; i < no_disks; i++)
|
||||
if (close(avail_fds[i]) == -1) {
|
||||
sprintf(errmsg, "Error on closing file descriptors: %s\n",
|
||||
strerror(errno));
|
||||
Fatal(errmsg);
|
||||
}
|
||||
|
||||
}
|
||||
|
80
sbin/sysinstall/stage2.c
Normal file
80
sbin/sysinstall/stage2.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <ncurses.h>
|
||||
#include <dialog.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "sysinstall.h"
|
||||
|
||||
void
|
||||
stage2()
|
||||
{
|
||||
char **p,**q;
|
||||
char buf[90];
|
||||
char *diskname = "sd0";
|
||||
int i;
|
||||
|
||||
for(p = devicename; *p; p++) {
|
||||
TellEm("newfs /dev/r%s",*p);
|
||||
strcpy(scratch, "/dev/r");
|
||||
strcat(scratch, *p);
|
||||
if (exec("/bin/newfs","/bin/newfs", scratch, 0) == -1)
|
||||
Fatal(errmsg);
|
||||
}
|
||||
|
||||
for(q=mountpoint,p = devicename; *p; p++,q++) {
|
||||
MountUfs(*p, "/mnt", *q, 1);
|
||||
}
|
||||
|
||||
TellEm("cpio -dumpv /mnt < file.list");
|
||||
if (exec("/bin/cpio","/bin/cpio", "-dumpv", "/mnt", 0) == -1)
|
||||
Fatal(errmsg);
|
||||
|
||||
TellEm("write /mnt/etc/fstab");
|
||||
i = open("/mnt/etc/fstab",O_CREAT|O_TRUNC|O_APPEND|O_WRONLY,0644);
|
||||
if(i < 0) {
|
||||
Fatal("Couldn't open /mnt/etc/fstab for writing");
|
||||
}
|
||||
|
||||
sprintf(scratch,"/dev/%sa / ufs rw 1 1\n",diskname);
|
||||
write(i,scratch,strlen(scratch));
|
||||
sprintf(scratch,"/dev/%sb none swap sw 0 0\n",diskname);
|
||||
write(i,scratch,strlen(scratch));
|
||||
sprintf(scratch,"proc /proc procfs rw 0 0\n");
|
||||
write(i,scratch,strlen(scratch));
|
||||
sprintf(scratch,"/dev/%se /usr ufs rw 1 2\n",diskname);
|
||||
write(i,scratch,strlen(scratch));
|
||||
close(i);
|
||||
|
||||
TellEm("unmount /mnt/usr");
|
||||
if (unmount("/mnt/usr", 0) == -1) {
|
||||
sprintf(errmsg, "Error unmounting /mnt/usr: %s\n", strerror(errno));
|
||||
Fatal(errmsg);
|
||||
}
|
||||
|
||||
TellEm("unmount /mnt");
|
||||
if (unmount("/mnt", 0) == -1) {
|
||||
sprintf(errmsg, "Error unmounting /mnt: %s\n", strerror(errno));
|
||||
Fatal(errmsg);
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@ stage3()
|
||||
|
||||
i = open("/etc/fstab", O_RDONLY);
|
||||
if (i < 0) {
|
||||
fatal("Couldn't open /etc/fstab");
|
||||
Fatal("Couldn't open /etc/fstab");
|
||||
}
|
||||
read(i, scratch, 100);
|
||||
for (s = scratch; *s != ' ' && *s != '\t'; s++);
|
||||
@ -60,7 +60,7 @@ stage3()
|
||||
s = scratch + 5;
|
||||
diskname = malloc(strlen(s) + 1);
|
||||
if (!diskname) {
|
||||
fatal("malloc failed");
|
||||
Fatal("malloc failed");
|
||||
}
|
||||
strcpy(diskname, s);
|
||||
close(i);
|
||||
@ -71,7 +71,7 @@ stage3()
|
||||
ufsargs.fspec = scratch;
|
||||
if (mount(MOUNT_UFS, "/", MNT_UPDATE, (caddr_t) & ufsargs) == -1) {
|
||||
sprintf(errmsg, "Failed to mount root read/write: %s\n%s", strerror(errno), ufsargs.fspec);
|
||||
fatal(errmsg);
|
||||
Fatal(errmsg);
|
||||
}
|
||||
sprintf(scratch, "mount /dev/%se /usr", diskname);
|
||||
TellEm(scratch);
|
||||
@ -79,58 +79,58 @@ stage3()
|
||||
ufsargs.fspec = scratch;
|
||||
if (mount(MOUNT_UFS, "/usr", 0, (caddr_t) & ufsargs) == -1) {
|
||||
sprintf(errmsg, "Failed to mount /usr: %s\n%s", strerror(errno), ufsargs.fspec);
|
||||
fatal(errmsg);
|
||||
Fatal(errmsg);
|
||||
}
|
||||
TellEm("mkdir /proc");
|
||||
if (mkdir("/proc", S_IRWXU) == -1) {
|
||||
sprintf(errmsg, "Couldn't create directory /proc: %s\n",
|
||||
strerror(errno));
|
||||
fatal(errmsg);
|
||||
Fatal(errmsg);
|
||||
}
|
||||
TellEm("mkdir /root");
|
||||
if (mkdir("/root", S_IRWXU) == -1) {
|
||||
sprintf(errmsg, "Couldn't create directory /root: %s\n",
|
||||
strerror(errno));
|
||||
fatal(errmsg);
|
||||
Fatal(errmsg);
|
||||
}
|
||||
TellEm("mkdir /var");
|
||||
if (mkdir("/var", S_IRWXU) == -1) {
|
||||
sprintf(errmsg, "Couldn't create directory /var: %s\n",
|
||||
strerror(errno));
|
||||
fatal(errmsg);
|
||||
Fatal(errmsg);
|
||||
}
|
||||
TellEm("mkdir /var/run");
|
||||
if (mkdir("/var/run", S_IRWXU) == -1) {
|
||||
sprintf(errmsg, "Couldn't create directory /var/run: %s\n",
|
||||
strerror(errno));
|
||||
fatal(errmsg);
|
||||
Fatal(errmsg);
|
||||
}
|
||||
sprintf(scratch, "Insert CPIO floppy in floppy drive 0\n");
|
||||
dialog_msgbox("Stage 2 installation", scratch, 6, 75, 1);
|
||||
ufsargs.fspec = "/dev/fd0a";
|
||||
if (mount(MOUNT_UFS, "/mnt", MNT_RDONLY, (caddr_t) & ufsargs) == -1) {
|
||||
sprintf(errmsg, "Failed to mount /mnt: %s\n%s", strerror(errno), ufsargs.fspec);
|
||||
fatal(errmsg);
|
||||
Fatal(errmsg);
|
||||
}
|
||||
TellEm("sh -c 'cd / ; gunzip < /mnt/inst2.cpio.gz | cpio -idum'");
|
||||
if (exec("/bin/sh", "/bin/sh", "-e", "-c",
|
||||
"cd / ; gunzip < /mnt/inst2.cpio.gz | cpio -idum", 0) == -1)
|
||||
fatal(errmsg);
|
||||
Fatal(errmsg);
|
||||
|
||||
TellEm("sh -c 'cd /mnt ; ls install magic | cpio -dump /'");
|
||||
if (exec("/bin/sh", "/bin/sh", "-e", "-c",
|
||||
"cd /mnt ; ls magic | cpio -dump /", 0) == -1)
|
||||
fatal(errmsg);
|
||||
Fatal(errmsg);
|
||||
|
||||
TellEm("unmount /mnt");
|
||||
if (unmount("/mnt", 0) == -1) {
|
||||
sprintf(errmsg, "Error unmounting /mnt: %s\n", strerror(errno));
|
||||
fatal(errmsg);
|
||||
Fatal(errmsg);
|
||||
}
|
||||
TellEm("sh -c 'cd /dev ; sh MAKEDEV all'");
|
||||
if (exec("/bin/sh", "/bin/sh", "-e", "-c",
|
||||
"PATH=/bin:/sbin:/usr/bin:/usr/sbin; export PATH ; cd /dev ; sh MAKEDEV all", 0) == -1)
|
||||
fatal(errmsg);
|
||||
Fatal(errmsg);
|
||||
|
||||
TellEm("unlink /sbin/oinit");
|
||||
unlink("/sbin/oinit");
|
||||
|
85
sbin/sysinstall/termcap.c
Normal file
85
sbin/sysinstall/termcap.c
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 1994, Paul Richards.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software may be used, modified, copied, distributed, and sold, in both
|
||||
* source and binary form provided that the above copyright and these terms
|
||||
* are retained, verbatim, as the first lines of this file. Under no
|
||||
* circumstances is the author responsible for the proper functioning of this
|
||||
* software, nor does the author assume any responsibility for damages
|
||||
* incurred with its use.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <fcntl.h>
|
||||
#include <dialog.h>
|
||||
#include <ncurses.h>
|
||||
#include <machine/console.h>
|
||||
|
||||
#include "sysinstall.h"
|
||||
|
||||
static void
|
||||
emergency()
|
||||
{
|
||||
putenv("TERMCAP=\
|
||||
cons25|ansis|ansi80x25:\
|
||||
:ac=l\\332m\\300k\\277j\\331u\\264t\\303v\\301w\\302q\\304x\\263n\\305`^Da\\260f\\370g\\361~\\371.^Y-^Xh\\261I^U0\\333y\\363z\\362:\
|
||||
:al=\\E[L:am:bs:cd=\\E[J:ce=\\E[K:cl=\\E[H\\E[J:cm=\\E[%i%d;%dH:co#80:\
|
||||
:dc=\\E[P:dl=\\E[M:do=\\E[B:bt=\\E[Z:ho=\\E[H:ic=\\E[@:li#25:\
|
||||
:ms:nd=\\E[C:pt:rs=\\E[x\\E[m\\Ec:so=\\E[7m:se=\\E[m:up=\\E[A:\
|
||||
:pa#64:Co#8:Sf=\\E[3%dm:Sb=\\E[4%dm:op=\\E[37;40m:\
|
||||
:k1=\\E[M:k2=\\E[N:k3=\\E[O:k4=\\E[P:k5=\\E[Q:k6=\\E[R:k7=\\E[S:k8=\\E[T:\
|
||||
:k9=\\E[U:k;=\\E[V:F1=\\E[W:F2=\\E[X:\
|
||||
:kb=^H:kh=\\E[H:ku=\\E[A:kd=\\E[B:kl=\\E[D:kr=\\E[C:\
|
||||
:le=^H:eo:sf=\\E[S:sr=\\E[T:\
|
||||
:kN=\\E[G:kP=\\E[I:@7=\\E[F:kI=\\E[L:kD=\\177:kB=\\E[Z:\
|
||||
:IC=\\E[%d@:DC=\\E[%dP:SF=\\E[%dS:SR=\\E[%dT:AL=\\E[%dL:DL=\\E[%dM:\
|
||||
:DO=\\E[%dB:LE=\\E[%dD:RI=\\E[%dC:UP=\\E[%dA:bw:\
|
||||
:mb=\\E[5m:md=\\E[1m:mh=\\E[30;1m:mr=\\E[7m:me=\\E[m:bl=^G:ut:it#8:");
|
||||
}
|
||||
|
||||
int
|
||||
set_termcap()
|
||||
{
|
||||
char *term;
|
||||
|
||||
term = getenv("TERM");
|
||||
if (term == NULL) {
|
||||
int color_display;
|
||||
|
||||
if (access("/etc/termcap.small",R_OK)) {
|
||||
emergency();
|
||||
} else if (setenv("TERMCAP", "/etc/termcap.small", 1) < 0)
|
||||
return -1;
|
||||
if (ioctl(STDERR_FILENO, GIO_COLOR, &color_display) < 0) {
|
||||
char buf[64];
|
||||
int len;
|
||||
|
||||
/* serial console */
|
||||
fprintf(stderr, "Enter your terminal type (must be present in /etc/termcap.small): ");
|
||||
if (fgets(buf, sizeof(buf), stdin) == NULL)
|
||||
return -1;
|
||||
len = strlen(buf);
|
||||
if (len > 0 && buf[len - 1] == '\n')
|
||||
buf[len - 1] = '\0';
|
||||
if (setenv("TERM", buf, 1) < 0)
|
||||
return -1;
|
||||
} else if (color_display) {
|
||||
|
||||
/* color console */
|
||||
if (setenv("TERM", "cons25", 1) < 0)
|
||||
return -1;
|
||||
} else {
|
||||
|
||||
/* mono console */
|
||||
if (setenv("TERM", "cons25-m", 1) < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -13,8 +13,17 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <dialog.h>
|
||||
#include <ncurses.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include "sysinstall.h"
|
||||
|
||||
@ -28,6 +37,37 @@ TellEm(char *fmt, ...)
|
||||
vsnprintf(p, 2048, fmt, ap);
|
||||
va_end(ap);
|
||||
dialog_msgbox("Progress", p, 3, 75, 0);
|
||||
free(p);
|
||||
}
|
||||
|
||||
void
|
||||
Fatal(char *fmt, ...)
|
||||
{
|
||||
char *p;
|
||||
va_list ap;
|
||||
p = Malloc(2048);
|
||||
va_start(ap,fmt);
|
||||
vsnprintf(p, 2048, fmt, ap);
|
||||
va_end(ap);
|
||||
dialog_msgbox("Fatal", p, 12, 75, 1);
|
||||
free(p);
|
||||
exit(7);
|
||||
}
|
||||
|
||||
int
|
||||
AskAbort(char *fmt, ...)
|
||||
{
|
||||
char *p;
|
||||
va_list ap;
|
||||
int i;
|
||||
|
||||
p = Malloc(2048);
|
||||
va_start(ap,fmt);
|
||||
vsnprintf(p, 2048, fmt, ap);
|
||||
va_end(ap);
|
||||
i = dialog_yesno("Abort", p, 12, 75);
|
||||
free(p);
|
||||
return i;
|
||||
}
|
||||
|
||||
void *
|
||||
@ -39,3 +79,92 @@ Malloc(size_t size)
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
char *
|
||||
StrAlloc(char *str)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = (char *)Malloc(strlen(str) + 1);
|
||||
strcpy(p,str);
|
||||
return p;
|
||||
}
|
||||
|
||||
int
|
||||
exec(char *cmd, char *args, ...)
|
||||
{
|
||||
int pid, w, status;
|
||||
char **argv = NULL;
|
||||
int arg = 0;
|
||||
int no_args = 0;
|
||||
va_list ap;
|
||||
struct stat dummy;
|
||||
|
||||
if (stat(cmd, &dummy) == -1) {
|
||||
sprintf(errmsg, "Executable %s does not exist\n", cmd);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
va_start(ap, args);
|
||||
do {
|
||||
if (arg == no_args) {
|
||||
no_args += 10;
|
||||
if (!(argv = realloc(argv, no_args * sizeof(char *)))) {
|
||||
sprintf(errmsg, "Failed to allocate memory during exec of %s\n", cmd);
|
||||
return(-1);
|
||||
}
|
||||
if (arg == 0)
|
||||
argv[arg++] = (char *)args;
|
||||
}
|
||||
} while ((argv[arg++] = va_arg(ap, char *)));
|
||||
va_end(ap);
|
||||
|
||||
if ((pid = fork()) == 0) {
|
||||
execv(cmd, argv);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while ((w = wait(&status)) != pid && w != -1)
|
||||
;
|
||||
|
||||
free(argv);
|
||||
if (w == -1) {
|
||||
sprintf(errmsg, "Child process %s terminated abnormally\n", cmd);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
MountUfs(char *device, char *prefix, char *mountpoint, int do_mkdir)
|
||||
{
|
||||
struct ufs_args ufsargs;
|
||||
char dbuf[90];
|
||||
char pbuf[90];
|
||||
|
||||
if (prefix)
|
||||
strcpy(pbuf,prefix);
|
||||
else
|
||||
strcpy(pbuf,"");
|
||||
|
||||
strcat(pbuf,mountpoint);
|
||||
|
||||
if(do_mkdir && access(pbuf,R_OK)) {
|
||||
TellEm("mkdir %s",pbuf);
|
||||
if (mkdir(pbuf,S_IRWXU) == -1) {
|
||||
Fatal("Couldn't create directory %s: %s\n",
|
||||
pbuf,strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
strcpy(dbuf,"/dev/");
|
||||
strcat(dbuf,device);
|
||||
|
||||
TellEm("mount /dev/%s /mnt%s",dbuf,pbuf);
|
||||
ufsargs.fspec = dbuf;
|
||||
if (mount(MOUNT_UFS,pbuf, 0, (caddr_t) &ufsargs) == -1) {
|
||||
Fatal("Error mounting %s on : %s\n",
|
||||
dbuf, pbuf, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user