]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/install+setup/install/main.c
Kleiner netter neuer Versuch.
[people/teissler/ipfire-2.x.git] / src / install+setup / install / main.c
CommitLineData
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
20int raid_disk = 0;
21FILE *flog = NULL;
22char *mylog;
10bc6f06 23
d6aaa55d
MT
24char **ctr;
25
26char *pcmcia = NULL;
27extern char url[STRING_SIZE];
28
10bc6f06 29extern char *en_tr[];
10bc6f06 30extern char *de_tr[];
d6aaa55d 31
72d80898
MT
32int 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
49int 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
83long 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
94int 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");
8e2e5cf3 150 replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0");
72d80898
MT
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");
edd536b6 183 return 0;
72d80898
MT
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
242int 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;
8e2e5cf3 270 long system_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
9607771a
MT
397 /* CDROM INSTALL */
398 if (installtype == CDROM_INSTALL) {
72d80898 399
9607771a
MT
400 switch (mysystem("/bin/mountsource.sh")) {
401 case 0:
402 installtype = CDROM_INSTALL;
403 cdmounted = 1;
404 break;
405 case 1:
406 installtype = DISK_INSTALL;
407 break;
408 case 10:
409 errorbox(ctr[TR_NO_CDROM]);
410 goto EXIT;
411 }
412
413 /* read source drive letter */
414 if ((handle = fopen("/source_device", "r")) == NULL) {
415 errorbox("ERROR reading source_device");
416 }
417 fgets(sourcedrive, 5, handle);
418 fprintf(flog, "Source drive: %s\n", sourcedrive);
419 fclose(handle);
420
421 snprintf(cdromparams.devnode, STRING_SIZE, "/dev/%s", sourcedrive);
422 cdromparams.module = 0;
423 fprintf(flog, "Source device: %s\n", cdromparams.devnode);
72d80898 424 }
9607771a
MT
425
426 /* Configure the network now! */
427 if (installtype == URL_INSTALL) {
428 /* Network driver and params. */
429 if (!(networkmenu(ethernetkv))) {
430 errorbox(ctr[TR_NETWORK_SETUP_FAILED]);
431 goto EXIT;
432 }
433
434 /* Check for ipcop-<VERSION>.tbz2 */
435 if (checktarball(SNAME "-" VERSION ".tbz2", ctr[TR_ENTER_URL])) {
436 errorbox(ctr[TR_NO_IPCOP_TARBALL_FOUND]);
437 goto EXIT;
438 }
72d80898
MT
439 }
440
441 /* Get device for the HD. This has to succeed. */
442 if (!(hdletter = findidetype(IDE_HD)))
443 {
444 /* Need to clean this up at some point */
445 if (!try_scsi("sda") || strstr(sourcedrive, "sda") != NULL) {
446 if (!try_scsi("ida/c0d0")) {
447 if (!try_scsi("cciss/c0d0")) {
448 if (!try_scsi("rd/c0d0")) {
449 if (!try_scsi("ataraid/d0")) {
450 errorbox(ctr[TR_NO_HARDDISK]);
451 goto EXIT;
452 } else {
453 raid_disk = 1;
454 sprintf(harddrive, "ataraid/d0");
455 }
456 } else {
457 raid_disk = 1;
458 sprintf(harddrive, "rd/c0d0");
459 }
460 } else {
461 raid_disk = 1;
462 sprintf(harddrive, "cciss/c0d0");
463 }
464 } else {
465 raid_disk = 1;
466 sprintf(harddrive, "ida/c0d0");
467 }
468 } else {
469 if (strstr(sourcedrive, "sda") != NULL) {
470 // probably installing from usb stick, try sdb
471 if (try_scsi("sdb")) {
472 sprintf(harddrive, "sdb");
473 }
474 else {
475 errorbox(ctr[TR_NO_HARDDISK]);
476 goto EXIT;
477 }
478 }
479 else {
480 sprintf(harddrive, "sda");
481 }
482 }
483 scsi_disk = 1;
484 } else
485 sprintf(harddrive, "hd%c", hdletter);
486
9607771a 487 fprintf(flog, "Destination drive: %s\n", harddrive);
d6aaa55d 488
72d80898
MT
489 /* load unattended configuration */
490 if (unattended) {
491 fprintf(flog, "unattended: Reading unattended.conf\n");
492
493 (void) readkeyvalues(unattendedkv, UNATTENDED_CONF);
494 }
495
496 /* Make the hdparms struct and print the contents. */
497 snprintf(hdparams.devnode, STRING_SIZE, "/dev/%s", harddrive);
498 hdparams.module = 0;
499
500 sprintf(message, ctr[TR_PREPARE_HARDDISK], hdparams.devnode);
501
502 if (unattended) {
503 hardyn = 1;
504 }
505
506 while (! hardyn) {
507 rc = newtWinMenu(title, message,
508 50, 5, 5, 6, yesnoharddisk,
509 &hardyn, ctr[TR_OK],
510 ctr[TR_CANCEL], NULL);
511 if (rc == 2)
512 goto EXIT;
513 }
5433e2c9
MT
514
515 if (rc == 2)
516 goto EXIT;
72d80898
MT
517
518 /* Calculate amount of memory in machine */
519 if ((handle = fopen("/proc/meminfo", "r")))
520 {
521 while (fgets(line, STRING_SIZE-1, handle)) {
522 if (sscanf (line, "MemTotal: %s kB", string)) {
523 memory = atoi(string) / 1024 ;
524 }
525 }
526 fclose(handle);
527 }
528
529 /* Partition, mkswp, mkfs.
530 * before partitioning, first determine the sizes of each
531 * partition. In order to do that we need to know the size of
532 * the disk.
533 */
534 /* Don't use mysystem here so we can redirect output */
535 sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /disksize 2> /dev/null", harddrive);
536 system(commandstring);
537
538 /* Calculate amount of disk space */
539 if ((handle = fopen("/disksize", "r")))
540 {
541 fgets(line, STRING_SIZE-1, handle);
542 if (sscanf (line, "%s", string)) {
543 maximum_free = atoi(string) / 1024;
544 }
545 fclose(handle);
546 }
547
548 fprintf(flog, "maximum_free = %ld, memory = %ld",
549 maximum_free, memory);
550
551 swap_file = calc_swapsize(memory, maximum_free);
552
553 if (maximum_free < 512 + swap_file ) {
554 if (maximum_free < 512) {
555 errorbox(ctr[TR_DISK_TOO_SMALL]);
556 goto EXIT;
557 }
558
559 if (!unattended) {
560 rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]);
561 }
562 else {
563 rc = 1;
564 }
565
566 if (rc != 1)
567 goto EXIT;
568 swap_file = 0;
569 }
570
8e2e5cf3 571 boot_partition = 20; /* in MB */
72d80898
MT
572 current_free = maximum_free - boot_partition - swap_file;
573
8e2e5cf3
MT
574 root_partition = 2048 ;
575 if (current_free < 512) {
72d80898
MT
576 errorbox(ctr[TR_DISK_TOO_SMALL]);
577 goto EXIT;
578 }
579
580 current_free = current_free - root_partition;
581 if (!swap_file) {
582 root_partition = root_partition + swap_file;
583 }
584
8e2e5cf3 585 system_partition = current_free;
72d80898
MT
586
587 fprintf(flog, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n",
8e2e5cf3 588 boot_partition, swap_file, system_partition, root_partition);
72d80898
MT
589
590 handle = fopen("/tmp/partitiontable", "w");
591
72d80898
MT
592 /* Make swapfile */
593 if (swap_file) {
9607771a 594 fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n",
72d80898
MT
595 boot_partition, swap_file, root_partition);
596 } else {
9607771a 597 fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n",
72d80898
MT
598 boot_partition, root_partition);
599 }
600
601 fclose(handle);
602
603 snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams.devnode);
604 if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK]))
605 {
606 errorbox(ctr[TR_UNABLE_TO_PARTITION]);
607 goto EXIT;
608 }
609
610 mysystem("/bin/udevstart");
611
612 if (raid_disk)
8e2e5cf3 613 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %sp1", hdparams.devnode);
72d80898 614 else
8e2e5cf3 615 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %s1", hdparams.devnode);
72d80898
MT
616 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM]))
617 {
618 errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]);
619 goto EXIT;
620 }
621
622 if (swap_file) {
623 if (raid_disk)
624 snprintf(commandstring, STRING_SIZE, "/bin/mkswap %sp2", hdparams.devnode);
625 else
626 snprintf(commandstring, STRING_SIZE, "/bin/mkswap %s2", hdparams.devnode);
627 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE]))
628 {
629 errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]);
630 goto EXIT;
631 }
632 }
633
634 if (raid_disk)
8e2e5cf3 635 snprintf(commandstring, STRING_SIZE, "/bin/mkreiserfs -f %sp3", hdparams.devnode);
72d80898 636 else
8e2e5cf3 637 snprintf(commandstring, STRING_SIZE, "/bin/mkreiserfs -f %s3", hdparams.devnode);
72d80898
MT
638
639 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM]))
640 {
641 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
642 goto EXIT;
643 }
644
9607771a 645 if (raid_disk)
8e2e5cf3 646 snprintf(commandstring, STRING_SIZE, "/bin/mkreiserfs -f %sp4", hdparams.devnode);
72d80898 647 else
8e2e5cf3 648 snprintf(commandstring, STRING_SIZE, "/bin/mkreiserfs -f %s4", hdparams.devnode);
72d80898
MT
649
650 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM]))
651 {
652 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
653 goto EXIT;
9607771a 654 }
72d80898
MT
655
656 /* Mount harddisk. */
657 if (raid_disk)
658 snprintf(commandstring, STRING_SIZE, "/sbin/mount %sp3 /harddisk", hdparams.devnode);
659 else
660 snprintf(commandstring, STRING_SIZE, "/sbin/mount %s3 /harddisk", hdparams.devnode);
661 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM]))
662 {
663 errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]);
664 goto EXIT;
665 }
666
667 mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO);
668 mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO);
669 mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO);
670
671 if (raid_disk)
672 snprintf(commandstring, STRING_SIZE, "/sbin/mount %sp1 /harddisk/boot", hdparams.devnode);
673 else
674 snprintf(commandstring, STRING_SIZE, "/sbin/mount %s1 /harddisk/boot", hdparams.devnode);
675
676 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM]))
677 {
678 errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]);
679 goto EXIT;
680 }
681 if (swap_file) {
682 if (raid_disk)
683 snprintf(commandstring, STRING_SIZE, "/bin/swapon %sp2", hdparams.devnode);
684 else
685 snprintf(commandstring, STRING_SIZE, "/bin/swapon %s2", hdparams.devnode);
686 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION]))
687 {
688 errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]);
689 goto EXIT;
690 }
691 }
9607771a 692 if (raid_disk)
72d80898
MT
693 snprintf(commandstring, STRING_SIZE, "/sbin/mount %sp4 /harddisk/var", hdparams.devnode);
694 else
695 snprintf(commandstring, STRING_SIZE, "/sbin/mount %s4 /harddisk/var", hdparams.devnode);
696 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM]))
697 {
698 errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]);
699 goto EXIT;
9607771a 700 }
10bc6f06 701
8e2e5cf3 702 snprintf(commandstring, STRING_SIZE, "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME "-" VERSION ".tbz2");
d6aaa55d 703
edd536b6
MT
704 if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
705 ctr[TR_INSTALLING_FILES]))
d6aaa55d
MT
706 {
707 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
708 goto EXIT;
709 }
e57bc1fd 710
d6aaa55d
MT
711 /* Save USB controller type to modules.conf */
712 write_usb_modules_conf();
713
714 /* touch the modules.dep files */
10bc6f06 715 snprintf(commandstring, STRING_SIZE,
8e2e5cf3 716 "/bin/chroot /harddisk /usr/bin/touch /lib/modules/%s/modules.dep",
10bc6f06
MT
717 KERNEL_VERSION);
718 mysystem(commandstring);
10bc6f06 719 snprintf(commandstring, STRING_SIZE,
8e2e5cf3 720 "/bin/chroot /harddisk /usr/bin/touch /lib/modules/%s-smp/modules.dep",
10bc6f06
MT
721 KERNEL_VERSION);
722 mysystem(commandstring);
d6aaa55d
MT
723
724 /* Rename uname */
725 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
726
727 /* Write PCMCIA Config */
728 if (pcmcia) {
729 handle = fopen("/harddisk/etc/modules.conf", "a");
730 if (handle != NULL) {
731 fprintf (handle, "# PCMCIA Settings\n");
732 fprintf (handle, "alias pcmcia-controller %s\n", pcmcia);
733 fclose(handle);
734 }
735 }
736
737 handle = fopen("/harddisk/etc/pcmcia.conf", "w");
738 if (handle != NULL) {
739 if (pcmcia) {
740 fprintf (handle, "PCMCIA=yes\n");
741 fprintf (handle, "PCIC=%s\n", pcmcia);
742 } else {
743 fprintf (handle, "PCMCIA=no\n");
744 fprintf (handle, "PCIC=\n");
745 }
746 fprintf (handle, "CARDMGR_OPTS=\n");
747 fprintf (handle, "SCHEME=\n");
748 fclose(handle);
749 }
750
751 /* *always* write disk configuration */
752 if (!(write_disk_configs(&hdparams))){
10bc6f06
MT
753 errorbox(ctr[TR_ERROR_WRITING_CONFIG]);
754 goto EXIT;
d6aaa55d
MT
755 }
756
9607771a
MT
757 /* mount proc filesystem */
758 mysystem("mkdir /harddisk/proc");
759 mysystem("/bin/mount -t proc none /harddisk/proc");
760 mysystem("/bin/mount --bind /dev /harddisk/dev");
761
22b9e405 762 /* if we detected SCSI then fixup */
9607771a
MT
763 mysystem("/bin/probecntrl.sh");
764 if ((handle = fopen("/cntrldriver", "r")))
22b9e405
MT
765 {
766 char *driver;
767 fgets(line, STRING_SIZE-1, handle);
768 fclose(handle);
769 line[strlen(line) - 1] = 0;
770 driver = strtok(line, ".");
771 fprintf(flog, "Detected SCSI driver %s\n",driver);
772 if (strlen(driver) > 1) {
773 fprintf(flog, "Fixing up ipfirerd.img\n");
774 mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
775 mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
9607771a 776 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata /boot/ipfirerd.img %s", driver, KERNEL_VERSION);
22b9e405 777 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
9607771a 778 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata /boot/ipfirerd-smp.img %s-smp", driver, KERNEL_VERSION);
22b9e405
MT
779 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
780 mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
9607771a
MT
781 }
782 }
22b9e405 783
9607771a
MT
784 /* Build cache lang file */
785 snprintf(commandstring, STRING_SIZE, "/bin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
786 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE]))
787 {
788 errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]);
789 goto EXIT;
790 }
edd536b6
MT
791
792 if (raid_disk)
793 sprintf(string, "root=%sp3", hdparams.devnode);
794 else
795 sprintf(string, "root=%s3", hdparams.devnode);
796 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string);
797 mysystem( "sed -i \"s|KVERSION|$(/bin/uname -r)|\" /harddisk/boot/grub/grub.conf" );
798
799 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode);
800 /* restore permissions */
801 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH);
802
edd536b6
MT
803 snprintf(commandstring, STRING_SIZE,
804 "/bin/chroot /harddisk /boot/grub/grubbatch");
805 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) {
806 errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
807 goto EXIT;
808 }
809
22b9e405
MT
810 /* Install bootsplash */
811 mysystem("/bin/installbootsplash.sh");
812
813 mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst");
814 mysystem("umount /harddisk/proc");
815 mysystem("umount /harddisk/dev");
816
817 sprintf(message, ctr[TR_CONGRATULATIONS_LONG],
818 NAME, SNAME, SNAME, NAME, NAME, NAME);
819 newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message);
820
821 allok = 1;
edd536b6 822
d6aaa55d 823EXIT:
10bc6f06 824 fprintf(flog, "Install program ended.\n");
d6aaa55d
MT
825 fflush(flog);
826 fclose(flog);
827
10bc6f06 828 if (!(allok))
d6aaa55d 829 newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]);
10bc6f06 830
d6aaa55d 831 newtFinished();
10bc6f06 832
d6aaa55d 833 freekeyvalues(ethernetkv);
d6aaa55d 834
10bc6f06 835 if (allok && !allok_fastexit)
d6aaa55d
MT
836 {
837 /* /proc is needed by the module checker. We have to mount it
838 * so it can be seen by setup, which is run chrooted. */
839 if (system("/sbin/mount proc -t proc /harddisk/proc"))
840 printf("Unable to mount proc in /harddisk.");
841 else
842 {
843 if (system("/bin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
844 printf("Unable to run setup.\n");
845 if (system("/sbin/umount /harddisk/proc"))
846 printf("Unable to umount /harddisk/proc.\n");
847 }
848 }
849
850 fcloseall();
851
852 system("/bin/swapoff /harddisk/swapfile");
9607771a 853 system("/sbin/umount /harddisk/var");
d6aaa55d
MT
854 system("/sbin/umount /harddisk/boot");
855 system("/sbin/umount /harddisk");
10bc6f06 856
d6aaa55d
MT
857 system("/etc/halt");
858
859 return 0;
860}