mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-20 23:54:38 +01:00
The beginning of some structural changes, and the merge of my code into
Pauls.
This commit is contained in:
parent
3e3ad4f2f1
commit
8ae68834f1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=3734
@ -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
|
||||
|
18
sbin/sysinstall/main.c
Normal file
18
sbin/sysinstall/main.c
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "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$
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
Xmain(int argc, char **argv)
|
||||
{
|
||||
stage0();
|
||||
return 0;
|
||||
}
|
34
sbin/sysinstall/stage0.c
Normal file
34
sbin/sysinstall/stage0.c
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <ncurses.h>
|
||||
#include <dialog.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
146
sbin/sysinstall/stage3.c
Normal file
146
sbin/sysinstall/stage3.c
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <phk@login.dknet.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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <dialog.h>
|
||||
#include <ncurses.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if 0
|
||||
#include <sys/types.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/wait.h>
|
||||
#include "bootarea.h"
|
||||
#include <ufs/ffs/fs.h>
|
||||
#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);
|
||||
}
|
@ -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);
|
||||
|
@ -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));
|
||||
|
||||
|
41
sbin/sysinstall/utils.c
Normal file
41
sbin/sysinstall/utils.c
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "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 <dialog.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user