Neue Hardwareerkennung im Installer...
[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 16#define DISK_INSTALL 2
9833e7d8 17#define INST_FILECOUNT 7000
33634aa8 18#define UNATTENDED_CONF "/cdrom/boot/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
72d80898
MT
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];
a1055a1c 71 char theme[STRING_SIZE];
72d80898
MT
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];
72d80898
MT
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);
a1055a1c 84 findkey(unattendedkv, "THEME", theme);
72d80898
MT
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);
72d80898
MT
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);
a1055a1c 98 replacekeyvalue(mainsettings, "THEME", theme);
72d80898
MT
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 */
72d80898
MT
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");
8e2e5cf3 114 replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0");
72d80898
MT
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);
3a1019f6 131 fclose(file);
72d80898
MT
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);
3a1019f6 141 fclose(hosts);
72d80898
MT
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");
edd536b6 147 return 0;
72d80898
MT
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
72d80898
MT
163 /* set root password */
164 fprintf(flog, "unattended: setting root password\n");
72d80898 165 snprintf(commandstring, STRING_SIZE,
532a3663 166 "/sbin/chroot /harddisk /bin/sh -c \"echo 'root:%s' | /usr/sbin/chpasswd\"", root_password);
72d80898
MT
167 if (mysystem(commandstring)) {
168 errorbox("unattended: ERROR setting root password");
169 return 0;
170 }
3a1019f6 171
72d80898
MT
172 /* set admin password */
173 fprintf(flog, "unattended: setting admin password\n");
174 snprintf(commandstring, STRING_SIZE,
3a1019f6 175 "/sbin/chroot /harddisk /usr/sbin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", admin_password);
72d80898
MT
176 if (mysystem(commandstring)) {
177 errorbox("unattended: ERROR setting admin password");
3a1019f6 178 return 0;
72d80898 179 }
3a1019f6 180 return 1;
72d80898
MT
181}
182
d6aaa55d
MT
183int main(int argc, char *argv[])
184{
b4e3cd7f
HS
185 char *langnames[] = { "Deutsch", "English", NULL };
186 char *shortlangnames[] = { "de", "en", NULL };
187 char **langtrs[] = { de_tr, en_tr, NULL };
d6aaa55d 188 char hdletter, cdletter;
72d80898
MT
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;
d6aaa55d 193 char commandstring[STRING_SIZE];
aa2870e6 194 char *installtypes[] = { "CDROM/USB", "HTTP/FTP", NULL };
72d80898 195 int installtype = CDROM_INSTALL;
d6aaa55d
MT
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;
10bc6f06 203 int allok_fastexit=0;
d6aaa55d
MT
204 int unmount_before=0;
205 struct keyvalue *ethernetkv = initkeyvalues();
206 FILE *handle, *cmdfile;
207 char line[STRING_SIZE];
208 char string[STRING_SIZE];
72d80898
MT
209 long maximum_free = 0, current_free;
210 long memory = 0;
8e2e5cf3 211 long system_partition, boot_partition, root_partition, swap_file;
d6aaa55d
MT
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;
72d80898
MT
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];
d6aaa55d
MT
227
228 setlocale (LC_ALL, "");
10bc6f06 229 sethostname( SNAME , 10);
72d80898 230
d6aaa55d
MT
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);
d6aaa55d
MT
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 }
72d80898
MT
262 // check if we have to make an unattended install
263 if (strstr (line, "unattended") != NULL) {
264 unattended = 1;
265 }
d6aaa55d 266 }
72d80898
MT
267
268 // make some beeps before wiping the system :)
269 if (unattended) {
33634aa8 270 runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds...");
72d80898 271 }
d6aaa55d 272
72d80898 273 /* German is the default */
d6aaa55d
MT
274 for (choice = 0; langnames[choice]; choice++)
275 {
b4e3cd7f 276 if (strcmp(langnames[choice], "Deutsch") == 0)
d6aaa55d
MT
277 break;
278 }
279 if (!langnames[choice])
280 goto EXIT;
281
72d80898
MT
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
d6aaa55d
MT
288 ctr = langtrs[choice];
289 strcpy(shortlangname, shortlangnames[choice]);
3d6e1202
MT
290
291 mysystem("/bin/setfont lat0-16");
72d80898 292
33634aa8 293 newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN );
d6aaa55d 294 newtPushHelpLine(ctr[TR_HELPLINE]);
4809e64e 295 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
d6aaa55d 296
72d80898
MT
297 if (!unattended) {
298 sprintf(message, ctr[TR_WELCOME], NAME);
72d80898
MT
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
9607771a
MT
317 /* CDROM INSTALL */
318 if (installtype == CDROM_INSTALL) {
72d80898 319
9607771a
MT
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 */
0b59f25c 334 if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
33634aa8
MT
335 errorbox(ctr[TR_ERROR_PROBING_CDROM]);
336 goto EXIT;
9607771a
MT
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);
72d80898 345 }
9607771a
MT
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 }
72d80898
MT
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
9607771a 408 fprintf(flog, "Destination drive: %s\n", harddrive);
d6aaa55d 409
72d80898
MT
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 }
5433e2c9
MT
435
436 if (rc == 2)
437 goto EXIT;
72d80898
MT
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 */
0b59f25c 456 sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /tmp/disksize 2> /dev/null", harddrive);
72d80898
MT
457 system(commandstring);
458
459 /* Calculate amount of disk space */
0b59f25c 460 if ((handle = fopen("/tmp/disksize", "r")))
72d80898
MT
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
8e2e5cf3 492 boot_partition = 20; /* in MB */
72d80898
MT
493 current_free = maximum_free - boot_partition - swap_file;
494
8e2e5cf3
MT
495 root_partition = 2048 ;
496 if (current_free < 512) {
72d80898
MT
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
8e2e5cf3 506 system_partition = current_free;
72d80898
MT
507
508 fprintf(flog, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n",
8e2e5cf3 509 boot_partition, swap_file, system_partition, root_partition);
72d80898
MT
510
511 handle = fopen("/tmp/partitiontable", "w");
512
72d80898
MT
513 /* Make swapfile */
514 if (swap_file) {
9607771a 515 fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n",
72d80898
MT
516 boot_partition, swap_file, root_partition);
517 } else {
9607771a 518 fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n",
72d80898
MT
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
532a3663 531 mysystem("/sbin/udevstart");
72d80898
MT
532
533 if (raid_disk)
8e2e5cf3 534 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %sp1", hdparams.devnode);
72d80898 535 else
8e2e5cf3 536 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %s1", hdparams.devnode);
72d80898
MT
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)
532a3663 545 snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %sp2", hdparams.devnode);
72d80898 546 else
532a3663 547 snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %s2", hdparams.devnode);
72d80898
MT
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)
76ed51e8 556 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %sp3", hdparams.devnode);
72d80898 557 else
76ed51e8 558 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s3", hdparams.devnode);
72d80898
MT
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
9607771a 566 if (raid_disk)
76ed51e8 567 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %sp4", hdparams.devnode);
72d80898 568 else
76ed51e8 569 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s4", hdparams.devnode);
72d80898
MT
570
571 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM]))
572 {
573 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
574 goto EXIT;
9607771a 575 }
72d80898
MT
576
577 /* Mount harddisk. */
578 if (raid_disk)
532a3663 579 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp3 /harddisk", hdparams.devnode);
72d80898 580 else
532a3663 581 snprintf(commandstring, STRING_SIZE, "/bin/mount %s3 /harddisk", hdparams.devnode);
72d80898
MT
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)
532a3663 593 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp1 /harddisk/boot", hdparams.devnode);
72d80898 594 else
532a3663 595 snprintf(commandstring, STRING_SIZE, "/bin/mount %s1 /harddisk/boot", hdparams.devnode);
72d80898
MT
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)
532a3663 604 snprintf(commandstring, STRING_SIZE, "/sbin/swapon %sp2", hdparams.devnode);
72d80898 605 else
532a3663 606 snprintf(commandstring, STRING_SIZE, "/sbin/swapon %s2", hdparams.devnode);
72d80898
MT
607 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION]))
608 {
609 errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]);
610 goto EXIT;
611 }
612 }
9607771a 613 if (raid_disk)
532a3663 614 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp4 /harddisk/var", hdparams.devnode);
72d80898 615 else
532a3663 616 snprintf(commandstring, STRING_SIZE, "/bin/mount %s4 /harddisk/var", hdparams.devnode);
72d80898
MT
617 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM]))
618 {
619 errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]);
620 goto EXIT;
9607771a 621 }
10bc6f06 622
8e2e5cf3 623 snprintf(commandstring, STRING_SIZE, "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME "-" VERSION ".tbz2");
d6aaa55d 624
edd536b6
MT
625 if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
626 ctr[TR_INSTALLING_FILES]))
d6aaa55d
MT
627 {
628 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
629 goto EXIT;
630 }
e57bc1fd 631
d6aaa55d
MT
632 /* Save USB controller type to modules.conf */
633 write_usb_modules_conf();
634
635 /* touch the modules.dep files */
10bc6f06 636 snprintf(commandstring, STRING_SIZE,
532a3663 637 "/sbin/chroot /harddisk /usr/bin/touch /lib/modules/%s/modules.dep",
10bc6f06
MT
638 KERNEL_VERSION);
639 mysystem(commandstring);
10bc6f06 640 snprintf(commandstring, STRING_SIZE,
532a3663 641 "/sbin/chroot /harddisk /usr/bin/touch /lib/modules/%s-smp/modules.dep",
10bc6f06
MT
642 KERNEL_VERSION);
643 mysystem(commandstring);
d6aaa55d
MT
644
645 /* Rename uname */
646 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
647
d6aaa55d
MT
648 /* *always* write disk configuration */
649 if (!(write_disk_configs(&hdparams))){
10bc6f06
MT
650 errorbox(ctr[TR_ERROR_WRITING_CONFIG]);
651 goto EXIT;
d6aaa55d
MT
652 }
653
9607771a
MT
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
73d9a908 659
22b9e405 660 /* if we detected SCSI then fixup */
73d9a908
MT
661 /* doesn't really work cause it sometimes creates a ramdisk on ide systems */
662/* mysystem("/bin/probecntrl.sh");
9607771a 663 if ((handle = fopen("/cntrldriver", "r")))
22b9e405
MT
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");
532a3663 673 mysystem("/sbin/chroot /harddisk /sbin/modprobe loop");
22b9e405 674 mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
532a3663 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);
22b9e405 676 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
532a3663 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);
22b9e405 678 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
532a3663 679 mysystem("/sbin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
9607771a 680 }
73d9a908 681 } */
22b9e405 682
9607771a 683 /* Build cache lang file */
532a3663 684 snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
9607771a
MT
685 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE]))
686 {
687 errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]);
688 goto EXIT;
689 }
edd536b6
MT
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);
edd536b6 696 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode);
fd0763dc 697
edd536b6
MT
698 /* restore permissions */
699 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH);
700
edd536b6 701 snprintf(commandstring, STRING_SIZE,
532a3663 702 "/sbin/chroot /harddisk /boot/grub/grubbatch");
edd536b6
MT
703 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) {
704 errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
705 goto EXIT;
706 }
707
73d9a908
MT
708 /* Update /etc/fstab */
709 replace( "/harddisk/etc/fstab", "DEVICE", hdparams.devnode);
710
22b9e405
MT
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
73d9a908
MT
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 }
22b9e405
MT
723
724 allok = 1;
edd536b6 725
d6aaa55d 726EXIT:
10bc6f06 727 fprintf(flog, "Install program ended.\n");
d6aaa55d
MT
728 fflush(flog);
729 fclose(flog);
730
10bc6f06 731 if (!(allok))
d6aaa55d 732 newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]);
10bc6f06 733
d6aaa55d 734 newtFinished();
10bc6f06 735
d6aaa55d 736 freekeyvalues(ethernetkv);
d6aaa55d 737
10bc6f06 738 if (allok && !allok_fastexit)
d6aaa55d
MT
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. */
532a3663 742 if (system("/bin/mount proc -t proc /harddisk/proc"))
d6aaa55d
MT
743 printf("Unable to mount proc in /harddisk.");
744 else
745 {
3a1019f6
MT
746
747 if (!unattended) {
069680ac 748 if (system("/sbin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
3a1019f6
MT
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
532a3663 758 if (system("/bin/umount /harddisk/proc"))
d6aaa55d
MT
759 printf("Unable to umount /harddisk/proc.\n");
760 }
761 }
762
763 fcloseall();
764
3a1019f6
MT
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
532a3663
MT
774 system("/bin/umount /harddisk/var");
775 system("/bin/umount /harddisk/boot");
776 system("/bin/umount /harddisk");
10bc6f06 777
d6aaa55d
MT
778 system("/etc/halt");
779
780 return 0;
781}