]>
Commit | Line | Data |
---|---|---|
d6aaa55d MT |
1 | /* SmoothWall install program. |
2 | * | |
3 | * This program is distributed under the terms of the GNU General Public | |
4 | * Licence. See the file COPYING for details. | |
5 | * | |
6 | * (c) Lawrence Manning, 2001 | |
7 | * Contains main entry point, and misc functions. | |
8 | * | |
d6aaa55d | 9 | */ |
10bc6f06 | 10 | |
d6aaa55d | 11 | #include "install.h" |
72d80898 MT |
12 | #define _GNU_SOURCE |
13 | ||
d6aaa55d MT |
14 | #define CDROM_INSTALL 0 |
15 | #define URL_INSTALL 1 | |
72d80898 MT |
16 | #define DISK_INSTALL 2 |
17 | #define INST_FILECOUNT 6600 | |
18 | #define UNATTENDED_CONF "/cdrom/data/unattended.conf" | |
d6aaa55d MT |
19 | |
20 | int raid_disk = 0; | |
21 | FILE *flog = NULL; | |
22 | char *mylog; | |
10bc6f06 | 23 | |
d6aaa55d MT |
24 | char **ctr; |
25 | ||
26 | char *pcmcia = NULL; | |
27 | extern char url[STRING_SIZE]; | |
28 | ||
10bc6f06 | 29 | extern char *en_tr[]; |
10bc6f06 | 30 | extern char *de_tr[]; |
d6aaa55d | 31 | |
72d80898 MT |
32 | int detect_smp() { |
33 | FILE *fd = NULL; | |
34 | char line[STRING_SIZE]; | |
35 | int cpu_count = 0; | |
36 | ||
37 | if ((fd = fopen("/proc/cpuinfo", "r")) == NULL) { | |
38 | return 0; | |
39 | } | |
40 | while (fgets(line, STRING_SIZE, fd) != NULL) { | |
41 | if (strstr(line, "processor") == line) { | |
42 | cpu_count++; | |
43 | } | |
44 | } | |
45 | (void)fclose(fd); | |
46 | return (cpu_count > 1); | |
47 | } | |
48 | ||
49 | int generate_packages_list(char *packages, const char *rpmdir, const char *source) { | |
50 | ||
51 | FILE *fd=NULL; | |
52 | char buffer[STRING_SIZE]; | |
53 | bzero(buffer, sizeof(buffer)); | |
54 | ||
55 | if ((fd = fopen(source, "r")) == NULL) { | |
56 | (void) fprintf(flog, "Packages file %s not found\n", source); | |
57 | return -1; | |
58 | } | |
59 | while (fgets(buffer, sizeof(buffer), fd) != NULL) { | |
60 | int length = -1; | |
61 | length = strlen(buffer)-1; | |
62 | if (length<=0) { | |
63 | continue; | |
64 | } | |
65 | if (buffer[length] == '\n') { | |
66 | buffer[length]='\0'; | |
67 | } | |
68 | length = snprintf(packages, STRING_SIZE, "%s %s/%s", strdup(packages), rpmdir, buffer); | |
69 | if ((length <0) || (length >STRING_SIZE)) { | |
70 | (void) fprintf(flog, "rpm command line too long: %d\n%s", length, packages); | |
71 | return -1; | |
72 | } | |
73 | } | |
74 | if (ferror(fd)) { | |
75 | (void) fprintf(flog, "Error reading file\n"); | |
76 | (void) fclose(fd); | |
77 | return -1; | |
78 | } | |
79 | (void) fclose(fd); | |
80 | return 0; | |
81 | } | |
82 | ||
83 | long calc_swapsize(long memory, long disk) { | |
84 | if (memory < 128) { | |
85 | return 256; | |
86 | } | |
87 | if (memory > 1024) { | |
88 | return 512; | |
89 | } | |
90 | ||
91 | return memory*2; | |
92 | } | |
93 | ||
94 | int unattended_setup(struct keyvalue *unattendedkv) { | |
95 | struct keyvalue *mainsettings = initkeyvalues(); | |
96 | struct keyvalue *ethernetkv = initkeyvalues(); | |
97 | FILE *file, *hosts; | |
98 | char commandstring[STRING_SIZE]; | |
99 | ||
100 | char domainname[STRING_SIZE]; | |
101 | char hostname[STRING_SIZE]; | |
102 | char keymap[STRING_SIZE]; | |
103 | char language[STRING_SIZE]; | |
104 | char timezone[STRING_SIZE]; | |
105 | char green_address[STRING_SIZE]; | |
106 | char green_netmask[STRING_SIZE]; | |
107 | char green_netaddress[STRING_SIZE]; | |
108 | char green_broadcast[STRING_SIZE]; | |
109 | char root_password[STRING_SIZE]; | |
110 | char admin_password[STRING_SIZE]; | |
111 | char serial_console[STRING_SIZE]; | |
112 | char reversesort[STRING_SIZE]; | |
113 | ||
114 | findkey(unattendedkv, "DOMAINNAME", domainname); | |
115 | findkey(unattendedkv, "HOSTNAME", hostname); | |
116 | findkey(unattendedkv, "KEYMAP", keymap); | |
117 | findkey(unattendedkv, "LANGUAGE", language); | |
118 | findkey(unattendedkv, "TIMEZONE", timezone); | |
119 | findkey(unattendedkv, "GREEN_ADDRESS", green_address); | |
120 | findkey(unattendedkv, "GREEN_NETMASK", green_netmask); | |
121 | findkey(unattendedkv, "GREEN_NETADDRESS", green_netaddress); | |
122 | findkey(unattendedkv, "GREEN_BROADCAST", green_broadcast); | |
123 | findkey(unattendedkv, "ROOT_PASSWORD", root_password); | |
124 | findkey(unattendedkv, "ADMIN_PASSWORD", admin_password); | |
125 | findkey(unattendedkv, "SERIAL_CONSOLE", serial_console); | |
126 | findkey(unattendedkv, "REVERSE_NICS", reversesort); | |
127 | ||
128 | /* write main/settings. */ | |
129 | replacekeyvalue(mainsettings, "DOMAINNAME", domainname); | |
130 | replacekeyvalue(mainsettings, "HOSTNAME", hostname); | |
131 | replacekeyvalue(mainsettings, "KEYMAP", keymap); | |
132 | replacekeyvalue(mainsettings, "LANGUAGE", language); | |
133 | replacekeyvalue(mainsettings, "TIMEZONE", timezone); | |
134 | writekeyvalues(mainsettings, "/harddisk" CONFIG_ROOT "/main/settings"); | |
135 | freekeyvalues(mainsettings); | |
136 | ||
137 | /* do setup stuff */ | |
138 | fprintf(flog, "unattended: Starting setup\n"); | |
139 | ||
140 | /* network */ | |
141 | ||
142 | fprintf(flog, "unattended: setting up network configuration\n"); | |
143 | ||
144 | (void) readkeyvalues(ethernetkv, "/harddisk" CONFIG_ROOT "/ethernet/settings"); | |
145 | replacekeyvalue(ethernetkv, "GREEN_ADDRESS", green_address); | |
146 | replacekeyvalue(ethernetkv, "GREEN_NETMASK", green_netmask); | |
147 | replacekeyvalue(ethernetkv, "GREEN_NETADDRESS", green_netaddress); | |
148 | replacekeyvalue(ethernetkv, "GREEN_BROADCAST", green_broadcast); | |
149 | replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0"); | |
150 | replacekeyvalue(ethernetkv, "GREEN_DEV", "br0"); | |
151 | write_ethernet_configs(ethernetkv); | |
152 | freekeyvalues(ethernetkv); | |
153 | ||
154 | /* timezone */ | |
155 | unlink("/harddisk/etc/localtime"); | |
156 | snprintf(commandstring, STRING_SIZE, "/harddisk/%s", timezone); | |
157 | link(commandstring, "/harddisk/etc/localtime"); | |
158 | ||
159 | /* hostname */ | |
160 | fprintf(flog, "unattended: writing hostname.conf\n"); | |
161 | if (!(file = fopen("/harddisk" CONFIG_ROOT "/main/hostname.conf", "w"))) | |
162 | { | |
163 | errorbox("unattended: ERROR writing hostname.conf"); | |
164 | return 0; | |
165 | } | |
166 | fprintf(file, "ServerName %s\n", hostname); | |
167 | fclose(file); | |
168 | ||
169 | fprintf(flog, "unattended: writing hosts\n"); | |
170 | if (!(hosts = fopen("/harddisk/etc/hosts", "w"))) | |
171 | { | |
172 | errorbox("unattended: ERROR writing hosts"); | |
173 | return 0; | |
174 | } | |
175 | fprintf(hosts, "127.0.0.1\tlocalhost\n"); | |
176 | fprintf(hosts, "%s\t%s.%s\t%s\n", green_address, hostname, domainname, hostname); | |
177 | fclose(hosts); | |
178 | ||
179 | fprintf(flog, "unattended: writing hosts.allow\n"); | |
180 | if (!(file = fopen("/harddisk/etc/hosts.allow", "w"))) | |
181 | { | |
182 | errorbox("unattended: ERROR writing hosts.allow"); | |
183 | return 0; | |
184 | } | |
185 | fprintf(file, "sshd : ALL\n"); | |
186 | fprintf(file, "ALL : localhost\n"); | |
187 | fprintf(file, "ALL : %s/%s\n", green_netaddress, green_netmask); | |
188 | fclose(file); | |
189 | ||
190 | fprintf(flog, "unattended: writing hosts.deny\n"); | |
191 | if (!(file = fopen("/harddisk/etc/hosts.deny", "w"))) | |
192 | { | |
193 | errorbox("unattended: ERROR writing hosts.deny"); | |
194 | return 0; | |
195 | } | |
196 | fprintf(file, "ALL : ALL\n"); | |
197 | fclose(file); | |
198 | ||
199 | if (strcmp(serial_console, "yes") != 0) { | |
200 | snprintf(commandstring, STRING_SIZE, | |
201 | "/bin/chroot /harddisk /bin/sed -i -e \"s/^s0/#s0/\" /etc/inittab"); | |
202 | if (mysystem(commandstring)) { | |
203 | errorbox("unattended: ERROR modifying inittab"); | |
204 | return 0; | |
205 | } | |
206 | ||
207 | snprintf(commandstring, STRING_SIZE, | |
208 | "/bin/chroot /harddisk /bin/sed -i -e \"s/^serial/#serial/; s/^terminal/#terminal/\" /boot/grub/grub.conf"); | |
209 | if (mysystem(commandstring)) { | |
210 | errorbox("unattended: ERROR modifying inittab"); | |
211 | return 0; | |
212 | } | |
213 | } | |
214 | ||
215 | /* set reverse sorting of interfaces */ | |
216 | if (strcmp(reversesort, "yes") == 0) { | |
217 | mysystem("/bin/touch /harddisk/var/ipfire/ethernet/reverse_nics"); | |
218 | } | |
219 | ||
220 | /* set root password */ | |
221 | fprintf(flog, "unattended: setting root password\n"); | |
222 | ||
223 | snprintf(commandstring, STRING_SIZE, | |
224 | "/bin/chroot /harddisk /bin/sh -c \"echo 'root:%s' | /usr/sbin/chpasswd\"", root_password); | |
225 | if (mysystem(commandstring)) { | |
226 | errorbox("unattended: ERROR setting root password"); | |
227 | return 0; | |
228 | } | |
229 | ||
230 | /* set admin password */ | |
231 | fprintf(flog, "unattended: setting admin password\n"); | |
232 | snprintf(commandstring, STRING_SIZE, | |
233 | "/bin/chroot /harddisk /usr/bin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", admin_password); | |
234 | if (mysystem(commandstring)) { | |
235 | errorbox("unattended: ERROR setting admin password"); | |
236 | return 0; | |
237 | } | |
238 | ||
239 | return 1; | |
240 | } | |
241 | ||
d6aaa55d MT |
242 | int main(int argc, char *argv[]) |
243 | { | |
b4e3cd7f HS |
244 | char *langnames[] = { "Deutsch", "English", NULL }; |
245 | char *shortlangnames[] = { "de", "en", NULL }; | |
246 | char **langtrs[] = { de_tr, en_tr, NULL }; | |
d6aaa55d | 247 | char hdletter, cdletter; |
72d80898 MT |
248 | char harddrive[5], sourcedrive[5]; /* Device holder. */ |
249 | struct devparams hdparams, cdromparams; /* Params for CDROM and HD */ | |
250 | int cdmounted = 0; /* Loop flag for inserting a cd. */ | |
251 | int rc = 0; | |
d6aaa55d | 252 | char commandstring[STRING_SIZE]; |
10bc6f06 | 253 | char *installtypes[] = { "CDROM", "HTTP/FTP", NULL }; |
72d80898 | 254 | int installtype = CDROM_INSTALL; |
d6aaa55d MT |
255 | char insertmessage[STRING_SIZE]; |
256 | char insertdevnode[STRING_SIZE]; | |
257 | int choice; | |
258 | char shortlangname[10]; | |
259 | char message[1000]; | |
260 | char title[STRING_SIZE]; | |
261 | int allok = 0; | |
10bc6f06 | 262 | int allok_fastexit=0; |
d6aaa55d MT |
263 | int unmount_before=0; |
264 | struct keyvalue *ethernetkv = initkeyvalues(); | |
265 | FILE *handle, *cmdfile; | |
266 | char line[STRING_SIZE]; | |
267 | char string[STRING_SIZE]; | |
72d80898 MT |
268 | long maximum_free = 0, current_free; |
269 | long memory = 0; | |
270 | long log_partition, boot_partition, root_partition, swap_file; | |
d6aaa55d MT |
271 | int scsi_disk = 0; |
272 | int pcmcia_disk = 0; | |
273 | int pcmcia_cdrom = 0; | |
274 | int scsi_cdrom = 0; | |
275 | int ide_cdrom = 0; | |
276 | int fdisk = 0; | |
72d80898 MT |
277 | int hardyn = 0; |
278 | char *yesnoharddisk[] = { "NO", "YES", NULL }; | |
279 | char *yesno[] = { "NO", "YES", NULL }; | |
280 | char green[STRING_SIZE]; | |
281 | int unattended = 0; | |
282 | struct keyvalue *unattendedkv = initkeyvalues(); | |
283 | char packages[STRING_SIZE]; | |
284 | int serial_console = 0; | |
285 | char megabridge[STRING_SIZE]; | |
d6aaa55d MT |
286 | |
287 | setlocale (LC_ALL, ""); | |
10bc6f06 | 288 | sethostname( SNAME , 10); |
72d80898 | 289 | |
d6aaa55d MT |
290 | memset(&hdparams, 0, sizeof(struct devparams)); |
291 | memset(&cdromparams, 0, sizeof(struct devparams)); | |
292 | ||
293 | /* Log file/terminal stuff. */ | |
294 | if (argc >= 2) | |
295 | { | |
296 | if (!(flog = fopen(argv[1], "w+"))) | |
297 | return 0; | |
298 | } | |
299 | else | |
300 | return 0; | |
301 | ||
302 | mylog = argv[1]; | |
303 | ||
304 | fprintf(flog, "Install program started.\n"); | |
305 | ||
306 | newtInit(); | |
307 | newtCls(); | |
308 | ||
309 | /* Do usb detection first for usb keyboard */ | |
310 | if (! (cmdfile = fopen("/proc/cmdline", "r"))) | |
311 | { | |
312 | fprintf(flog, "Couldn't open commandline: /proc/cmdline\n"); | |
313 | } else { | |
314 | fgets(line, STRING_SIZE, cmdfile); | |
315 | if (strstr (line, "fdisk") != NULL) { | |
316 | fprintf(flog, "Manual FDISK selected.\n"); | |
317 | fdisk = 1; | |
318 | } | |
319 | if (strstr (line, "nopcmcia") == NULL) { | |
320 | fprintf(flog, "Initializing PCMCIA controllers.\n"); | |
321 | pcmcia = initialize_pcmcia(); | |
322 | if (pcmcia) { | |
323 | fprintf (flog, "Detected PCMCIA Controller: %s.\n", pcmcia); | |
324 | sprintf(commandstring, "/sbin/modprobe %s", pcmcia); | |
325 | mysystem("/sbin/modprobe pcmcia_core"); | |
326 | mysystem(commandstring); | |
327 | mysystem("/sbin/modprobe ds"); | |
328 | /* pcmcia netcard drivers are not available from Boot floppy, | |
329 | * they will be loaded from Drivers floppy later */ | |
330 | } else { | |
331 | fprintf (flog, "Detected No PCMCIA Controller.\n"); | |
332 | } | |
333 | } else { | |
334 | fprintf(flog, "Skipping PCMCIA detection.\n"); | |
335 | } | |
336 | if (strstr (line, "nousb") == NULL) { | |
337 | fprintf(flog, "Initializing USB controllers.\n"); | |
338 | initialize_usb(); | |
339 | } else { | |
340 | fprintf(flog, "Skipping USB detection.\n"); | |
341 | } | |
72d80898 MT |
342 | // check if we have to make an unattended install |
343 | if (strstr (line, "unattended") != NULL) { | |
344 | unattended = 1; | |
345 | } | |
d6aaa55d | 346 | } |
72d80898 MT |
347 | |
348 | // make some beeps before wiping the system :) | |
349 | if (unattended) { | |
350 | runcommandwithstatus("/bin/beep -f 450 -r 10 -D 800 -n -f 900 -l 1000", "WARNING: Unattended installation will start in 10 seconds..."); | |
351 | } | |
d6aaa55d | 352 | |
72d80898 | 353 | /* German is the default */ |
d6aaa55d MT |
354 | for (choice = 0; langnames[choice]; choice++) |
355 | { | |
b4e3cd7f | 356 | if (strcmp(langnames[choice], "Deutsch") == 0) |
d6aaa55d MT |
357 | break; |
358 | } | |
359 | if (!langnames[choice]) | |
360 | goto EXIT; | |
361 | ||
72d80898 MT |
362 | if (!unattended) { |
363 | rc = newtWinMenu("Language selection", | |
364 | "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8, | |
365 | langnames, &choice, "Ok", NULL); | |
366 | } | |
367 | ||
d6aaa55d MT |
368 | ctr = langtrs[choice]; |
369 | strcpy(shortlangname, shortlangnames[choice]); | |
3d6e1202 MT |
370 | |
371 | mysystem("/bin/setfont lat0-16"); | |
72d80898 | 372 | |
d6aaa55d MT |
373 | newtDrawRootText(14, 0, NAME " v" VERSION " - " SLOGAN ); |
374 | newtPushHelpLine(ctr[TR_HELPLINE]); | |
375 | ||
72d80898 MT |
376 | if (!unattended) { |
377 | sprintf(message, ctr[TR_WELCOME], NAME); | |
378 | sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN); | |
379 | newtWinMessage(title, ctr[TR_OK], message); | |
380 | ||
381 | sprintf(message, ctr[TR_SELECT_INSTALLATION_MEDIA_LONG], NAME); | |
382 | rc = newtWinMenu(ctr[TR_SELECT_INSTALLATION_MEDIA], message, | |
383 | 50, 5, 5, 6, installtypes, &installtype, ctr[TR_OK], | |
384 | ctr[TR_CANCEL], NULL); | |
385 | } | |
386 | else { | |
387 | rc = 1; | |
388 | installtype = CDROM_INSTALL; | |
389 | } | |
390 | ||
391 | if (rc == 2) | |
392 | goto EXIT; | |
393 | ||
394 | // Starting hardware detection | |
395 | runcommandwithstatus("/bin/probehw.sh", ctr[TR_PROBING_HARDWARE]); | |
396 | ||
397 | switch (mysystem("/bin/mountsource.sh")) { | |
398 | case 0: | |
399 | installtype = CDROM_INSTALL; | |
400 | cdmounted = 1; | |
401 | break; | |
402 | case 1: | |
403 | installtype = DISK_INSTALL; | |
404 | break; | |
405 | case 10: | |
406 | errorbox(ctr[TR_NO_CDROM]); | |
407 | goto EXIT; | |
408 | } | |
409 | ||
410 | /* read source drive letter */ | |
411 | if ((handle = fopen("/source_device", "r")) == NULL) { | |
412 | errorbox("ERROR reading source_device"); | |
413 | } | |
414 | fgets(sourcedrive, 5, handle); | |
415 | fprintf(flog, "Source drive: %s\n", sourcedrive); | |
416 | fclose(handle); | |
417 | ||
418 | if (installtype == CDROM_INSTALL) { | |
419 | snprintf(cdromparams.devnode, STRING_SIZE, "/dev/%s", sourcedrive); | |
420 | cdromparams.module = 0; | |
421 | fprintf(flog, "Source device: %s\n", cdromparams.devnode); | |
422 | } | |
423 | ||
424 | /* Get device for the HD. This has to succeed. */ | |
425 | if (!(hdletter = findidetype(IDE_HD))) | |
426 | { | |
427 | /* Need to clean this up at some point */ | |
428 | if (!try_scsi("sda") || strstr(sourcedrive, "sda") != NULL) { | |
429 | if (!try_scsi("ida/c0d0")) { | |
430 | if (!try_scsi("cciss/c0d0")) { | |
431 | if (!try_scsi("rd/c0d0")) { | |
432 | if (!try_scsi("ataraid/d0")) { | |
433 | errorbox(ctr[TR_NO_HARDDISK]); | |
434 | goto EXIT; | |
435 | } else { | |
436 | raid_disk = 1; | |
437 | sprintf(harddrive, "ataraid/d0"); | |
438 | } | |
439 | } else { | |
440 | raid_disk = 1; | |
441 | sprintf(harddrive, "rd/c0d0"); | |
442 | } | |
443 | } else { | |
444 | raid_disk = 1; | |
445 | sprintf(harddrive, "cciss/c0d0"); | |
446 | } | |
447 | } else { | |
448 | raid_disk = 1; | |
449 | sprintf(harddrive, "ida/c0d0"); | |
450 | } | |
451 | } else { | |
452 | if (strstr(sourcedrive, "sda") != NULL) { | |
453 | // probably installing from usb stick, try sdb | |
454 | if (try_scsi("sdb")) { | |
455 | sprintf(harddrive, "sdb"); | |
456 | } | |
457 | else { | |
458 | errorbox(ctr[TR_NO_HARDDISK]); | |
459 | goto EXIT; | |
460 | } | |
461 | } | |
462 | else { | |
463 | sprintf(harddrive, "sda"); | |
464 | } | |
465 | } | |
466 | scsi_disk = 1; | |
467 | } else | |
468 | sprintf(harddrive, "hd%c", hdletter); | |
469 | ||
d6aaa55d | 470 | |
72d80898 MT |
471 | /* load unattended configuration */ |
472 | if (unattended) { | |
473 | fprintf(flog, "unattended: Reading unattended.conf\n"); | |
474 | ||
475 | (void) readkeyvalues(unattendedkv, UNATTENDED_CONF); | |
476 | } | |
477 | ||
478 | /* Make the hdparms struct and print the contents. */ | |
479 | snprintf(hdparams.devnode, STRING_SIZE, "/dev/%s", harddrive); | |
480 | hdparams.module = 0; | |
481 | ||
482 | sprintf(message, ctr[TR_PREPARE_HARDDISK], hdparams.devnode); | |
483 | ||
484 | if (unattended) { | |
485 | hardyn = 1; | |
486 | } | |
487 | ||
488 | while (! hardyn) { | |
489 | rc = newtWinMenu(title, message, | |
490 | 50, 5, 5, 6, yesnoharddisk, | |
491 | &hardyn, ctr[TR_OK], | |
492 | ctr[TR_CANCEL], NULL); | |
493 | if (rc == 2) | |
494 | goto EXIT; | |
495 | } | |
5433e2c9 MT |
496 | |
497 | if (rc == 2) | |
498 | goto EXIT; | |
72d80898 MT |
499 | |
500 | /* Calculate amount of memory in machine */ | |
501 | if ((handle = fopen("/proc/meminfo", "r"))) | |
502 | { | |
503 | while (fgets(line, STRING_SIZE-1, handle)) { | |
504 | if (sscanf (line, "MemTotal: %s kB", string)) { | |
505 | memory = atoi(string) / 1024 ; | |
506 | } | |
507 | } | |
508 | fclose(handle); | |
509 | } | |
510 | ||
511 | /* Partition, mkswp, mkfs. | |
512 | * before partitioning, first determine the sizes of each | |
513 | * partition. In order to do that we need to know the size of | |
514 | * the disk. | |
515 | */ | |
516 | /* Don't use mysystem here so we can redirect output */ | |
517 | sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /disksize 2> /dev/null", harddrive); | |
518 | system(commandstring); | |
519 | ||
520 | /* Calculate amount of disk space */ | |
521 | if ((handle = fopen("/disksize", "r"))) | |
522 | { | |
523 | fgets(line, STRING_SIZE-1, handle); | |
524 | if (sscanf (line, "%s", string)) { | |
525 | maximum_free = atoi(string) / 1024; | |
526 | } | |
527 | fclose(handle); | |
528 | } | |
529 | ||
530 | fprintf(flog, "maximum_free = %ld, memory = %ld", | |
531 | maximum_free, memory); | |
532 | ||
533 | swap_file = calc_swapsize(memory, maximum_free); | |
534 | ||
535 | if (maximum_free < 512 + swap_file ) { | |
536 | if (maximum_free < 512) { | |
537 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
538 | goto EXIT; | |
539 | } | |
540 | ||
541 | if (!unattended) { | |
542 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]); | |
543 | } | |
544 | else { | |
545 | rc = 1; | |
546 | } | |
547 | ||
548 | if (rc != 1) | |
549 | goto EXIT; | |
550 | swap_file = 0; | |
551 | } | |
552 | ||
553 | boot_partition = 10; /* in MB */ | |
554 | current_free = maximum_free - boot_partition - swap_file; | |
555 | ||
556 | root_partition = current_free / 3 ; | |
557 | if (current_free < 400) { | |
558 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
559 | goto EXIT; | |
560 | } | |
561 | ||
562 | current_free = current_free - root_partition; | |
563 | if (!swap_file) { | |
564 | root_partition = root_partition + swap_file; | |
565 | } | |
566 | ||
567 | log_partition = current_free; | |
568 | ||
569 | fprintf(flog, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n", | |
570 | boot_partition, swap_file, log_partition, root_partition); | |
571 | ||
572 | handle = fopen("/tmp/partitiontable", "w"); | |
573 | ||
574 | ||
575 | /* Make swapfile */ | |
576 | if (swap_file) { | |
577 | fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n", | |
578 | boot_partition, swap_file, root_partition); | |
579 | } else { | |
580 | fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n", | |
581 | boot_partition, root_partition); | |
582 | } | |
583 | ||
584 | fclose(handle); | |
585 | ||
586 | snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams.devnode); | |
587 | if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK])) | |
588 | { | |
589 | errorbox(ctr[TR_UNABLE_TO_PARTITION]); | |
590 | goto EXIT; | |
591 | } | |
592 | ||
593 | mysystem("/bin/udevstart"); | |
594 | ||
595 | if (raid_disk) | |
596 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext3 -c %sp1", hdparams.devnode); | |
597 | else | |
598 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext3 -c %s1", hdparams.devnode); | |
599 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM])) | |
600 | { | |
601 | errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]); | |
602 | goto EXIT; | |
603 | } | |
604 | ||
605 | if (swap_file) { | |
606 | if (raid_disk) | |
607 | snprintf(commandstring, STRING_SIZE, "/bin/mkswap %sp2", hdparams.devnode); | |
608 | else | |
609 | snprintf(commandstring, STRING_SIZE, "/bin/mkswap %s2", hdparams.devnode); | |
610 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE])) | |
611 | { | |
612 | errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]); | |
613 | goto EXIT; | |
614 | } | |
615 | } | |
616 | ||
617 | if (raid_disk) | |
618 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext3 %sp3", hdparams.devnode); | |
619 | else | |
620 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext3 %s3", hdparams.devnode); | |
621 | ||
622 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM])) | |
623 | { | |
624 | errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]); | |
625 | goto EXIT; | |
626 | } | |
627 | ||
628 | if (raid_disk) | |
629 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext3 %sp4", hdparams.devnode); | |
630 | else | |
631 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext3 %s4", hdparams.devnode); | |
632 | ||
633 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM])) | |
634 | { | |
635 | errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]); | |
636 | goto EXIT; | |
637 | } | |
638 | ||
639 | /* Mount harddisk. */ | |
640 | if (raid_disk) | |
641 | snprintf(commandstring, STRING_SIZE, "/sbin/mount %sp3 /harddisk", hdparams.devnode); | |
642 | else | |
643 | snprintf(commandstring, STRING_SIZE, "/sbin/mount %s3 /harddisk", hdparams.devnode); | |
644 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM])) | |
645 | { | |
646 | errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]); | |
647 | goto EXIT; | |
648 | } | |
649 | ||
650 | mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO); | |
651 | mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO); | |
652 | mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO); | |
653 | ||
654 | if (raid_disk) | |
655 | snprintf(commandstring, STRING_SIZE, "/sbin/mount %sp1 /harddisk/boot", hdparams.devnode); | |
656 | else | |
657 | snprintf(commandstring, STRING_SIZE, "/sbin/mount %s1 /harddisk/boot", hdparams.devnode); | |
658 | ||
659 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM])) | |
660 | { | |
661 | errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]); | |
662 | goto EXIT; | |
663 | } | |
664 | if (swap_file) { | |
665 | if (raid_disk) | |
666 | snprintf(commandstring, STRING_SIZE, "/bin/swapon %sp2", hdparams.devnode); | |
667 | else | |
668 | snprintf(commandstring, STRING_SIZE, "/bin/swapon %s2", hdparams.devnode); | |
669 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION])) | |
670 | { | |
671 | errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]); | |
672 | goto EXIT; | |
673 | } | |
674 | } | |
675 | if (raid_disk) | |
676 | snprintf(commandstring, STRING_SIZE, "/sbin/mount %sp4 /harddisk/var", hdparams.devnode); | |
677 | else | |
678 | snprintf(commandstring, STRING_SIZE, "/sbin/mount %s4 /harddisk/var", hdparams.devnode); | |
679 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM])) | |
680 | { | |
681 | errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]); | |
682 | goto EXIT; | |
683 | } | |
684 | ||
685 | ||
686 | ||
10bc6f06 MT |
687 | if (installtype == CDROM_INSTALL) |
688 | { | |
689 | /* First look for an IDE CDROM. */ | |
690 | if (!(cdletter = findidetype(IDE_CDROM))) | |
d6aaa55d | 691 | { |
10bc6f06 MT |
692 | /* If we have a USB attached CDROM then it will |
693 | * have already appeared at /dev/scd0, so we | |
694 | * try to access it first, before asking for the | |
695 | * SCSI drivers disk. | |
696 | */ | |
697 | if (!(try_scsi("scd0"))) { | |
698 | sprintf(insertmessage, ctr[TR_INSERT_FLOPPY], NAME" SCSI"); | |
699 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage); | |
700 | if (rc != 1) | |
701 | { | |
702 | errorbox(ctr[TR_INSTALLATION_CANCELED]); | |
703 | goto EXIT; | |
704 | } | |
705 | ||
706 | if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr[TR_EXTRACTING_MODULES])) | |
707 | { | |
708 | errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); | |
709 | goto EXIT; | |
710 | } | |
711 | ||
712 | if (pcmcia) | |
713 | { | |
714 | /* trying to support SCSI pcmcia :-) */ | |
715 | runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi", | |
716 | ctr[TR_LOADING_PCMCIA]); | |
717 | if (try_scsi("scd0")) | |
718 | pcmcia_cdrom = 1; | |
719 | } | |
720 | ||
721 | /* try loading all SCSI modules with default options */ | |
722 | /* Should expand this to allow options later though */ | |
723 | if (!pcmcia_cdrom) | |
72d80898 MT |
724 | runcommandwithstatus("/bin/probehw.sh", |
725 | ctr[TR_PROBING_HARDWARE]); | |
10bc6f06 MT |
726 | |
727 | /* If it fails, give up. */ | |
728 | if (!(try_scsi("scd0"))) { | |
729 | errorbox(ctr[TR_NO_CDROM]); | |
730 | goto EXIT; | |
731 | } | |
d6aaa55d | 732 | } |
d6aaa55d | 733 | |
72d80898 | 734 | sprintf(sourcedrive, "scd0"); |
d6aaa55d | 735 | scsi_cdrom = 1; |
10bc6f06 | 736 | } else { |
72d80898 | 737 | sprintf(sourcedrive, "hd%c", cdletter); |
10bc6f06 | 738 | ide_cdrom = 1; |
d6aaa55d MT |
739 | } |
740 | ||
72d80898 | 741 | snprintf(cdromparams.devnode, STRING_SIZE, "/dev/%s", sourcedrive); |
10bc6f06 MT |
742 | cdromparams.module = 0; |
743 | ||
744 | sprintf(insertmessage, ctr[TR_INSERT_CDROM], NAME); | |
745 | strcpy (insertdevnode, cdromparams.devnode); | |
d6aaa55d | 746 | } |
10bc6f06 | 747 | else |
d6aaa55d MT |
748 | { |
749 | /* If we've done a PXE boot, we can skip the Drivers floppy, | |
750 | * as we've already got the modules in our instroot.gz */ | |
751 | if (!(handle = fopen("/CDROMBOOT", "r"))) { | |
10bc6f06 | 752 | sprintf(insertmessage, ctr[TR_INSERT_FLOPPY], NAME); |
d6aaa55d MT |
753 | strcpy (insertdevnode , "/dev/floppy"); |
754 | } else { | |
755 | fclose(handle); | |
756 | cdmounted = 1; | |
757 | unmount_before = 1; | |
758 | } | |
759 | } | |
760 | ||
10bc6f06 MT |
761 | if (scsi_cdrom || ide_cdrom) { |
762 | /* Try to mount /cdrom in a loop. */ | |
d6aaa55d | 763 | snprintf(commandstring, STRING_SIZE, "/bin/mount -o ro %s /cdrom", insertdevnode); |
d6aaa55d MT |
764 | while (!cdmounted) |
765 | { | |
10bc6f06 MT |
766 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage); |
767 | if (rc != 1) | |
768 | { | |
d6aaa55d MT |
769 | errorbox(ctr[TR_INSTALLATION_CANCELED]); |
770 | goto EXIT; | |
d6aaa55d | 771 | } |
10bc6f06 MT |
772 | if (!(mysystem(commandstring))) { |
773 | handle = fopen ("/cdrom/" SNAME "-" VERSION ".tgz", "r"); | |
774 | if (handle != NULL) { | |
775 | fclose (handle); | |
776 | cdmounted = 1; | |
777 | /* If we've booted from CDROM, then | |
778 | * we've already got the drivers, | |
779 | * so we can skip this unpack. */ | |
780 | if (!(handle = fopen("/CDROMBOOT", "r"))) { | |
781 | sprintf(string, "/bin/tar -C / -xvzf /cdrom/images/drivers-%s.img", VERSION); | |
782 | if (runcommandwithprogress(60, 4, title, | |
783 | string, | |
784 | 175, ctr[TR_EXTRACTING_MODULES])) | |
785 | { | |
786 | errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); | |
787 | ||
788 | goto EXIT; | |
789 | } | |
790 | } else | |
791 | fclose(handle); | |
792 | } else { | |
793 | mysystem ("/bin/umount /cdrom"); | |
794 | } | |
d6aaa55d MT |
795 | } |
796 | } | |
10bc6f06 MT |
797 | } else { |
798 | snprintf(commandstring, STRING_SIZE, "/bin/tar -C / -xvzf /dev/floppy"); | |
d6aaa55d MT |
799 | while (!cdmounted) |
800 | { | |
801 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage); | |
802 | if (rc != 1) | |
803 | { | |
804 | errorbox(ctr[TR_INSTALLATION_CANCELED]); | |
805 | goto EXIT; | |
806 | } | |
807 | if (runcommandwithprogress(60, 4, title, | |
808 | commandstring, | |
809 | 175, ctr[TR_EXTRACTING_MODULES])) | |
810 | { | |
811 | #if 0 /* disable this, so we allow for people putting in the wrong disk */ | |
812 | errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); | |
813 | goto EXIT; | |
814 | #endif | |
815 | } | |
816 | else | |
817 | { | |
818 | handle = fopen ("/bin/mke2fs", "r"); | |
819 | if (handle != NULL) { | |
820 | fclose (handle); | |
821 | cdmounted = 1; | |
822 | } | |
823 | } | |
824 | } | |
825 | } | |
826 | ||
827 | /* PCMCIA controller is already detected | |
828 | * On Boot floppy, we didn't have the PCMCIA drivers | |
829 | * so load them now because they are installed from Drivers. */ | |
830 | if (!(handle = fopen("/CDROMBOOT", "r"))) { | |
831 | if (strstr (line, "nopcmcia") == NULL) { | |
832 | fprintf(flog,"Floppy boot detected, loading PCMCIA drivers.\n"); | |
833 | if (pcmcia) { | |
834 | fprintf (flog, "Detected PCMCIA Controller: %s.\n", pcmcia); | |
835 | sprintf(commandstring, "/sbin/modprobe %s", pcmcia); | |
836 | mysystem("/sbin/modprobe pcmcia_core"); | |
837 | mysystem(commandstring); | |
838 | mysystem("/sbin/modprobe ds"); | |
839 | } else { | |
840 | fprintf (flog, "Detected No PCMCIA Controller.\n"); | |
841 | } | |
842 | } else { | |
843 | fprintf(flog, "Skipping PCMCIA detection.\n"); | |
844 | } | |
845 | if (strstr (line, "nousb") == NULL) { | |
846 | fprintf(flog, "Initializing USB controllers.\n"); | |
847 | initialize_usb(); | |
848 | } else { | |
849 | fprintf(flog, "Skipping USB detection.\n"); | |
850 | } | |
851 | } else | |
852 | fclose(handle); | |
853 | ||
854 | /* Configure the network now! */ | |
855 | if (installtype == URL_INSTALL) | |
856 | { | |
857 | /* Network driver and params. */ | |
858 | if (!(networkmenu(ethernetkv))) | |
859 | { | |
860 | errorbox(ctr[TR_NETWORK_SETUP_FAILED]); | |
861 | goto EXIT; | |
862 | } | |
863 | ||
e57bc1fd | 864 | /* Check for ipfire-<VERSION>.tgz */ |
d6aaa55d MT |
865 | if (!(checktarball(SNAME "-" VERSION ".tgz"))) |
866 | { | |
867 | errorbox(ctr[TR_NO_IPCOP_TARBALL_FOUND]); | |
868 | goto EXIT; | |
869 | } | |
870 | } | |
871 | ||
872 | /* Get device for the HD. This has to succeed. */ | |
10bc6f06 | 873 | if (!(hdletter = findidetype(IDE_HD))) |
d6aaa55d | 874 | { |
10bc6f06 | 875 | if (installtype == URL_INSTALL) |
d6aaa55d | 876 | { |
10bc6f06 MT |
877 | /* If we've done a PXE boot, we can skip the SCSI |
878 | * floppy as we've already got the modules in our | |
879 | * instroot.gz */ | |
880 | if (!(handle = fopen("/CDROMBOOT", "r"))) | |
d6aaa55d | 881 | { |
10bc6f06 MT |
882 | /* search img where it is on a mounted loop iso */ |
883 | sprintf(string, "images/scsidrv-%s.img", VERSION); | |
884 | if (!(checktarball(string))) | |
d6aaa55d | 885 | { |
10bc6f06 MT |
886 | /* Couldn't find the SCSI drivers on the URL page, |
887 | * so after 3 failed attempts, ask the user for the | |
888 | * SCSI drivers floppy disk. */ | |
889 | errorbox(ctr[TR_NO_SCSI_IMAGE_FOUND]); | |
890 | sprintf(insertmessage, ctr[TR_INSERT_FLOPPY], NAME" SCSI"); | |
891 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], insertmessage); | |
892 | if (rc != 1) | |
893 | { | |
894 | errorbox(ctr[TR_INSTALLATION_CANCELED]); | |
895 | goto EXIT; | |
896 | } | |
897 | ||
898 | if (runcommandwithstatus("/bin/tar -C / -xvzf /dev/floppy", ctr[TR_EXTRACTING_MODULES])) | |
899 | { | |
900 | errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); | |
901 | goto EXIT; | |
902 | } | |
903 | } else { | |
904 | /* unpack... */ | |
905 | snprintf(commandstring, STRING_SIZE, | |
906 | "/bin/wget -O - %s/%s | /bin/tar -C / -xvzf -", | |
907 | url, string); | |
908 | if (runcommandwithprogress(60, 4, title, commandstring, | |
909 | 4500, ctr[TR_INSTALLING_FILES])) | |
910 | { | |
911 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
912 | goto EXIT; | |
913 | } | |
d6aaa55d | 914 | } |
10bc6f06 MT |
915 | } else |
916 | fclose(handle); | |
917 | } else { | |
918 | if (ide_cdrom) { | |
919 | sprintf(string, "/bin/tar -C / -xvzf /cdrom/images/scsidrv-%s.img", VERSION); | |
920 | if (runcommandwithstatus(string, ctr[TR_EXTRACTING_MODULES])) | |
d6aaa55d MT |
921 | { |
922 | errorbox(ctr[TR_UNABLE_TO_EXTRACT_MODULES]); | |
923 | goto EXIT; | |
924 | } | |
d6aaa55d MT |
925 | } |
926 | } | |
d6aaa55d | 927 | |
10bc6f06 MT |
928 | if (!scsi_cdrom) { |
929 | ||
d6aaa55d | 930 | #if 0 /* not yet */ |
10bc6f06 MT |
931 | if (pcmcia) |
932 | { | |
933 | /* trying to support SCSI pcmcia :-) */ | |
934 | runcommandwithstatus("cardmgr -o -c /etc/pcmcia/scsi", | |
935 | ctr[TR_LOADING_PCMCIA]); | |
936 | if (try_scsi("sda")) | |
937 | pcmcia_disk = 1; | |
d6aaa55d | 938 | } |
10bc6f06 MT |
939 | #endif |
940 | ||
941 | /* try loading all SCSI modules with default options */ | |
942 | /* Should expand this to allow options later though */ | |
943 | if (!pcmcia_disk) | |
72d80898 MT |
944 | runcommandwithstatus("/bin/probehw.sh", |
945 | ctr[TR_PROBING_HARDWARE]); | |
10bc6f06 MT |
946 | } |
947 | ||
948 | /* Need to clean this up at some point */ | |
949 | if (!try_scsi("sda")) { | |
950 | if (!try_scsi("ida/c0d0")) { | |
951 | if (!try_scsi("cciss/c0d0")) { | |
952 | if (!try_scsi("rd/c0d0")) { | |
953 | if (!try_scsi("ataraid/d0")) { | |
954 | errorbox(ctr[TR_NO_HARDDISK]); | |
955 | goto EXIT; | |
956 | } else { | |
957 | raid_disk = 1; | |
958 | sprintf(harddrive, "ataraid/d0"); | |
959 | } | |
960 | } else { | |
961 | raid_disk = 1; | |
962 | sprintf(harddrive, "rd/c0d0"); | |
963 | } | |
964 | } else { | |
965 | raid_disk = 1; | |
966 | sprintf(harddrive, "cciss/c0d0"); | |
967 | } | |
968 | } else { | |
969 | raid_disk = 1; | |
970 | sprintf(harddrive, "ida/c0d0"); | |
d6aaa55d | 971 | } |
10bc6f06 MT |
972 | } else { |
973 | sprintf(harddrive, "sda"); | |
d6aaa55d | 974 | } |
d6aaa55d | 975 | scsi_disk = 1; |
10bc6f06 MT |
976 | } else |
977 | sprintf(harddrive, "hd%c", hdletter); | |
978 | ||
979 | /* Make the hdparms struct and print the contents. */ | |
980 | snprintf(hdparams.devnode, STRING_SIZE, "/dev/%s", harddrive); | |
981 | hdparams.module = 0; | |
d6aaa55d MT |
982 | |
983 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], | |
10bc6f06 | 984 | ctr[TR_PREPARE_HARDDISK], hdparams.devnode); |
d6aaa55d MT |
985 | if (rc != 1) |
986 | goto EXIT; | |
987 | ||
988 | /* Calculate amount of memory in machine */ | |
989 | if ((handle = fopen("/proc/meminfo", "r"))) | |
990 | { | |
991 | while (fgets(line, STRING_SIZE-1, handle)) { | |
992 | if (sscanf (line, "MemTotal: %s kB", string)) { | |
993 | memory = atoi(string) / 1024 ; | |
994 | } | |
995 | } | |
996 | fclose(handle); | |
997 | } | |
998 | ||
999 | /* Partition, mkswp, mkfs. | |
1000 | * before partitioning, first determine the sizes of each | |
1001 | * partition. In order to do that we need to know the size of | |
1002 | * the disk. | |
1003 | */ | |
1004 | /* Don't use mysystem here so we can redirect output */ | |
1005 | sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /disksize 2> /dev/null", harddrive); | |
1006 | system(commandstring); | |
1007 | ||
1008 | /* Calculate amount of disk space */ | |
1009 | if ((handle = fopen("/disksize", "r"))) | |
1010 | { | |
1011 | fgets(line, STRING_SIZE-1, handle); | |
1012 | if (sscanf (line, "%s", string)) { | |
1013 | maximum_free = atoi(string) / 1024; | |
1014 | } | |
1015 | fclose(handle); | |
1016 | } | |
1017 | ||
10bc6f06 MT |
1018 | fprintf(flog, "maximum_free = %d, memory = %d", |
1019 | maximum_free, memory); | |
d6aaa55d MT |
1020 | |
1021 | /* If you need more than this, you should really add physical memory */ | |
1022 | /* Minimum: 192 = 64 real + 128 swap */ | |
1023 | swap_file = memory < 64 ? 2 * memory : 192 - memory ; | |
1024 | swap_file = swap_file < 32 ? 32 : swap_file ; | |
1025 | ||
1026 | if (maximum_free < 135 + swap_file ) | |
1027 | { | |
1028 | if (maximum_free < 135) { | |
1029 | errorbox(ctr[TR_DISK_TOO_SMALL]); | |
1030 | goto EXIT; | |
1031 | } | |
1032 | ||
1033 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]); | |
1034 | if (rc != 1) | |
1035 | goto EXIT; | |
1036 | swap_file = 0; | |
1037 | } | |
1038 | ||
9badc9e9 | 1039 | boot_partition = 20; /* in MB */ |
d6aaa55d MT |
1040 | current_free = maximum_free - boot_partition - swap_file; |
1041 | ||
1042 | /* Give more place for add-on, extend root to 25% of current_free, upper limit to 8 gigas */ | |
1043 | root_partition = current_free / 4 ; | |
1044 | root_partition = root_partition > 8192 ? 8192 : root_partition ; | |
1045 | root_partition = current_free < 860 ? 235 : root_partition; | |
1046 | root_partition = current_free < 380 ? 110 : root_partition; | |
1047 | ||
1048 | current_free = current_free - root_partition; | |
1049 | root_partition = root_partition + swap_file; | |
1050 | ||
1051 | log_partition = current_free; | |
1052 | ||
1053 | fprintf(flog, "boot = %d, swap = %d, mylog = %d, root = %d\n", | |
1054 | boot_partition, swap_file, log_partition, root_partition); | |
1055 | ||
10bc6f06 | 1056 | |
d6aaa55d MT |
1057 | #ifdef __alpha__ |
1058 | fdisk = 1; | |
1059 | #endif | |
1060 | ||
1061 | if (fdisk) { | |
1062 | rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], "NOW FDISK"); | |
1063 | if (rc != 1) | |
1064 | goto EXIT; | |
1065 | } else { | |
1066 | #ifdef __i386__ | |
1067 | handle = fopen("/tmp/partitiontable", "w"); | |
1068 | ||
1069 | fprintf(handle, ",%d,83,*\n,%d,83,\n,0,0,\n,,83,\n", | |
1070 | boot_partition, log_partition); | |
1071 | ||
1072 | fclose(handle); | |
1073 | ||
10bc6f06 | 1074 | snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -uM %s < /tmp/partitiontable", hdparams.devnode); |
d6aaa55d MT |
1075 | if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK])) |
1076 | { | |
1077 | errorbox(ctr[TR_UNABLE_TO_PARTITION]); | |
1078 | goto EXIT; | |
1079 | } | |
1080 | #endif | |
1081 | } | |
10bc6f06 MT |
1082 | |
1083 | if (raid_disk) | |
1084 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -m 0 -j %sp1", hdparams.devnode); | |
1085 | else | |
1086 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -m 0 -j %s1", hdparams.devnode); | |
d6aaa55d MT |
1087 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM])) |
1088 | { | |
1089 | errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]); | |
1090 | goto EXIT; | |
1091 | } | |
10bc6f06 MT |
1092 | if (raid_disk) |
1093 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -j %sp2", hdparams.devnode); | |
1094 | else | |
1095 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -j %s2", hdparams.devnode); | |
d6aaa55d MT |
1096 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM])) |
1097 | { | |
1098 | errorbox(ctr[TR_UNABLE_TO_MAKE_LOG_FILESYSTEM]); | |
1099 | goto EXIT; | |
1100 | } | |
10bc6f06 MT |
1101 | if (raid_disk) |
1102 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -m 1 -j %sp4", hdparams.devnode); | |
1103 | else | |
1104 | snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -m 1 -j %s4", hdparams.devnode); | |
d6aaa55d | 1105 | |
d6aaa55d MT |
1106 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM])) |
1107 | { | |
1108 | errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]); | |
1109 | goto EXIT; | |
1110 | } | |
10bc6f06 MT |
1111 | /* Mount harddisk. */ |
1112 | if (raid_disk) | |
1113 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %sp4 /harddisk", hdparams.devnode); | |
1114 | else | |
1115 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %s4 /harddisk", hdparams.devnode); | |
d6aaa55d MT |
1116 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM])) |
1117 | { | |
1118 | errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]); | |
1119 | goto EXIT; | |
1120 | } | |
10bc6f06 | 1121 | /* Make swapfile */ |
d6aaa55d | 1122 | if (swap_file) { |
10bc6f06 | 1123 | snprintf(commandstring, STRING_SIZE, "/bin/dd if=/dev/zero of=/harddisk/swapfile bs=1024k count=%d", swap_file); |
d6aaa55d MT |
1124 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE])) |
1125 | { | |
1126 | errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]); | |
1127 | goto EXIT; | |
1128 | } | |
10bc6f06 MT |
1129 | snprintf(commandstring, STRING_SIZE, "/bin/mkswap /harddisk/swapfile"); |
1130 | if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE])) | |
d6aaa55d MT |
1131 | { |
1132 | errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]); | |
1133 | goto EXIT; | |
1134 | } | |
d6aaa55d | 1135 | } |
10bc6f06 MT |
1136 | mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO); |
1137 | mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO); | |
1138 | mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO); | |
1139 | ||
1140 | if (raid_disk) | |
1141 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %sp1 /harddisk/boot", hdparams.devnode); | |
1142 | else | |
1143 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %s1 /harddisk/boot", hdparams.devnode); | |
d6aaa55d | 1144 | |
d6aaa55d MT |
1145 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM])) |
1146 | { | |
1147 | errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]); | |
1148 | goto EXIT; | |
1149 | } | |
10bc6f06 MT |
1150 | if (swap_file) { |
1151 | snprintf(commandstring, STRING_SIZE, "/bin/swapon /harddisk/swapfile"); | |
1152 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION])) | |
1153 | { | |
1154 | errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]); | |
1155 | goto EXIT; | |
1156 | } | |
1157 | } | |
1158 | if (raid_disk) | |
1159 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %sp2 /harddisk/var/log", hdparams.devnode); | |
1160 | else | |
1161 | snprintf(commandstring, STRING_SIZE, "/sbin/mount -t ext2 %s2 /harddisk/var/log", hdparams.devnode); | |
d6aaa55d MT |
1162 | if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM])) |
1163 | { | |
1164 | errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]); | |
1165 | goto EXIT; | |
1166 | } | |
1167 | ||
1168 | /* Either use tarball from cdrom or download. */ | |
1169 | if (installtype == CDROM_INSTALL) | |
1170 | snprintf(commandstring, STRING_SIZE, | |
1171 | "/bin/tar -C /harddisk -xvzf /cdrom/" SNAME "-" VERSION ".tgz"); | |
1172 | else | |
1173 | snprintf(commandstring, STRING_SIZE, | |
1174 | "/bin/wget -O - %s/" SNAME "-" VERSION ".tgz | /bin/tar -C /harddisk -xvzf -", url); | |
1175 | ||
e57bc1fd MT |
1176 | /* if (runcommandwithprogress(60, 4, title, commandstring, 4600, |
1177 | * ctr[TR_INSTALLING_FILES])) | |
1178 | * { | |
1179 | * errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
1180 | * goto EXIT; | |
1181 | * } | |
1182 | */ | |
1183 | ||
1184 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_FILES])) | |
d6aaa55d MT |
1185 | { |
1186 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
1187 | goto EXIT; | |
1188 | } | |
e57bc1fd | 1189 | |
d6aaa55d MT |
1190 | /* Save USB controller type to modules.conf */ |
1191 | write_usb_modules_conf(); | |
1192 | ||
1193 | /* touch the modules.dep files */ | |
10bc6f06 MT |
1194 | snprintf(commandstring, STRING_SIZE, |
1195 | "/bin/chroot /harddisk /bin/touch /lib/modules/%s/modules.dep", | |
1196 | KERNEL_VERSION); | |
1197 | mysystem(commandstring); | |
d6aaa55d | 1198 | #ifdef __i386__ |
10bc6f06 MT |
1199 | snprintf(commandstring, STRING_SIZE, |
1200 | "/bin/chroot /harddisk /bin/touch /lib/modules/%s-smp/modules.dep", | |
1201 | KERNEL_VERSION); | |
1202 | mysystem(commandstring); | |
d6aaa55d MT |
1203 | #endif |
1204 | ||
1205 | /* Rename uname */ | |
1206 | rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname"); | |
1207 | ||
1208 | /* Write PCMCIA Config */ | |
1209 | if (pcmcia) { | |
1210 | handle = fopen("/harddisk/etc/modules.conf", "a"); | |
1211 | if (handle != NULL) { | |
1212 | fprintf (handle, "# PCMCIA Settings\n"); | |
1213 | fprintf (handle, "alias pcmcia-controller %s\n", pcmcia); | |
1214 | fclose(handle); | |
1215 | } | |
1216 | } | |
1217 | ||
1218 | handle = fopen("/harddisk/etc/pcmcia.conf", "w"); | |
1219 | if (handle != NULL) { | |
1220 | if (pcmcia) { | |
1221 | fprintf (handle, "PCMCIA=yes\n"); | |
1222 | fprintf (handle, "PCIC=%s\n", pcmcia); | |
1223 | } else { | |
1224 | fprintf (handle, "PCMCIA=no\n"); | |
1225 | fprintf (handle, "PCIC=\n"); | |
1226 | } | |
1227 | fprintf (handle, "CARDMGR_OPTS=\n"); | |
1228 | fprintf (handle, "SCHEME=\n"); | |
1229 | fclose(handle); | |
1230 | } | |
1231 | ||
1232 | /* *always* write disk configuration */ | |
1233 | if (!(write_disk_configs(&hdparams))){ | |
10bc6f06 MT |
1234 | errorbox(ctr[TR_ERROR_WRITING_CONFIG]); |
1235 | goto EXIT; | |
d6aaa55d MT |
1236 | } |
1237 | ||
1238 | /* | |
1239 | Allow the user to restore their configuration from a floppy. | |
1240 | It uses tar. If the tar fails for any reason, show user an | |
1241 | error and go back to the restore/skip question. This gives | |
1242 | the user the chance to have another go. */ | |
10bc6f06 | 1243 | |
a6753b55 | 1244 | #ifdef OLD_RESTORECFG |
10bc6f06 MT |
1245 | RESTORE: |
1246 | /* set status variables to nonsense values */ | |
1247 | allok_fastexit = 0; | |
1248 | /* loop until floppy succeeds or user skips out */ | |
1249 | while (1) | |
1250 | { | |
1251 | sprintf(message, ctr[TR_RESTORE_CONFIGURATION], NAME); | |
1252 | if (newtWinChoice(title, ctr[TR_RESTORE], ctr[TR_SKIP], message) == 1) | |
1253 | { | |
1254 | /* Temporarily mount /proc under /harddisk/proc, | |
1255 | * run updfstab to locate the floppy, and unmount /harddisk/proc | |
1256 | * again. This should be run each time the user tries to restore | |
1257 | * so it can properly detect removable devices */ | |
1258 | if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) { | |
1259 | errorbox(ctr[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM]); | |
1260 | goto EXIT; | |
1261 | } | |
1262 | if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) { | |
1263 | errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_FSTAB]); | |
1264 | goto EXIT; | |
1265 | } | |
1266 | mysystem("/bin/umount /harddisk/proc"); | |
1267 | ||
1268 | mkdir("/harddisk/tmp/ipcop", S_IRWXU|S_IRWXG|S_IRWXO); | |
1269 | ||
1270 | /* Always extract to /tmp/ipcop for temporary extraction | |
1271 | * just in case floppy fails */ | |
1272 | ||
1273 | /* try a compressed backup first because it's quicker to fail. | |
1274 | * In exclude.system, files name must be without leading / or | |
1275 | * on extraction, name will never match */ | |
1276 | snprintf(commandstring, STRING_SIZE, | |
1277 | "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C /tmp/ipcop -xvzf /dev/floppy > %s 2> /dev/null", mylog); | |
d6aaa55d | 1278 | |
10bc6f06 MT |
1279 | statuswindow(45, 4, title, ctr[TR_INSTALLING_FILES]); |
1280 | rc = system(commandstring); | |
1281 | ||
1282 | if (rc) { | |
1283 | /* if it's not compressed, try uncompressed first before failing*/ | |
1284 | snprintf(commandstring, STRING_SIZE, | |
1285 | "/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C /tmp/ipcop -xvf /dev/floppy > %s 2> /dev/null", mylog); | |
1286 | rc = system(commandstring); | |
1287 | if (rc) { | |
1288 | newtPopWindow(); | |
1289 | /* command failed trying to read from floppy */ | |
1290 | errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]); | |
1291 | ||
1292 | /* remove badly restored files */ | |
1293 | mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop"); | |
1294 | goto RESTORE; | |
1295 | } else { | |
1296 | /* Now copy to correct location */ | |
1297 | mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /"); | |
1298 | mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop"); | |
1299 | newtPopWindow(); | |
1300 | allok_fastexit=1; | |
1301 | ||
1302 | /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */ | |
1303 | upgrade_v12_v13(); | |
1304 | upgrade_v130_v140(); | |
1305 | break; /* out of loop at this point because floppy has | |
1306 | successfully restored */ | |
1307 | } | |
1308 | } | |
1309 | else { /* success */ | |
1310 | /* Now copy to correct location */ | |
1311 | mysystem("/bin/chroot /harddisk /bin/cp -af /tmp/ipcop/. /"); | |
1312 | mysystem("/bin/chroot /harddisk /bin/rm -rf /tmp/ipcop"); | |
1313 | newtPopWindow(); | |
1314 | allok_fastexit=1; | |
1315 | ||
1316 | /* Upgrade necessary files from v1.2 to v1.3 to v1.4 */ | |
1317 | upgrade_v12_v13(); | |
1318 | upgrade_v130_v140(); | |
1319 | break; /* out of loop at this point because floppy has | |
1320 | successfully restored */ | |
1321 | } | |
1322 | } | |
1323 | else{ /* user chose to skip install from floppy */ | |
1324 | if (installtype == CDROM_INSTALL){ | |
1325 | /* if we installed from CD ROM then we didn't set up the | |
1326 | network interface yet. Therefore, set up Network | |
1327 | driver and params just before we need them. */ | |
1328 | ||
1329 | if (!(networkmenu(ethernetkv))){ | |
1330 | /* network setup failed, tell the world */ | |
1331 | errorbox(ctr[TR_NETWORK_SETUP_FAILED]); | |
1332 | goto EXIT; | |
1333 | } | |
1334 | } | |
1335 | break; /* out of loop because we succeeded with ethernet | |
1336 | set up and user is notrestarting from floppy*/ | |
1337 | } | |
1338 | } | |
a6753b55 HS |
1339 | #else |
1340 | if (installtype == CDROM_INSTALL){ | |
1341 | /* if we installed from CD ROM then we didn't set up the | |
1342 | network interface yet. Therefore, set up Network | |
1343 | driver and params just before we need them. */ | |
1344 | ||
1345 | if (!(networkmenu(ethernetkv))){ | |
1346 | /* network setup failed, tell the world */ | |
1347 | errorbox(ctr[TR_NETWORK_SETUP_FAILED]); | |
1348 | goto EXIT; | |
1349 | } | |
1350 | } | |
1351 | #endif | |
10bc6f06 MT |
1352 | |
1353 | /* Check the SQUID acl file exists, if not use our 1.4 copy */ | |
1354 | { | |
1355 | FILE *aclreadfile; | |
1356 | ||
1357 | if (!(aclreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/acl", "r"))) { | |
1358 | rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4", | |
1359 | "/harddisk" CONFIG_ROOT "/proxy/acl"); | |
1360 | } else { | |
1361 | unlink ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4"); | |
1362 | fclose(aclreadfile); | |
d6aaa55d | 1363 | } |
10bc6f06 | 1364 | chown ("/harddisk" CONFIG_ROOT "/proxy/acl", 99, 99); |
d6aaa55d MT |
1365 | } |
1366 | ||
1367 | /* Build cache lang file */ | |
1368 | mysystem("/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\""); | |
1369 | ||
10bc6f06 MT |
1370 | if (!allok_fastexit){ |
1371 | /* write ethernet and lang configs only if they have not | |
1372 | been restored from floppy already. */ | |
1373 | if (!(write_ethernet_configs( ethernetkv))|| | |
1374 | !(write_lang_configs(shortlangname))){ | |
1375 | errorbox(ctr[TR_ERROR_WRITING_CONFIG]); | |
1376 | goto EXIT; | |
1377 | } | |
1378 | } | |
1379 | ||
1380 | /* if we detected SCSI then fixup */ | |
1381 | if ((handle = fopen("/scsidriver", "r"))) | |
1382 | { | |
1383 | char *driver; | |
1384 | fgets(line, STRING_SIZE-1, handle); | |
1385 | fclose(handle); | |
1386 | line[strlen(line) - 1] = 0; | |
1387 | driver = strtok(line, "."); | |
1388 | fprintf(flog, "Detected SCSI driver %s\n",driver); | |
1389 | if (strlen(driver) > 1) { | |
f8ae001e | 1390 | fprintf(flog, "Fixing up ipfirerd.img\n"); |
10bc6f06 MT |
1391 | mysystem("/bin/chroot /harddisk /sbin/modprobe loop"); |
1392 | mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO); | |
f8ae001e | 1393 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata --with=ataraid /boot/ipfirerd.img %s", driver, KERNEL_VERSION); |
10bc6f06 MT |
1394 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); |
1395 | #ifdef __i386__ | |
f8ae001e | 1396 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata --with=ataraid /boot/ipfirerd-smp.img %s-smp", driver, KERNEL_VERSION); |
10bc6f06 MT |
1397 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); |
1398 | mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf"); | |
1399 | #endif | |
1400 | #ifdef __alpha__ | |
1401 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf"); | |
1402 | runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]); | |
1403 | #endif | |
d6aaa55d MT |
1404 | } |
1405 | } | |
1406 | ||
d6aaa55d MT |
1407 | #if 0 /* not yet */ |
1408 | if (pcmcia_disk) | |
1409 | { | |
1410 | fprintf(flog, "Detected SCSI driver PCMCIA\n"); | |
f8ae001e | 1411 | fprintf(flog, "Fixing up ipfirerd.img\n"); |
d6aaa55d MT |
1412 | mysystem("/bin/chroot /harddisk /sbin/modprobe loop"); |
1413 | mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO); | |
f8ae001e | 1414 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/pcinitrd -r %s /boot/ipfirerd.img", KERNEL_VERSION); |
10bc6f06 | 1415 | mysystem(commandstring); |
d6aaa55d MT |
1416 | #ifdef __i386__ |
1417 | mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf"); | |
1418 | #endif | |
1419 | #ifdef __alpha__ | |
1420 | mysystem("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf"); | |
1421 | #endif | |
1422 | } | |
1423 | #endif | |
1424 | ||
1425 | #ifdef __i386__ | |
10bc6f06 | 1426 | replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode); |
d6aaa55d MT |
1427 | /* restore permissions */ |
1428 | chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); | |
1429 | ||
10bc6f06 MT |
1430 | if (raid_disk) |
1431 | sprintf(string, "root=%sp4", hdparams.devnode); | |
1432 | else | |
1433 | sprintf(string, "root=%s4", hdparams.devnode); | |
d6aaa55d MT |
1434 | replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string); |
1435 | ||
1436 | mysystem("/bin/chroot /harddisk /bin/mount -n -t proc none /proc"); | |
1437 | ||
10bc6f06 MT |
1438 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /boot/grub/grubbatch"); |
1439 | ||
1440 | if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) | |
d6aaa55d MT |
1441 | { |
1442 | errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]); | |
1443 | goto EXIT; | |
1444 | } | |
f8ae001e | 1445 | /* Set Bootsplash */ |
5433e2c9 | 1446 | mysystem("/bin/installbootsplash.sh"); |
d6aaa55d MT |
1447 | mysystem("/bin/chroot /harddisk /bin/umount -n /proc"); |
1448 | #endif | |
1449 | #ifdef __alpha__ | |
10bc6f06 | 1450 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/swriteboot -f3 %s /boot/bootlx", hdparams.devnode); |
d6aaa55d | 1451 | mysystem(commandstring); |
10bc6f06 | 1452 | snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/abootconf %s 1", hdparams.devnode); |
d6aaa55d | 1453 | mysystem(commandstring); |
10bc6f06 MT |
1454 | if (raid_disk) |
1455 | sprintf(string, "root=%sp4", hdparams.devnode); | |
1456 | else | |
1457 | sprintf(string, "root=%s4", hdparams.devnode); | |
d6aaa55d MT |
1458 | replace( "/harddisk/boot/etc/aboot.conf", "root=ROOT", string); |
1459 | #endif | |
1460 | ||
1461 | /* unmounting happens everywhere because there are places | |
1462 | which require device is to be unmounted under certain | |
1463 | circumstances. This is the last place we can unmount | |
10bc6f06 | 1464 | anything and still succeed. */ |
d6aaa55d | 1465 | |
10bc6f06 MT |
1466 | if (!unmount_before && installtype == CDROM_INSTALL){ |
1467 | if (mysystem("/sbin/umount /cdrom")) | |
1468 | { | |
1469 | errorbox(ctr[TR_UNABLE_TO_UNMOUNT_CDROM]); | |
1470 | goto EXIT; | |
1471 | } | |
d6aaa55d MT |
1472 | } |
1473 | ||
10bc6f06 | 1474 | if (installtype == CDROM_INSTALL) |
d6aaa55d | 1475 | { |
10bc6f06 MT |
1476 | |
1477 | if (!(ejectcdrom(cdromparams.devnode))) | |
d6aaa55d MT |
1478 | { |
1479 | errorbox(ctr[TR_UNABLE_TO_EJECT_CDROM]); | |
1480 | // goto EXIT; | |
1481 | } | |
1482 | } | |
10bc6f06 MT |
1483 | |
1484 | ||
1485 | sprintf(message, ctr[TR_CONGRATULATIONS_LONG], | |
d6aaa55d MT |
1486 | NAME, SNAME, SNAME, NAME, NAME, NAME); |
1487 | newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message); | |
10bc6f06 | 1488 | |
d6aaa55d | 1489 | allok = 1; |
10bc6f06 | 1490 | |
d6aaa55d | 1491 | EXIT: |
10bc6f06 | 1492 | fprintf(flog, "Install program ended.\n"); |
d6aaa55d MT |
1493 | fflush(flog); |
1494 | fclose(flog); | |
1495 | ||
10bc6f06 | 1496 | if (!(allok)) |
d6aaa55d | 1497 | newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]); |
10bc6f06 | 1498 | |
d6aaa55d | 1499 | newtFinished(); |
10bc6f06 | 1500 | |
d6aaa55d | 1501 | freekeyvalues(ethernetkv); |
d6aaa55d | 1502 | |
10bc6f06 | 1503 | if (allok && !allok_fastexit) |
d6aaa55d MT |
1504 | { |
1505 | /* /proc is needed by the module checker. We have to mount it | |
1506 | * so it can be seen by setup, which is run chrooted. */ | |
1507 | if (system("/sbin/mount proc -t proc /harddisk/proc")) | |
1508 | printf("Unable to mount proc in /harddisk."); | |
1509 | else | |
1510 | { | |
1511 | if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL")) | |
1512 | printf("Unable to run setup.\n"); | |
1513 | if (system("/sbin/umount /harddisk/proc")) | |
1514 | printf("Unable to umount /harddisk/proc.\n"); | |
1515 | } | |
1516 | } | |
1517 | ||
1518 | fcloseall(); | |
1519 | ||
1520 | system("/bin/swapoff /harddisk/swapfile"); | |
1521 | system("/sbin/umount /harddisk/var/log"); | |
1522 | system("/sbin/umount /harddisk/boot"); | |
1523 | system("/sbin/umount /harddisk"); | |
10bc6f06 | 1524 | |
d6aaa55d MT |
1525 | system("/etc/halt"); |
1526 | ||
1527 | return 0; | |
1528 | } |