install.c revision 8363
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
6 *
7 * $Id: install.c,v 1.12 1995/05/08 10:20:51 jkh Exp $
8 *
9 * Copyright (c) 1995
10 *	Jordan Hubbard.  All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer,
17 *    verbatim and that no modifications are made prior to this
18 *    point in the file.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 *    must display the following acknowledgement:
24 *	This product includes software developed by Jordan Hubbard
25 *	for the FreeBSD Project.
26 * 4. The name of Jordan Hubbard or the FreeBSD project may not be used to
27 *    endorse or promote products derived from this software without specific
28 *    prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 */
43
44#include "sysinstall.h"
45#include <sys/disklabel.h>
46#include <sys/errno.h>
47#include <sys/fcntl.h>
48#include <unistd.h>
49
50Boolean SystemWasInstalled;
51struct disk *Disks[100];	/* some ridiculously large number */
52
53static int
54installHook(char *str)
55{
56    int i;
57    extern DMenu MenuInstall;
58
59    i = 0;
60    /* Clip garbage off the ends */
61    string_prune(str);
62    str = string_skipwhite(str);
63    /* Try and open all the disks */
64    while (str) {
65	char *cp;
66
67	cp = index(str, '\n');
68	if (cp)
69	   *cp++ = 0;
70	if (!*str) {
71	    beep();
72	    return 0;
73	}
74	Disks[i] = Open_Disk(str);
75	if (!Disks[i])
76	    msgFatal("Unable to open disk %s!", str);
77	++i;
78	str = cp;
79    }
80    Disks[i] = NULL;
81    if (!i)
82	return 0;
83
84    while (1) {
85	/* Now go set up all the MBR partition information */
86	for (i = 0; Disks[i]; i++)
87	    Disks[i] = device_slice_disk(Disks[i]);
88
89	/* Whap partitions on all the FreeBSD slices created */
90	partition_disks();
91
92	/* Try and write it out */
93	if (!write_disks()) {
94	    int scroll, choice, curr, max;
95
96	    make_filesystems();
97	    scroll = choice = curr = max = 0;
98	    dmenuOpen(&MenuInstall, &choice, &scroll, &curr, &max);
99	    cpio_extract();
100	    distExtractAll();
101	    install_configuration_files();
102	    do_final_setup();
103	    SystemWasInstalled = TRUE;
104	    break;
105	}
106	else {
107	    dialog_clear();
108	    if (msgYesNo("Would you like to go back to the Master Partition Editor?")) {
109		for (i = 0; Disks[i]; i++)
110		    Free_Disk(Disks[i]);
111		break;
112	    }
113	}
114    }
115    return SystemWasInstalled;
116}
117
118int
119installCustom(char *str)
120{
121    int scroll, choice, curr, max;
122    extern DMenu MenuDiskDevices;
123    DMenu *menu;
124    Device *devs;
125
126    variable_set2("install_type", "custom");
127    menu = device_create_disk_menu(&MenuDiskDevices, &devs, installHook);
128    if (!menu)
129	return 0;
130    choice = scroll = curr = max = 0;
131    dmenuOpen(menu, &choice, &scroll, &curr, &max);
132    free(menu);
133    free(devs);
134    return SystemWasInstalled;
135}
136
137int
138installExpress(char *str)
139{
140    int scroll, choice, curr, max;
141    extern DMenu MenuDiskDevices;
142    DMenu *menu;
143    Device *devs;
144
145    variable_set2("install_type", "express");
146    menu = device_create_disk_menu(&MenuDiskDevices, &devs, installHook);
147    if (!menu)
148	return 0;
149    choice = scroll = curr = max = 0;
150    dmenuOpen(menu, &choice, &scroll, &curr, &max);
151    free(menu);
152    free(devs);
153    return SystemWasInstalled;
154}
155
156int
157installMaint(char *str)
158{
159    msgConfirm("Sorry, maintainance mode is not implemented in this version.");
160    return 0;
161}
162
163/* Go newfs and/or mount all the filesystems we've been asked to */
164void
165make_filesystems(void)
166{
167    int i;
168
169    command_clear();
170    for (i = 0; Disks[i]; i++) {
171	struct chunk *c1;
172
173	if (!Disks[i]->chunks)
174	    msgFatal("No chunk list found for %s!", Disks[i]->name);
175	c1 = Disks[i]->chunks->part;
176	while (c1) {
177	    if (c1->type == freebsd) {
178		struct chunk *c2 = c1->part;
179
180		while (c2) {
181		    if (c2->type == part && c2->subtype != FS_SWAP &&
182			c2->private) {
183			PartInfo *tmp = (PartInfo *)c2->private;
184
185			if (tmp->newfs)
186			    command_add(tmp->mountpoint,
187					"%s %s", tmp->newfs_cmd, c2->name);
188			command_add(tmp->mountpoint,
189				    "mkdir -p /mnt/%s", tmp->mountpoint);
190			command_add(tmp->mountpoint,
191				    "mount /mnt/dev/%s /mnt/%s", c2->name,
192				    tmp->mountpoint);
193		    }
194		    c2 = c2->next;
195		}
196	    }
197	    c1 = c1->next;
198	}
199    }
200    command_sort();
201    command_execute();
202}
203
204void
205cpio_extract(void)
206{
207    int i, j, zpid, cpid, pfd[2];
208
209    while (CpioFD == -1) {
210	msgConfirm("Please Insert CPIO floppy in floppy drive 0");
211	CpioFD = open("/dev/rfd0", O_RDONLY);
212    }
213    msgNotify("Extracting contents of CPIO floppy.");
214    pipe(pfd);
215    zpid = fork();
216    if (!zpid) {
217	close(0); dup(CpioFD); close(CpioFD);
218	close(1); dup(pfd[1]); close(pfd[1]);
219	close(pfd[0]);
220	i = execl("/stand/gunzip", "/stand/gunzip", 0);
221	msgDebug("/stand/gunzip command returns %d status\n", i);
222	exit(i);
223    }
224    cpid = fork();
225    if (!cpid) {
226	close(0); dup(pfd[0]); close(pfd[0]);
227	close(CpioFD);
228	close(pfd[1]);
229	close(1); open("/dev/null", O_WRONLY);
230	i = execl("/stand/cpio", "/stand/cpio", "-iduvm", 0);
231	msgDebug("/stand/cpio command returns %d status\n", i);
232	exit(i);
233    }
234    close(pfd[0]);
235    close(pfd[1]);
236    close(CpioFD);
237    i = wait(&j);
238    if (i < 0 || j)
239	msgFatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s",
240		 i, j, cpid, zpid, strerror(errno));
241    i = wait(&j);
242    if (i < 0 || j)
243	msgFatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s",
244		 i, j, cpid, zpid, strerror(errno));
245}
246
247void
248install_configuration_files(void)
249{
250}
251
252void
253do_final_setup(void)
254{
255}
256
257