eb5540a594cfc93c7a121968b62272e22f5509d3
[people/teissler/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 7000
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 long 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
60 int 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
183 int 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, "fdisk") != NULL) {
257 fprintf(flog, "Manual FDISK selected.\n");
258 fdisk = 1;
259 }
260 if (strstr (line, "nousb") == NULL) {
261 fprintf(flog, "Initializing USB controllers.\n");
262 initialize_usb();
263 } else {
264 fprintf(flog, "Skipping USB detection.\n");
265 }
266 // check if we have to make an unattended install
267 if (strstr (line, "unattended") != NULL) {
268 unattended = 1;
269 }
270 }
271
272 // make some beeps before wiping the system :)
273 if (unattended) {
274 runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds...");
275 }
276
277 /* German is the default */
278 for (choice = 0; langnames[choice]; choice++)
279 {
280 if (strcmp(langnames[choice], "Deutsch") == 0)
281 break;
282 }
283 if (!langnames[choice])
284 goto EXIT;
285
286 if (!unattended) {
287 rc = newtWinMenu("Language selection",
288 "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8,
289 langnames, &choice, "Ok", NULL);
290 }
291
292 ctr = langtrs[choice];
293 strcpy(shortlangname, shortlangnames[choice]);
294
295 mysystem("/bin/setfont lat0-16");
296
297 newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN );
298 newtPushHelpLine(ctr[TR_HELPLINE]);
299
300 if (!unattended) {
301 sprintf(message, ctr[TR_WELCOME], NAME);
302 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
303 newtWinMessage(title, ctr[TR_OK], message);
304
305 sprintf(message, ctr[TR_SELECT_INSTALLATION_MEDIA_LONG], NAME);
306 rc = newtWinMenu(ctr[TR_SELECT_INSTALLATION_MEDIA], message,
307 50, 5, 5, 6, installtypes, &installtype, ctr[TR_OK],
308 ctr[TR_CANCEL], NULL);
309 }
310 else {
311 rc = 1;
312 installtype = CDROM_INSTALL;
313 }
314
315 if (rc == 2)
316 goto EXIT;
317
318 // Starting hardware detection
319 runcommandwithstatus("/bin/probehw.sh", ctr[TR_PROBING_HARDWARE]);
320
321 /* CDROM INSTALL */
322 if (installtype == CDROM_INSTALL) {
323
324 switch (mysystem("/bin/mountsource.sh")) {
325 case 0:
326 installtype = CDROM_INSTALL;
327 cdmounted = 1;
328 break;
329 case 1:
330 installtype = DISK_INSTALL;
331 break;
332 case 10:
333 errorbox(ctr[TR_NO_CDROM]);
334 goto EXIT;
335 }
336
337 /* read source drive letter */
338 if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
339 errorbox(ctr[TR_ERROR_PROBING_CDROM]);
340 goto EXIT;
341 }
342 fgets(sourcedrive, 5, handle);
343 fprintf(flog, "Source drive: %s\n", sourcedrive);
344 fclose(handle);
345
346 snprintf(cdromparams.devnode, STRING_SIZE, "/dev/%s", sourcedrive);
347 cdromparams.module = 0;
348 fprintf(flog, "Source device: %s\n", cdromparams.devnode);
349 }
350
351 /* Configure the network now! */
352 if (installtype == URL_INSTALL) {
353 /* Network driver and params. */
354 if (!(networkmenu(ethernetkv))) {
355 errorbox(ctr[TR_NETWORK_SETUP_FAILED]);
356 goto EXIT;
357 }
358
359 /* Check for ipcop-<VERSION>.tbz2 */
360 if (checktarball(SNAME "-" VERSION ".tbz2", ctr[TR_ENTER_URL])) {
361 errorbox(ctr[TR_NO_IPCOP_TARBALL_FOUND]);
362 goto EXIT;
363 }
364 }
365
366 /* Get device for the HD. This has to succeed. */
367 if (!(hdletter = findidetype(IDE_HD)))
368 {
369 /* Need to clean this up at some point */
370 if (!try_scsi("sda") || strstr(sourcedrive, "sda") != NULL) {
371 if (!try_scsi("ida/c0d0")) {
372 if (!try_scsi("cciss/c0d0")) {
373 if (!try_scsi("rd/c0d0")) {
374 if (!try_scsi("ataraid/d0")) {
375 errorbox(ctr[TR_NO_HARDDISK]);
376 goto EXIT;
377 } else {
378 raid_disk = 1;
379 sprintf(harddrive, "ataraid/d0");
380 }
381 } else {
382 raid_disk = 1;
383 sprintf(harddrive, "rd/c0d0");
384 }
385 } else {
386 raid_disk = 1;
387 sprintf(harddrive, "cciss/c0d0");
388 }
389 } else {
390 raid_disk = 1;
391 sprintf(harddrive, "ida/c0d0");
392 }
393 } else {
394 if (strstr(sourcedrive, "sda") != NULL) {
395 // probably installing from usb stick, try sdb
396 if (try_scsi("sdb")) {
397 sprintf(harddrive, "sdb");
398 }
399 else {
400 errorbox(ctr[TR_NO_HARDDISK]);
401 goto EXIT;
402 }
403 }
404 else {
405 sprintf(harddrive, "sda");
406 }
407 }
408 scsi_disk = 1;
409 } else
410 sprintf(harddrive, "hd%c", hdletter);
411
412 fprintf(flog, "Destination drive: %s\n", harddrive);
413
414 /* load unattended configuration */
415 if (unattended) {
416 fprintf(flog, "unattended: Reading unattended.conf\n");
417
418 (void) readkeyvalues(unattendedkv, UNATTENDED_CONF);
419 }
420
421 /* Make the hdparms struct and print the contents. */
422 snprintf(hdparams.devnode, STRING_SIZE, "/dev/%s", harddrive);
423 hdparams.module = 0;
424
425 sprintf(message, ctr[TR_PREPARE_HARDDISK], hdparams.devnode);
426
427 if (unattended) {
428 hardyn = 1;
429 }
430
431 while (! hardyn) {
432 rc = newtWinMenu(title, message,
433 50, 5, 5, 6, yesnoharddisk,
434 &hardyn, ctr[TR_OK],
435 ctr[TR_CANCEL], NULL);
436 if (rc == 2)
437 goto EXIT;
438 }
439
440 if (rc == 2)
441 goto EXIT;
442
443 /* Calculate amount of memory in machine */
444 if ((handle = fopen("/proc/meminfo", "r")))
445 {
446 while (fgets(line, STRING_SIZE-1, handle)) {
447 if (sscanf (line, "MemTotal: %s kB", string)) {
448 memory = atoi(string) / 1024 ;
449 }
450 }
451 fclose(handle);
452 }
453
454 /* Partition, mkswp, mkfs.
455 * before partitioning, first determine the sizes of each
456 * partition. In order to do that we need to know the size of
457 * the disk.
458 */
459 /* Don't use mysystem here so we can redirect output */
460 sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /tmp/disksize 2> /dev/null", harddrive);
461 system(commandstring);
462
463 /* Calculate amount of disk space */
464 if ((handle = fopen("/tmp/disksize", "r")))
465 {
466 fgets(line, STRING_SIZE-1, handle);
467 if (sscanf (line, "%s", string)) {
468 maximum_free = atoi(string) / 1024;
469 }
470 fclose(handle);
471 }
472
473 fprintf(flog, "maximum_free = %ld, memory = %ld",
474 maximum_free, memory);
475
476 swap_file = calc_swapsize(memory, maximum_free);
477
478 if (maximum_free < 512 + swap_file ) {
479 if (maximum_free < 512) {
480 errorbox(ctr[TR_DISK_TOO_SMALL]);
481 goto EXIT;
482 }
483
484 if (!unattended) {
485 rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]);
486 }
487 else {
488 rc = 1;
489 }
490
491 if (rc != 1)
492 goto EXIT;
493 swap_file = 0;
494 }
495
496 boot_partition = 20; /* in MB */
497 current_free = maximum_free - boot_partition - swap_file;
498
499 root_partition = 2048 ;
500 if (current_free < 512) {
501 errorbox(ctr[TR_DISK_TOO_SMALL]);
502 goto EXIT;
503 }
504
505 current_free = current_free - root_partition;
506 if (!swap_file) {
507 root_partition = root_partition + swap_file;
508 }
509
510 system_partition = current_free;
511
512 fprintf(flog, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n",
513 boot_partition, swap_file, system_partition, root_partition);
514
515 handle = fopen("/tmp/partitiontable", "w");
516
517 /* Make swapfile */
518 if (swap_file) {
519 fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n",
520 boot_partition, swap_file, root_partition);
521 } else {
522 fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n",
523 boot_partition, root_partition);
524 }
525
526 fclose(handle);
527
528 snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams.devnode);
529 if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK]))
530 {
531 errorbox(ctr[TR_UNABLE_TO_PARTITION]);
532 goto EXIT;
533 }
534
535 mysystem("/sbin/udevstart");
536
537 if (raid_disk)
538 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %sp1", hdparams.devnode);
539 else
540 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %s1", hdparams.devnode);
541 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM]))
542 {
543 errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]);
544 goto EXIT;
545 }
546
547 if (swap_file) {
548 if (raid_disk)
549 snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %sp2", hdparams.devnode);
550 else
551 snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %s2", hdparams.devnode);
552 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE]))
553 {
554 errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]);
555 goto EXIT;
556 }
557 }
558
559 if (raid_disk)
560 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %sp3", hdparams.devnode);
561 else
562 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s3", hdparams.devnode);
563
564 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM]))
565 {
566 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
567 goto EXIT;
568 }
569
570 if (raid_disk)
571 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %sp4", hdparams.devnode);
572 else
573 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s4", hdparams.devnode);
574
575 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM]))
576 {
577 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
578 goto EXIT;
579 }
580
581 /* Mount harddisk. */
582 if (raid_disk)
583 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp3 /harddisk", hdparams.devnode);
584 else
585 snprintf(commandstring, STRING_SIZE, "/bin/mount %s3 /harddisk", hdparams.devnode);
586 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM]))
587 {
588 errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]);
589 goto EXIT;
590 }
591
592 mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO);
593 mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO);
594 mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO);
595
596 if (raid_disk)
597 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp1 /harddisk/boot", hdparams.devnode);
598 else
599 snprintf(commandstring, STRING_SIZE, "/bin/mount %s1 /harddisk/boot", hdparams.devnode);
600
601 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM]))
602 {
603 errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]);
604 goto EXIT;
605 }
606 if (swap_file) {
607 if (raid_disk)
608 snprintf(commandstring, STRING_SIZE, "/sbin/swapon %sp2", hdparams.devnode);
609 else
610 snprintf(commandstring, STRING_SIZE, "/sbin/swapon %s2", hdparams.devnode);
611 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION]))
612 {
613 errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]);
614 goto EXIT;
615 }
616 }
617 if (raid_disk)
618 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp4 /harddisk/var", hdparams.devnode);
619 else
620 snprintf(commandstring, STRING_SIZE, "/bin/mount %s4 /harddisk/var", hdparams.devnode);
621 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM]))
622 {
623 errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]);
624 goto EXIT;
625 }
626
627 snprintf(commandstring, STRING_SIZE, "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME "-" VERSION ".tbz2");
628
629 if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
630 ctr[TR_INSTALLING_FILES]))
631 {
632 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
633 goto EXIT;
634 }
635
636 /* Save USB controller type to modules.conf */
637 write_usb_modules_conf();
638
639 /* touch the modules.dep files */
640 snprintf(commandstring, STRING_SIZE,
641 "/sbin/chroot /harddisk /usr/bin/touch /lib/modules/%s/modules.dep",
642 KERNEL_VERSION);
643 mysystem(commandstring);
644 snprintf(commandstring, STRING_SIZE,
645 "/sbin/chroot /harddisk /usr/bin/touch /lib/modules/%s-smp/modules.dep",
646 KERNEL_VERSION);
647 mysystem(commandstring);
648
649 /* Rename uname */
650 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
651
652 /* *always* write disk configuration */
653 if (!(write_disk_configs(&hdparams))){
654 errorbox(ctr[TR_ERROR_WRITING_CONFIG]);
655 goto EXIT;
656 }
657
658 /* mount proc filesystem */
659 mysystem("mkdir /harddisk/proc");
660 mysystem("/bin/mount -t proc none /harddisk/proc");
661 mysystem("/bin/mount --bind /dev /harddisk/dev");
662
663
664 /* if we detected SCSI then fixup */
665 /* doesn't really work cause it sometimes creates a ramdisk on ide systems */
666 /* mysystem("/bin/probecntrl.sh");
667 if ((handle = fopen("/cntrldriver", "r")))
668 {
669 char *driver;
670 fgets(line, STRING_SIZE-1, handle);
671 fclose(handle);
672 line[strlen(line) - 1] = 0;
673 driver = strtok(line, ".");
674 fprintf(flog, "Detected SCSI driver %s\n",driver);
675 if (strlen(driver) > 1) {
676 fprintf(flog, "Fixing up ipfirerd.img\n");
677 mysystem("/sbin/chroot /harddisk /sbin/modprobe loop");
678 mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
679 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);
680 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
681 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);
682 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
683 mysystem("/sbin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
684 }
685 } */
686
687 /* Build cache lang file */
688 snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
689 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE]))
690 {
691 errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]);
692 goto EXIT;
693 }
694
695 if (raid_disk)
696 sprintf(string, "root=%sp3", hdparams.devnode);
697 else
698 sprintf(string, "root=%s3", hdparams.devnode);
699 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string);
700 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode);
701
702 /* restore permissions */
703 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH);
704
705 snprintf(commandstring, STRING_SIZE,
706 "/sbin/chroot /harddisk /boot/grub/grubbatch");
707 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) {
708 errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
709 goto EXIT;
710 }
711
712 /* Update /etc/fstab */
713 replace( "/harddisk/etc/fstab", "DEVICE", hdparams.devnode);
714
715 /* Install bootsplash */
716 mysystem("/bin/installbootsplash.sh");
717
718 mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst");
719 mysystem("umount /harddisk/proc");
720 mysystem("umount /harddisk/dev");
721
722 if (!unattended) {
723 sprintf(message, ctr[TR_CONGRATULATIONS_LONG],
724 NAME, SNAME, SNAME, NAME, NAME, NAME);
725 newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message);
726 }
727
728 allok = 1;
729
730 EXIT:
731 fprintf(flog, "Install program ended.\n");
732 fflush(flog);
733 fclose(flog);
734
735 if (!(allok))
736 newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]);
737
738 newtFinished();
739
740 freekeyvalues(ethernetkv);
741
742 if (allok && !allok_fastexit)
743 {
744 /* /proc is needed by the module checker. We have to mount it
745 * so it can be seen by setup, which is run chrooted. */
746 if (system("/bin/mount proc -t proc /harddisk/proc"))
747 printf("Unable to mount proc in /harddisk.");
748 else
749 {
750
751 if (!unattended) {
752 if (system("/sbin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
753 printf("Unable to run setup.\n");
754 }
755 else {
756 fprintf(flog, "Entering unattended setup\n");
757 unattended_setup(unattendedkv);
758 snprintf(commandstring, STRING_SIZE, "/bin/sleep 10");
759 runcommandwithstatus(commandstring, "Unattended installation finished, system will reboot");
760 }
761
762 if (system("/bin/umount /harddisk/proc"))
763 printf("Unable to umount /harddisk/proc.\n");
764 }
765 }
766
767 fcloseall();
768
769 if (swap_file) {
770 if (raid_disk)
771 snprintf(commandstring, STRING_SIZE, "/bin/swapoff %sp2", hdparams.devnode);
772 else
773 snprintf(commandstring, STRING_SIZE, "/bin/swapoff %s2", hdparams.devnode);
774 }
775
776 newtFinished();
777
778 system("/bin/umount /harddisk/var");
779 system("/bin/umount /harddisk/boot");
780 system("/bin/umount /harddisk");
781
782 system("/etc/halt");
783
784 return 0;
785 }