e87ebb7e2300ce47c24d415c377eba4ccc6a8765
[people/pmueller/ipfire-2.x.git] / src / install+setup / install / main.c
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 *
9 */
10
11 #include "install.h"
12 #define _GNU_SOURCE
13
14 #define CDROM_INSTALL 0
15 #define URL_INSTALL 1
16 #define DISK_INSTALL 2
17 #define INST_FILECOUNT 6600
18 #define UNATTENDED_CONF "/cdrom/data/unattended.conf"
19
20 int raid_disk = 0;
21 FILE *flog = NULL;
22 char *mylog;
23
24 char **ctr;
25
26 char *pcmcia = NULL;
27 extern char url[STRING_SIZE];
28
29 extern char *en_tr[];
30 extern char *de_tr[];
31
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", "eth0");
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
242 int main(int argc, char *argv[])
243 {
244 char *langnames[] = { "Deutsch", "English", NULL };
245 char *shortlangnames[] = { "de", "en", NULL };
246 char **langtrs[] = { de_tr, en_tr, NULL };
247 char hdletter, cdletter;
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;
252 char commandstring[STRING_SIZE];
253 char *installtypes[] = { "CDROM", "HTTP/FTP", NULL };
254 int installtype = CDROM_INSTALL;
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;
262 int allok_fastexit=0;
263 int unmount_before=0;
264 struct keyvalue *ethernetkv = initkeyvalues();
265 FILE *handle, *cmdfile;
266 char line[STRING_SIZE];
267 char string[STRING_SIZE];
268 long maximum_free = 0, current_free;
269 long memory = 0;
270 long system_partition, boot_partition, root_partition, swap_file;
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;
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];
286
287 setlocale (LC_ALL, "");
288 sethostname( SNAME , 10);
289
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 }
342 // check if we have to make an unattended install
343 if (strstr (line, "unattended") != NULL) {
344 unattended = 1;
345 }
346 }
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 }
352
353 /* German is the default */
354 for (choice = 0; langnames[choice]; choice++)
355 {
356 if (strcmp(langnames[choice], "Deutsch") == 0)
357 break;
358 }
359 if (!langnames[choice])
360 goto EXIT;
361
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
368 ctr = langtrs[choice];
369 strcpy(shortlangname, shortlangnames[choice]);
370
371 mysystem("/bin/setfont lat0-16");
372
373 newtDrawRootText(14, 0, NAME " v" VERSION " - " SLOGAN );
374 newtPushHelpLine(ctr[TR_HELPLINE]);
375
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
470
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 }
496
497 if (rc == 2)
498 goto EXIT;
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 = 20; /* in MB */
554 current_free = maximum_free - boot_partition - swap_file;
555
556 root_partition = 2048 ;
557 if (current_free < 512) {
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 system_partition = current_free;
568
569 fprintf(flog, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n",
570 boot_partition, swap_file, system_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",
578 boot_partition, swap_file, root_partition);
579 } else {
580 fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,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 ext2 -c %sp1", hdparams.devnode);
597 else
598 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -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/mkreiserfs -f %sp3", hdparams.devnode);
619 else
620 snprintf(commandstring, STRING_SIZE, "/bin/mkreiserfs -f %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/mkreiserfs -f %sp4", hdparams.devnode);
630 else
631 snprintf(commandstring, STRING_SIZE, "/bin/mkreiserfs -f %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 snprintf(commandstring, STRING_SIZE, "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME "-" VERSION ".tbz2");
686
687 if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
688 ctr[TR_INSTALLING_FILES]))
689 {
690 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
691 goto EXIT;
692 }
693
694 /* Save USB controller type to modules.conf */
695 write_usb_modules_conf();
696
697 /* touch the modules.dep files */
698 snprintf(commandstring, STRING_SIZE,
699 "/bin/chroot /harddisk /usr/bin/touch /lib/modules/%s/modules.dep",
700 KERNEL_VERSION);
701 mysystem(commandstring);
702 snprintf(commandstring, STRING_SIZE,
703 "/bin/chroot /harddisk /usr/bin/touch /lib/modules/%s-smp/modules.dep",
704 KERNEL_VERSION);
705 mysystem(commandstring);
706
707 /* Rename uname */
708 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
709
710 /* Write PCMCIA Config */
711 if (pcmcia) {
712 handle = fopen("/harddisk/etc/modules.conf", "a");
713 if (handle != NULL) {
714 fprintf (handle, "# PCMCIA Settings\n");
715 fprintf (handle, "alias pcmcia-controller %s\n", pcmcia);
716 fclose(handle);
717 }
718 }
719
720 handle = fopen("/harddisk/etc/pcmcia.conf", "w");
721 if (handle != NULL) {
722 if (pcmcia) {
723 fprintf (handle, "PCMCIA=yes\n");
724 fprintf (handle, "PCIC=%s\n", pcmcia);
725 } else {
726 fprintf (handle, "PCMCIA=no\n");
727 fprintf (handle, "PCIC=\n");
728 }
729 fprintf (handle, "CARDMGR_OPTS=\n");
730 fprintf (handle, "SCHEME=\n");
731 fclose(handle);
732 }
733
734 /* *always* write disk configuration */
735 if (!(write_disk_configs(&hdparams))){
736 errorbox(ctr[TR_ERROR_WRITING_CONFIG]);
737 goto EXIT;
738 }
739
740 /* if we detected SCSI then fixup */
741 if ((handle = fopen("/scsidriver", "r")))
742 {
743 char *driver;
744 fgets(line, STRING_SIZE-1, handle);
745 fclose(handle);
746 line[strlen(line) - 1] = 0;
747 driver = strtok(line, ".");
748 fprintf(flog, "Detected SCSI driver %s\n",driver);
749 if (strlen(driver) > 1) {
750 fprintf(flog, "Fixing up ipfirerd.img\n");
751 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
752 mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
753 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);
754 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
755 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);
756 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
757 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
758 }
759 }
760
761
762 /* Build cache lang file */
763 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
764 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE]))
765 {
766 errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]);
767 goto EXIT;
768 }
769
770 if (raid_disk)
771 sprintf(string, "root=%sp3", hdparams.devnode);
772 else
773 sprintf(string, "root=%s3", hdparams.devnode);
774 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string);
775 mysystem( "sed -i \"s|KVERSION|$(/bin/uname -r)|\" /harddisk/boot/grub/grub.conf" );
776
777 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode);
778 /* restore permissions */
779 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH);
780
781 /* mount proc filesystem */
782 mysystem("mkdir /harddisk/proc");
783 mysystem("/bin/mount -t proc none /harddisk/proc");
784 mysystem("/bin/mount --bind /dev /harddisk/dev");
785
786 snprintf(commandstring, STRING_SIZE,
787 "/bin/chroot /harddisk /boot/grub/grubbatch");
788 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) {
789 errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
790 goto EXIT;
791 }
792
793 /* Install bootsplash */
794 mysystem("/bin/installbootsplash.sh");
795
796 mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst");
797 mysystem("umount /harddisk/proc");
798 mysystem("umount /harddisk/dev");
799
800 sprintf(message, ctr[TR_CONGRATULATIONS_LONG],
801 NAME, SNAME, SNAME, NAME, NAME, NAME);
802 newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message);
803
804 allok = 1;
805
806 EXIT:
807 fprintf(flog, "Install program ended.\n");
808 fflush(flog);
809 fclose(flog);
810
811 if (!(allok))
812 newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]);
813
814 newtFinished();
815
816 freekeyvalues(ethernetkv);
817
818 if (allok && !allok_fastexit)
819 {
820 /* /proc is needed by the module checker. We have to mount it
821 * so it can be seen by setup, which is run chrooted. */
822 if (system("/sbin/mount proc -t proc /harddisk/proc"))
823 printf("Unable to mount proc in /harddisk.");
824 else
825 {
826 if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
827 printf("Unable to run setup.\n");
828 if (system("/sbin/umount /harddisk/proc"))
829 printf("Unable to umount /harddisk/proc.\n");
830 }
831 }
832
833 fcloseall();
834
835 system("/bin/swapoff /harddisk/swapfile");
836 system("/sbin/umount /harddisk/var/log");
837 system("/sbin/umount /harddisk/boot");
838 system("/sbin/umount /harddisk");
839
840 system("/etc/halt");
841
842 return 0;
843 }