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