diff --git a/sbin/sysinstall/Makefile b/sbin/sysinstall/Makefile index 8ab1f792f112..b69c29a41115 100644 --- a/sbin/sysinstall/Makefile +++ b/sbin/sysinstall/Makefile @@ -4,7 +4,9 @@ NOMAN= yet .PATH: /usr/src/sbin/disklabel -SRCS = sysinstall.c dkcksum.c bootarea.c mbr.c +SRCS = sysinstall.c \ + dkcksum.c bootarea.c mbr.c \ + utils.c stage0.c stage3.c main.c CFLAGS += -Wall LDADD = -ldialog -lncurses -lmytinfo diff --git a/sbin/sysinstall/main.c b/sbin/sysinstall/main.c new file mode 100644 index 000000000000..7c1a106724fc --- /dev/null +++ b/sbin/sysinstall/main.c @@ -0,0 +1,18 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * 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$ + * + */ + +int +Xmain(int argc, char **argv) +{ + stage0(); + return 0; +} diff --git a/sbin/sysinstall/stage0.c b/sbin/sysinstall/stage0.c new file mode 100644 index 000000000000..72d3795f69a7 --- /dev/null +++ b/sbin/sysinstall/stage0.c @@ -0,0 +1,34 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * 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 +#include +#include +#include + +#include +#include + +#include "sysinstall.h" + +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); + } +} diff --git a/sbin/sysinstall/stage3.c b/sbin/sysinstall/stage3.c new file mode 100644 index 000000000000..5b7a1a1b481b --- /dev/null +++ b/sbin/sysinstall/stage3.c @@ -0,0 +1,146 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#if 0 +#include +#include +#include +#include +#include +#include "bootarea.h" +#include +#endif + +#include "sysinstall.h" + +void +stage3() +{ + char *diskname; + struct ufs_args ufsargs; + char *s; + int i; + + /* + * Extract the disk-name from /etc/fstab, we wrote it ourselves, + * so we know how to read it :-) + * XXX: Multidisk installs. We need to mount all partitions. + */ + + i = open("/etc/fstab", O_RDONLY); + if (i < 0) { + fatal("Couldn't open /etc/fstab"); + } + read(i, scratch, 100); + for (s = scratch; *s != ' ' && *s != '\t'; s++); + s--; + *s = '\0'; + s = scratch + 5; + diskname = malloc(strlen(s) + 1); + if (!diskname) { + fatal("malloc failed"); + } + strcpy(diskname, s); + close(i); + + sprintf(scratch, "mount -u /dev/%sa /", diskname); + TellEm(scratch); + sprintf(scratch, "/dev/%sa", diskname); + 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); + } + sprintf(scratch, "mount /dev/%se /usr", diskname); + TellEm(scratch); + sprintf(scratch, "/dev/%se", diskname); + 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); + } + TellEm("mkdir /proc"); + if (mkdir("/proc", S_IRWXU) == -1) { + sprintf(errmsg, "Couldn't create directory /proc: %s\n", + strerror(errno)); + fatal(errmsg); + } + TellEm("mkdir /root"); + if (mkdir("/root", S_IRWXU) == -1) { + sprintf(errmsg, "Couldn't create directory /root: %s\n", + strerror(errno)); + fatal(errmsg); + } + TellEm("mkdir /var"); + if (mkdir("/var", S_IRWXU) == -1) { + sprintf(errmsg, "Couldn't create directory /var: %s\n", + strerror(errno)); + 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); + } + 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); + } + 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); + + 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); + + TellEm("unmount /mnt"); + if (unmount("/mnt", 0) == -1) { + sprintf(errmsg, "Error unmounting /mnt: %s\n", strerror(errno)); + 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); + + TellEm("unlink /sbin/oinit"); + unlink("/sbin/oinit"); + TellEm("link /stand/sysinstall /sbin/init"); + link("/stand/sysinstall", "/sbin/init"); + clear(); + refresh(); + endwin(); + close(0); + close(1); + close(2); + execl("/sbin/init", "init", 0); +} diff --git a/sbin/sysinstall/sysinstall.c b/sbin/sysinstall/sysinstall.c index 6787a2942c38..16b263bad41b 100644 --- a/sbin/sysinstall/sysinstall.c +++ b/sbin/sysinstall/sysinstall.c @@ -765,6 +765,12 @@ main(int argc, char **argv) { int i; + /* phk's main */ + if (argc > 1 && !strcmp(argv[1],"phk")) { + return Xmain(argc,argv); + } + + /* paul's main */ /* Are we running as init? */ if (getpid() == 1) { close(0); open("/dev/console",O_RDWR); diff --git a/sbin/sysinstall/sysinstall.h b/sbin/sysinstall/sysinstall.h index 4562263c4844..b92124d4135c 100644 --- a/sbin/sysinstall/sysinstall.h +++ b/sbin/sysinstall/sysinstall.h @@ -22,6 +22,9 @@ #define BOOT_MAGIC 0xAA55 #define ACTIVE 0x80 +#define COPYRIGHT_FILE "/COPYRIGHT" +#define README_FILE "/README" + #define STATUSFILE "sysinstall.stat" #define NOT_INSTALLED 0 #define DISK_READY 1 @@ -45,3 +48,8 @@ extern unsigned char *errmsg; extern int *avail_fds; extern struct disklabel *avail_disklabels; extern u_short dkcksum(struct disklabel *); + +void TellEm __P((char *fmt, ...)); +void stage0 __P((void)); +void *Malloc __P((size_t size)); + diff --git a/sbin/sysinstall/utils.c b/sbin/sysinstall/utils.c new file mode 100644 index 000000000000..24bd0ada9ae9 --- /dev/null +++ b/sbin/sysinstall/utils.c @@ -0,0 +1,41 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * 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 +#include +#include +#include +#include + +#include "sysinstall.h" + +void +TellEm(char *fmt, ...) +{ + char *p; + va_list ap; + p = Malloc(2048); + va_start(ap,fmt); + vsnprintf(p, 2048, fmt, ap); + va_end(ap); + dialog_msgbox("Progress", p, 3, 75, 0); +} + +void * +Malloc(size_t size) +{ + void *p = malloc(size); + if (!p) { + exit(7); /* XXX longjmp bad */ + } + return p; +}