aboutsummaryrefslogtreecommitdiff
path: root/sbin/sysinstall/stage4.c
blob: 81222d0e3fd52f9b83e0e70149cfb1a98ac08630 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * ----------------------------------------------------------------------------
 * "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: stage4.c,v 1.9 1994/11/17 23:36:48 ache Exp $
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <dialog.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>
#include <sys/types.h>
#include <sys/wait.h>

#include "sysinstall.h"

void
stage4()
{
    int ffd, pfd[2];
    int zpid, cpid;
    int i,j;

    if (access("/stand/need_cpio_floppy",R_OK))
	return;
retry:
    while (1) {
	dialog_msgbox(TITLE, 
		      "Insert CPIO floppy in floppy drive 0", -1, -1, 1);
	ffd = open("/dev/fd0a",O_RDONLY);
	if (ffd > 0)
	    break;
    }
    dialog_clear_norefresh();
    TellEm("cd /stand ; gunzip < /dev/fd0 | cpio -idum");
    pipe(pfd);
    zpid = fork();
    if (!zpid) {
	close(0); dup(ffd); close(ffd);
	close(1); dup(pfd[1]); close(pfd[1]);
	close(pfd[0]);
	i = exec (1,"/stand/gunzip","/stand/gunzip", 0);
	exit(i);
    }
    cpid = fork();
    if (!cpid) {
	close(0); dup(pfd[0]); close(pfd[0]);
	close(ffd);
	close(pfd[1]);
	close(1); open("/dev/null",O_WRONLY);
	chdir("/stand");
	i = exec (1,"/stand/cpio","/stand/cpio","-iduvm", 0);
	exit(i);
    }
    close(pfd[0]);
    close(pfd[1]);
    close(ffd);
    i = wait(&j);
    if (i < 0 || j)
	Fatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s",
	      i, j, cpid, zpid, strerror(errno));
    i = wait(&j);
    if (i < 0 || j)
	Fatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s",
	      i, j, cpid, zpid, strerror(errno));
    
    /* bininst MUST be the last file on the floppy */
    if (access("/stand/bininst", R_OK) == -1) {
	AskAbort("CPIO floppy was bad!  Please check media for defects and retry.");
	goto retry;
    }
    else {
	TellEm("unlink /stand/need_cpio_floppy");
	unlink("/stand/need_cpio_floppy");
    }
}