]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame_incremental - src/install+setup/install/main.c
Neue Hardwareerkennung im Installer...
[people/teissler/ipfire-2.x.git] / src / install+setup / install / main.c
... / ...
CommitLineData
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 7000
18#define UNATTENDED_CONF "/cdrom/boot/unattended.conf"
19
20int raid_disk = 0;
21FILE *flog = NULL;
22char *mylog;
23
24char **ctr;
25
26char *pcmcia = NULL;
27extern char url[STRING_SIZE];
28
29extern char *en_tr[];
30extern char *de_tr[];
31
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
49long calc_swapsize(long memory, long disk) {
50 if (memory < 128) {
51 return 256;
52 }
53 if (memory > 1024) {
54 return 512;
55 }
56
57 return memory*2;
58}
59
60int unattended_setup(struct keyvalue *unattendedkv) {
61 struct keyvalue *mainsettings = initkeyvalues();
62 struct keyvalue *ethernetkv = initkeyvalues();
63 FILE *file, *hosts;
64 char commandstring[STRING_SIZE];
65
66 char domainname[STRING_SIZE];
67 char hostname[STRING_SIZE];
68 char keymap[STRING_SIZE];
69 char language[STRING_SIZE];
70 char timezone[STRING_SIZE];
71 char theme[STRING_SIZE];
72 char green_address[STRING_SIZE];
73 char green_netmask[STRING_SIZE];
74 char green_netaddress[STRING_SIZE];
75 char green_broadcast[STRING_SIZE];
76 char root_password[STRING_SIZE];
77 char admin_password[STRING_SIZE];
78
79 findkey(unattendedkv, "DOMAINNAME", domainname);
80 findkey(unattendedkv, "HOSTNAME", hostname);
81 findkey(unattendedkv, "KEYMAP", keymap);
82 findkey(unattendedkv, "LANGUAGE", language);
83 findkey(unattendedkv, "TIMEZONE", timezone);
84 findkey(unattendedkv, "THEME", theme);
85 findkey(unattendedkv, "GREEN_ADDRESS", green_address);
86 findkey(unattendedkv, "GREEN_NETMASK", green_netmask);
87 findkey(unattendedkv, "GREEN_NETADDRESS", green_netaddress);
88 findkey(unattendedkv, "GREEN_BROADCAST", green_broadcast);
89 findkey(unattendedkv, "ROOT_PASSWORD", root_password);
90 findkey(unattendedkv, "ADMIN_PASSWORD", admin_password);
91
92 /* write main/settings. */
93 replacekeyvalue(mainsettings, "DOMAINNAME", domainname);
94 replacekeyvalue(mainsettings, "HOSTNAME", hostname);
95 replacekeyvalue(mainsettings, "KEYMAP", keymap);
96 replacekeyvalue(mainsettings, "LANGUAGE", language);
97 replacekeyvalue(mainsettings, "TIMEZONE", timezone);
98 replacekeyvalue(mainsettings, "THEME", theme);
99 writekeyvalues(mainsettings, "/harddisk" CONFIG_ROOT "/main/settings");
100 freekeyvalues(mainsettings);
101
102 /* do setup stuff */
103 fprintf(flog, "unattended: Starting setup\n");
104
105 /* network */
106 fprintf(flog, "unattended: setting up network configuration\n");
107
108 (void) readkeyvalues(ethernetkv, "/harddisk" CONFIG_ROOT "/ethernet/settings");
109 replacekeyvalue(ethernetkv, "GREEN_ADDRESS", green_address);
110 replacekeyvalue(ethernetkv, "GREEN_NETMASK", green_netmask);
111 replacekeyvalue(ethernetkv, "GREEN_NETADDRESS", green_netaddress);
112 replacekeyvalue(ethernetkv, "GREEN_BROADCAST", green_broadcast);
113 replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0");
114 replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0");
115 write_ethernet_configs(ethernetkv);
116 freekeyvalues(ethernetkv);
117
118 /* timezone */
119 unlink("/harddisk/etc/localtime");
120 snprintf(commandstring, STRING_SIZE, "/harddisk/%s", timezone);
121 link(commandstring, "/harddisk/etc/localtime");
122
123 /* hostname */
124 fprintf(flog, "unattended: writing hostname.conf\n");
125 if (!(file = fopen("/harddisk" CONFIG_ROOT "/main/hostname.conf", "w")))
126 {
127 errorbox("unattended: ERROR writing hostname.conf");
128 return 0;
129 }
130 fprintf(file, "ServerName %s\n", hostname);
131 fclose(file);
132
133 fprintf(flog, "unattended: writing hosts\n");
134 if (!(hosts = fopen("/harddisk/etc/hosts", "w")))
135 {
136 errorbox("unattended: ERROR writing hosts");
137 return 0;
138 }
139 fprintf(hosts, "127.0.0.1\tlocalhost\n");
140 fprintf(hosts, "%s\t%s.%s\t%s\n", green_address, hostname, domainname, hostname);
141 fclose(hosts);
142
143 fprintf(flog, "unattended: writing hosts.allow\n");
144 if (!(file = fopen("/harddisk/etc/hosts.allow", "w")))
145 {
146 errorbox("unattended: ERROR writing hosts.allow");
147 return 0;
148 }
149 fprintf(file, "sshd : ALL\n");
150 fprintf(file, "ALL : localhost\n");
151 fprintf(file, "ALL : %s/%s\n", green_netaddress, green_netmask);
152 fclose(file);
153
154 fprintf(flog, "unattended: writing hosts.deny\n");
155 if (!(file = fopen("/harddisk/etc/hosts.deny", "w")))
156 {
157 errorbox("unattended: ERROR writing hosts.deny");
158 return 0;
159 }
160 fprintf(file, "ALL : ALL\n");
161 fclose(file);
162
163 /* set root password */
164 fprintf(flog, "unattended: setting root password\n");
165 snprintf(commandstring, STRING_SIZE,
166 "/sbin/chroot /harddisk /bin/sh -c \"echo 'root:%s' | /usr/sbin/chpasswd\"", root_password);
167 if (mysystem(commandstring)) {
168 errorbox("unattended: ERROR setting root password");
169 return 0;
170 }
171
172 /* set admin password */
173 fprintf(flog, "unattended: setting admin password\n");
174 snprintf(commandstring, STRING_SIZE,
175 "/sbin/chroot /harddisk /usr/sbin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", admin_password);
176 if (mysystem(commandstring)) {
177 errorbox("unattended: ERROR setting admin password");
178 return 0;
179 }
180 return 1;
181}
182
183int main(int argc, char *argv[])
184{
185 char *langnames[] = { "Deutsch", "English", NULL };
186 char *shortlangnames[] = { "de", "en", NULL };
187 char **langtrs[] = { de_tr, en_tr, NULL };
188 char hdletter, cdletter;
189 char harddrive[5], sourcedrive[5]; /* Device holder. */
190 struct devparams hdparams, cdromparams; /* Params for CDROM and HD */
191 int cdmounted = 0; /* Loop flag for inserting a cd. */
192 int rc = 0;
193 char commandstring[STRING_SIZE];
194 char *installtypes[] = { "CDROM/USB", "HTTP/FTP", NULL };
195 int installtype = CDROM_INSTALL;
196 char insertmessage[STRING_SIZE];
197 char insertdevnode[STRING_SIZE];
198 int choice;
199 char shortlangname[10];
200 char message[1000];
201 char title[STRING_SIZE];
202 int allok = 0;
203 int allok_fastexit=0;
204 int unmount_before=0;
205 struct keyvalue *ethernetkv = initkeyvalues();
206 FILE *handle, *cmdfile;
207 char line[STRING_SIZE];
208 char string[STRING_SIZE];
209 long maximum_free = 0, current_free;
210 long memory = 0;
211 long system_partition, boot_partition, root_partition, swap_file;
212 int scsi_disk = 0;
213 int pcmcia_disk = 0;
214 int pcmcia_cdrom = 0;
215 int scsi_cdrom = 0;
216 int ide_cdrom = 0;
217 int fdisk = 0;
218 int hardyn = 0;
219 char *yesnoharddisk[] = { "NO", "YES", NULL };
220 char *yesno[] = { "NO", "YES", NULL };
221 char green[STRING_SIZE];
222 int unattended = 0;
223 struct keyvalue *unattendedkv = initkeyvalues();
224 char packages[STRING_SIZE];
225 int serial_console = 0;
226 char megabridge[STRING_SIZE];
227
228 setlocale (LC_ALL, "");
229 sethostname( SNAME , 10);
230
231 memset(&hdparams, 0, sizeof(struct devparams));
232 memset(&cdromparams, 0, sizeof(struct devparams));
233
234 /* Log file/terminal stuff. */
235 if (argc >= 2)
236 {
237 if (!(flog = fopen(argv[1], "w+")))
238 return 0;
239 }
240 else
241 return 0;
242
243 mylog = argv[1];
244
245 fprintf(flog, "Install program started.\n");
246
247 newtInit();
248 newtCls();
249
250 /* Do usb detection first for usb keyboard */
251 if (! (cmdfile = fopen("/proc/cmdline", "r")))
252 {
253 fprintf(flog, "Couldn't open commandline: /proc/cmdline\n");
254 } else {
255 fgets(line, STRING_SIZE, cmdfile);
256 if (strstr (line, "nousb") == NULL) {
257 fprintf(flog, "Initializing USB controllers.\n");
258 initialize_usb();
259 } else {
260 fprintf(flog, "Skipping USB detection.\n");
261 }
262 // check if we have to make an unattended install
263 if (strstr (line, "unattended") != NULL) {
264 unattended = 1;
265 }
266 }
267
268 // make some beeps before wiping the system :)
269 if (unattended) {
270 runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds...");
271 }
272
273 /* German is the default */
274 for (choice = 0; langnames[choice]; choice++)
275 {
276 if (strcmp(langnames[choice], "Deutsch") == 0)
277 break;
278 }
279 if (!langnames[choice])
280 goto EXIT;
281
282 if (!unattended) {
283 rc = newtWinMenu("Language selection",
284 "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8,
285 langnames, &choice, "Ok", NULL);
286 }
287
288 ctr = langtrs[choice];
289 strcpy(shortlangname, shortlangnames[choice]);
290
291 mysystem("/bin/setfont lat0-16");
292
293 newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN );
294 newtPushHelpLine(ctr[TR_HELPLINE]);
295 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
296
297 if (!unattended) {
298 sprintf(message, ctr[TR_WELCOME], NAME);
299 newtWinMessage(title, ctr[TR_OK], message);
300
301 sprintf(message, ctr[TR_SELECT_INSTALLATION_MEDIA_LONG], NAME);
302 rc = newtWinMenu(ctr[TR_SELECT_INSTALLATION_MEDIA], message,
303 50, 5, 5, 6, installtypes, &installtype, ctr[TR_OK],
304 ctr[TR_CANCEL], NULL);
305 }
306 else {
307 rc = 1;
308 installtype = CDROM_INSTALL;
309 }
310
311 if (rc == 2)
312 goto EXIT;
313
314 // Starting hardware detection
315 runcommandwithstatus("/bin/probehw.sh", ctr[TR_PROBING_HARDWARE]);
316
317 /* CDROM INSTALL */
318 if (installtype == CDROM_INSTALL) {
319
320 switch (mysystem("/bin/mountsource.sh")) {
321 case 0:
322 installtype = CDROM_INSTALL;
323 cdmounted = 1;
324 break;
325 case 1:
326 installtype = DISK_INSTALL;
327 break;
328 case 10:
329 errorbox(ctr[TR_NO_CDROM]);
330 goto EXIT;
331 }
332
333 /* read source drive letter */
334 if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
335 errorbox(ctr[TR_ERROR_PROBING_CDROM]);
336 goto EXIT;
337 }
338 fgets(sourcedrive, 5, handle);
339 fprintf(flog, "Source drive: %s\n", sourcedrive);
340 fclose(handle);
341
342 snprintf(cdromparams.devnode, STRING_SIZE, "/dev/%s", sourcedrive);
343 cdromparams.module = 0;
344 fprintf(flog, "Source device: %s\n", cdromparams.devnode);
345 }
346
347 /* Configure the network now! */
348 if (installtype == URL_INSTALL) {
349 /* Network driver and params. */
350 if (!(networkmenu(ethernetkv))) {
351 errorbox(ctr[TR_NETWORK_SETUP_FAILED]);
352 goto EXIT;
353 }
354
355 /* Check for ipcop-<VERSION>.tbz2 */
356 if (checktarball(SNAME "-" VERSION ".tbz2", ctr[TR_ENTER_URL])) {
357 errorbox(ctr[TR_NO_IPCOP_TARBALL_FOUND]);
358 goto EXIT;
359 }
360 }
361
362 /* Get device for the HD. This has to succeed. */
363 if (!(hdletter = findidetype(IDE_HD)))
364 {
365 /* Need to clean this up at some point */
366 if (!try_scsi("sda") || strstr(sourcedrive, "sda") != NULL) {
367 if (!try_scsi("ida/c0d0")) {
368 if (!try_scsi("cciss/c0d0")) {
369 if (!try_scsi("rd/c0d0")) {
370 if (!try_scsi("ataraid/d0")) {
371 errorbox(ctr[TR_NO_HARDDISK]);
372 goto EXIT;
373 } else {
374 raid_disk = 1;
375 sprintf(harddrive, "ataraid/d0");
376 }
377 } else {
378 raid_disk = 1;
379 sprintf(harddrive, "rd/c0d0");
380 }
381 } else {
382 raid_disk = 1;
383 sprintf(harddrive, "cciss/c0d0");
384 }
385 } else {
386 raid_disk = 1;
387 sprintf(harddrive, "ida/c0d0");
388 }
389 } else {
390 if (strstr(sourcedrive, "sda") != NULL) {
391 // probably installing from usb stick, try sdb
392 if (try_scsi("sdb")) {
393 sprintf(harddrive, "sdb");
394 }
395 else {
396 errorbox(ctr[TR_NO_HARDDISK]);
397 goto EXIT;
398 }
399 }
400 else {
401 sprintf(harddrive, "sda");
402 }
403 }
404 scsi_disk = 1;
405 } else
406 sprintf(harddrive, "hd%c", hdletter);
407
408 fprintf(flog, "Destination drive: %s\n", harddrive);
409
410 /* load unattended configuration */
411 if (unattended) {
412 fprintf(flog, "unattended: Reading unattended.conf\n");
413
414 (void) readkeyvalues(unattendedkv, UNATTENDED_CONF);
415 }
416
417 /* Make the hdparms struct and print the contents. */
418 snprintf(hdparams.devnode, STRING_SIZE, "/dev/%s", harddrive);
419 hdparams.module = 0;
420
421 sprintf(message, ctr[TR_PREPARE_HARDDISK], hdparams.devnode);
422
423 if (unattended) {
424 hardyn = 1;
425 }
426
427 while (! hardyn) {
428 rc = newtWinMenu(title, message,
429 50, 5, 5, 6, yesnoharddisk,
430 &hardyn, ctr[TR_OK],
431 ctr[TR_CANCEL], NULL);
432 if (rc == 2)
433 goto EXIT;
434 }
435
436 if (rc == 2)
437 goto EXIT;
438
439 /* Calculate amount of memory in machine */
440 if ((handle = fopen("/proc/meminfo", "r")))
441 {
442 while (fgets(line, STRING_SIZE-1, handle)) {
443 if (sscanf (line, "MemTotal: %s kB", string)) {
444 memory = atoi(string) / 1024 ;
445 }
446 }
447 fclose(handle);
448 }
449
450 /* Partition, mkswp, mkfs.
451 * before partitioning, first determine the sizes of each
452 * partition. In order to do that we need to know the size of
453 * the disk.
454 */
455 /* Don't use mysystem here so we can redirect output */
456 sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /tmp/disksize 2> /dev/null", harddrive);
457 system(commandstring);
458
459 /* Calculate amount of disk space */
460 if ((handle = fopen("/tmp/disksize", "r")))
461 {
462 fgets(line, STRING_SIZE-1, handle);
463 if (sscanf (line, "%s", string)) {
464 maximum_free = atoi(string) / 1024;
465 }
466 fclose(handle);
467 }
468
469 fprintf(flog, "maximum_free = %ld, memory = %ld",
470 maximum_free, memory);
471
472 swap_file = calc_swapsize(memory, maximum_free);
473
474 if (maximum_free < 512 + swap_file ) {
475 if (maximum_free < 512) {
476 errorbox(ctr[TR_DISK_TOO_SMALL]);
477 goto EXIT;
478 }
479
480 if (!unattended) {
481 rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]);
482 }
483 else {
484 rc = 1;
485 }
486
487 if (rc != 1)
488 goto EXIT;
489 swap_file = 0;
490 }
491
492 boot_partition = 20; /* in MB */
493 current_free = maximum_free - boot_partition - swap_file;
494
495 root_partition = 2048 ;
496 if (current_free < 512) {
497 errorbox(ctr[TR_DISK_TOO_SMALL]);
498 goto EXIT;
499 }
500
501 current_free = current_free - root_partition;
502 if (!swap_file) {
503 root_partition = root_partition + swap_file;
504 }
505
506 system_partition = current_free;
507
508 fprintf(flog, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n",
509 boot_partition, swap_file, system_partition, root_partition);
510
511 handle = fopen("/tmp/partitiontable", "w");
512
513 /* Make swapfile */
514 if (swap_file) {
515 fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n",
516 boot_partition, swap_file, root_partition);
517 } else {
518 fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n",
519 boot_partition, root_partition);
520 }
521
522 fclose(handle);
523
524 snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams.devnode);
525 if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK]))
526 {
527 errorbox(ctr[TR_UNABLE_TO_PARTITION]);
528 goto EXIT;
529 }
530
531 mysystem("/sbin/udevstart");
532
533 if (raid_disk)
534 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %sp1", hdparams.devnode);
535 else
536 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %s1", hdparams.devnode);
537 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM]))
538 {
539 errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]);
540 goto EXIT;
541 }
542
543 if (swap_file) {
544 if (raid_disk)
545 snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %sp2", hdparams.devnode);
546 else
547 snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %s2", hdparams.devnode);
548 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE]))
549 {
550 errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]);
551 goto EXIT;
552 }
553 }
554
555 if (raid_disk)
556 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %sp3", hdparams.devnode);
557 else
558 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s3", hdparams.devnode);
559
560 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM]))
561 {
562 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
563 goto EXIT;
564 }
565
566 if (raid_disk)
567 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %sp4", hdparams.devnode);
568 else
569 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s4", hdparams.devnode);
570
571 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM]))
572 {
573 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
574 goto EXIT;
575 }
576
577 /* Mount harddisk. */
578 if (raid_disk)
579 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp3 /harddisk", hdparams.devnode);
580 else
581 snprintf(commandstring, STRING_SIZE, "/bin/mount %s3 /harddisk", hdparams.devnode);
582 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM]))
583 {
584 errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]);
585 goto EXIT;
586 }
587
588 mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO);
589 mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO);
590 mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO);
591
592 if (raid_disk)
593 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp1 /harddisk/boot", hdparams.devnode);
594 else
595 snprintf(commandstring, STRING_SIZE, "/bin/mount %s1 /harddisk/boot", hdparams.devnode);
596
597 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM]))
598 {
599 errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]);
600 goto EXIT;
601 }
602 if (swap_file) {
603 if (raid_disk)
604 snprintf(commandstring, STRING_SIZE, "/sbin/swapon %sp2", hdparams.devnode);
605 else
606 snprintf(commandstring, STRING_SIZE, "/sbin/swapon %s2", hdparams.devnode);
607 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION]))
608 {
609 errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]);
610 goto EXIT;
611 }
612 }
613 if (raid_disk)
614 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp4 /harddisk/var", hdparams.devnode);
615 else
616 snprintf(commandstring, STRING_SIZE, "/bin/mount %s4 /harddisk/var", hdparams.devnode);
617 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM]))
618 {
619 errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]);
620 goto EXIT;
621 }
622
623 snprintf(commandstring, STRING_SIZE, "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME "-" VERSION ".tbz2");
624
625 if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
626 ctr[TR_INSTALLING_FILES]))
627 {
628 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
629 goto EXIT;
630 }
631
632 /* Save USB controller type to modules.conf */
633 write_usb_modules_conf();
634
635 /* touch the modules.dep files */
636 snprintf(commandstring, STRING_SIZE,
637 "/sbin/chroot /harddisk /usr/bin/touch /lib/modules/%s/modules.dep",
638 KERNEL_VERSION);
639 mysystem(commandstring);
640 snprintf(commandstring, STRING_SIZE,
641 "/sbin/chroot /harddisk /usr/bin/touch /lib/modules/%s-smp/modules.dep",
642 KERNEL_VERSION);
643 mysystem(commandstring);
644
645 /* Rename uname */
646 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
647
648 /* *always* write disk configuration */
649 if (!(write_disk_configs(&hdparams))){
650 errorbox(ctr[TR_ERROR_WRITING_CONFIG]);
651 goto EXIT;
652 }
653
654 /* mount proc filesystem */
655 mysystem("mkdir /harddisk/proc");
656 mysystem("/bin/mount -t proc none /harddisk/proc");
657 mysystem("/bin/mount --bind /dev /harddisk/dev");
658
659
660 /* if we detected SCSI then fixup */
661 /* doesn't really work cause it sometimes creates a ramdisk on ide systems */
662/* mysystem("/bin/probecntrl.sh");
663 if ((handle = fopen("/cntrldriver", "r")))
664 {
665 char *driver;
666 fgets(line, STRING_SIZE-1, handle);
667 fclose(handle);
668 line[strlen(line) - 1] = 0;
669 driver = strtok(line, ".");
670 fprintf(flog, "Detected SCSI driver %s\n",driver);
671 if (strlen(driver) > 1) {
672 fprintf(flog, "Fixing up ipfirerd.img\n");
673 mysystem("/sbin/chroot /harddisk /sbin/modprobe loop");
674 mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
675 snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /sbin/mkinitrd --with=scsi_mod --with=%s --with=sd_mod --with=sr_mod --with=libata /boot/ipfirerd.img %s", driver, KERNEL_VERSION);
676 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
677 snprintf(commandstring, STRING_SIZE, "/sbin/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);
678 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
679 mysystem("/sbin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
680 }
681 } */
682
683 /* Build cache lang file */
684 snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
685 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE]))
686 {
687 errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]);
688 goto EXIT;
689 }
690
691 if (raid_disk)
692 sprintf(string, "root=%sp3", hdparams.devnode);
693 else
694 sprintf(string, "root=%s3", hdparams.devnode);
695 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string);
696 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode);
697
698 /* restore permissions */
699 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH);
700
701 snprintf(commandstring, STRING_SIZE,
702 "/sbin/chroot /harddisk /boot/grub/grubbatch");
703 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) {
704 errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
705 goto EXIT;
706 }
707
708 /* Update /etc/fstab */
709 replace( "/harddisk/etc/fstab", "DEVICE", hdparams.devnode);
710
711 /* Install bootsplash */
712 mysystem("/bin/installbootsplash.sh");
713
714 mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst");
715 mysystem("umount /harddisk/proc");
716 mysystem("umount /harddisk/dev");
717
718 if (!unattended) {
719 sprintf(message, ctr[TR_CONGRATULATIONS_LONG],
720 NAME, SNAME, SNAME, NAME, NAME, NAME);
721 newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message);
722 }
723
724 allok = 1;
725
726EXIT:
727 fprintf(flog, "Install program ended.\n");
728 fflush(flog);
729 fclose(flog);
730
731 if (!(allok))
732 newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]);
733
734 newtFinished();
735
736 freekeyvalues(ethernetkv);
737
738 if (allok && !allok_fastexit)
739 {
740 /* /proc is needed by the module checker. We have to mount it
741 * so it can be seen by setup, which is run chrooted. */
742 if (system("/bin/mount proc -t proc /harddisk/proc"))
743 printf("Unable to mount proc in /harddisk.");
744 else
745 {
746
747 if (!unattended) {
748 if (system("/sbin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
749 printf("Unable to run setup.\n");
750 }
751 else {
752 fprintf(flog, "Entering unattended setup\n");
753 unattended_setup(unattendedkv);
754 snprintf(commandstring, STRING_SIZE, "/bin/sleep 10");
755 runcommandwithstatus(commandstring, "Unattended installation finished, system will reboot");
756 }
757
758 if (system("/bin/umount /harddisk/proc"))
759 printf("Unable to umount /harddisk/proc.\n");
760 }
761 }
762
763 fcloseall();
764
765 if (swap_file) {
766 if (raid_disk)
767 snprintf(commandstring, STRING_SIZE, "/bin/swapoff %sp2", hdparams.devnode);
768 else
769 snprintf(commandstring, STRING_SIZE, "/bin/swapoff %s2", hdparams.devnode);
770 }
771
772 newtFinished();
773
774 system("/bin/umount /harddisk/var");
775 system("/bin/umount /harddisk/boot");
776 system("/bin/umount /harddisk");
777
778 system("/etc/halt");
779
780 return 0;
781}