install.c revision 8351
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.11 1995/05/08 06:06:25 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	partition_disks();
90
91	if (!write_disks()) {
92	    int scroll, choice, curr, max;
93
94	    make_filesystems();
95	    scroll = choice = curr = max = 0;
96	    dmenuOpen(&MenuInstall, &choice, &scroll, &curr, &max);
97	    cpio_extract();
98	    extract_dists();
99	    install_configuration_files();
100	    do_final_setup();
101	    SystemWasInstalled = TRUE;
102	    break;
103	}
104	else {
105	    dialog_clear();
106	    if (msgYesNo("Would you like to go back to the Master Partition Editor?")) {
107		for (i = 0; Disks[i]; i++)
108		    Free_Disk(Disks[i]);
109		break;
110	    }
111	}
112    }
113    return SystemWasInstalled;
114}
115
116int
117installCustom(char *str)
118{
119    int scroll, choice, curr, max;
120    extern DMenu MenuDiskDevices;
121    DMenu *menu;
122    Device *devs;
123
124    variable_set2("install_type", "custom");
125    menu = device_create_disk_menu(&MenuDiskDevices, &devs, installHook);
126    if (!menu)
127	return 0;
128    choice = scroll = curr = max = 0;
129    dmenuOpen(menu, &choice, &scroll, &curr, &max);
130    free(menu);
131    free(devs);
132    return SystemWasInstalled;
133}
134
135int
136installExpress(char *str)
137{
138    int scroll, choice, curr, max;
139    extern DMenu MenuDiskDevices;
140    DMenu *menu;
141    Device *devs;
142
143    variable_set2("install_type", "express");
144    menu = device_create_disk_menu(&MenuDiskDevices, &devs, installHook);
145    if (!menu)
146	return 0;
147    choice = scroll = curr = max = 0;
148    dmenuOpen(menu, &choice, &scroll, &curr, &max);
149    free(menu);
150    free(devs);
151    return SystemWasInstalled;
152}
153
154int
155installMaint(char *str)
156{
157    msgConfirm("Sorry, maintainance mode is not implemented in this version.");
158    return 0;
159}
160
161/* Go newfs and/or mount all the filesystems we've been asked to */
162void
163make_filesystems(void)
164{
165    int i;
166
167    command_clear();
168    for (i = 0; Disks[i]; i++) {
169	struct chunk *c1;
170
171	if (!Disks[i]->chunks)
172	    msgFatal("No chunk list found for %s!", Disks[i]->name);
173	c1 = Disks[i]->chunks->part;
174	while (c1) {
175	    if (c1->type == freebsd) {
176		struct chunk *c2 = c1->part;
177
178		while (c2) {
179		    if (c2->type == part && c2->subtype != FS_SWAP &&
180			c2->private) {
181			PartInfo *tmp = (PartInfo *)c2->private;
182
183			if (tmp->newfs)
184			    command_add(tmp->mountpoint,
185					"%s %s", tmp->newfs_cmd, c2->name);
186			command_add(tmp->mountpoint,
187				    "mkdir -p /mnt/%s", tmp->mountpoint);
188			command_add(tmp->mountpoint,
189				    "mount /mnt/dev/%s /mnt/%s", c2->name,
190				    tmp->mountpoint);
191		    }
192		    c2 = c2->next;
193		}
194	    }
195	    c1 = c1->next;
196	}
197    }
198    command_sort();
199    command_execute();
200}
201
202void
203cpio_extract(void)
204{
205    int i, j, zpid, cpid, pfd[2];
206
207    while (CpioFD == -1) {
208	msgConfirm("Please Insert CPIO floppy in floppy drive 0");
209	CpioFD = open("/dev/rfd0", O_RDONLY);
210    }
211    msgNotify("Extracting contents of CPIO floppy.");
212    pipe(pfd);
213    zpid = fork();
214    if (!zpid) {
215	close(0); dup(CpioFD); close(CpioFD);
216	close(1); dup(pfd[1]); close(pfd[1]);
217	close(pfd[0]);
218	i = execl("/stand/gunzip", "/stand/gunzip", 0);
219	msgDebug("/stand/gunzip command returns %d status\n", i);
220	exit(i);
221    }
222    cpid = fork();
223    if (!cpid) {
224	close(0); dup(pfd[0]); close(pfd[0]);
225	close(CpioFD);
226	close(pfd[1]);
227	close(1); open("/dev/null", O_WRONLY);
228	i = execl("/stand/cpio", "/stand/cpio", "-iduvm", 0);
229	msgDebug("/stand/cpio command returns %d status\n", i);
230	exit(i);
231    }
232    close(pfd[0]);
233    close(pfd[1]);
234    close(CpioFD);
235    i = wait(&j);
236    if (i < 0 || j)
237	msgFatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s",
238		 i, j, cpid, zpid, strerror(errno));
239    i = wait(&j);
240    if (i < 0 || j)
241	msgFatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s",
242		 i, j, cpid, zpid, strerror(errno));
243}
244
245void
246extract_dists(void)
247{
248}
249
250void
251install_configuration_files(void)
252{
253}
254
255void
256do_final_setup(void)
257{
258}
259
260