Alten PCMCIA Code aus dem Installer entfernt.
[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
d6aaa55d
MT
26extern char url[STRING_SIZE];
27
10bc6f06 28extern char *en_tr[];
10bc6f06 29extern char *de_tr[];
d6aaa55d 30
72d80898
MT
31int detect_smp() {
32 FILE *fd = NULL;
33 char line[STRING_SIZE];
34 int cpu_count = 0;
35
36 if ((fd = fopen("/proc/cpuinfo", "r")) == NULL) {
37 return 0;
38 }
39 while (fgets(line, STRING_SIZE, fd) != NULL) {
40 if (strstr(line, "processor") == line) {
41 cpu_count++;
42 }
43 }
44 (void)fclose(fd);
45 return (cpu_count > 1);
46}
47
72d80898
MT
48long calc_swapsize(long memory, long disk) {
49 if (memory < 128) {
50 return 256;
51 }
52 if (memory > 1024) {
53 return 512;
54 }
55
56 return memory*2;
57}
58
d6aaa55d
MT
59int main(int argc, char *argv[])
60{
b4e3cd7f
HS
61 char *langnames[] = { "Deutsch", "English", NULL };
62 char *shortlangnames[] = { "de", "en", NULL };
63 char **langtrs[] = { de_tr, en_tr, NULL };
c78a77eb 64 char hdletter;
72d80898
MT
65 char harddrive[5], sourcedrive[5]; /* Device holder. */
66 struct devparams hdparams, cdromparams; /* Params for CDROM and HD */
67 int cdmounted = 0; /* Loop flag for inserting a cd. */
68 int rc = 0;
d6aaa55d 69 char commandstring[STRING_SIZE];
aa2870e6 70 char *installtypes[] = { "CDROM/USB", "HTTP/FTP", NULL };
72d80898 71 int installtype = CDROM_INSTALL;
d6aaa55d
MT
72 int choice;
73 char shortlangname[10];
74 char message[1000];
75 char title[STRING_SIZE];
76 int allok = 0;
10bc6f06 77 int allok_fastexit=0;
d6aaa55d
MT
78 struct keyvalue *ethernetkv = initkeyvalues();
79 FILE *handle, *cmdfile;
80 char line[STRING_SIZE];
81 char string[STRING_SIZE];
72d80898
MT
82 long maximum_free = 0, current_free;
83 long memory = 0;
8e2e5cf3 84 long system_partition, boot_partition, root_partition, swap_file;
d6aaa55d 85 int scsi_disk = 0;
72d80898 86 char *yesnoharddisk[] = { "NO", "YES", NULL };
72d80898
MT
87 int unattended = 0;
88 struct keyvalue *unattendedkv = initkeyvalues();
c78a77eb 89 int hardyn = 0;
d6aaa55d
MT
90
91 setlocale (LC_ALL, "");
10bc6f06 92 sethostname( SNAME , 10);
72d80898 93
d6aaa55d
MT
94 memset(&hdparams, 0, sizeof(struct devparams));
95 memset(&cdromparams, 0, sizeof(struct devparams));
96
97 /* Log file/terminal stuff. */
98 if (argc >= 2)
99 {
100 if (!(flog = fopen(argv[1], "w+")))
101 return 0;
102 }
103 else
104 return 0;
105
106 mylog = argv[1];
107
108 fprintf(flog, "Install program started.\n");
109
110 newtInit();
111 newtCls();
112
113 /* Do usb detection first for usb keyboard */
114 if (! (cmdfile = fopen("/proc/cmdline", "r")))
115 {
116 fprintf(flog, "Couldn't open commandline: /proc/cmdline\n");
117 } else {
118 fgets(line, STRING_SIZE, cmdfile);
d6aaa55d
MT
119 if (strstr (line, "nousb") == NULL) {
120 fprintf(flog, "Initializing USB controllers.\n");
121 initialize_usb();
122 } else {
123 fprintf(flog, "Skipping USB detection.\n");
124 }
72d80898
MT
125 // check if we have to make an unattended install
126 if (strstr (line, "unattended") != NULL) {
127 unattended = 1;
128 }
d6aaa55d 129 }
72d80898
MT
130
131 // make some beeps before wiping the system :)
132 if (unattended) {
33634aa8 133 runcommandwithstatus("/bin/sleep 10", "WARNING: Unattended installation will start in 10 seconds...");
72d80898 134 }
d6aaa55d 135
72d80898 136 /* German is the default */
d6aaa55d
MT
137 for (choice = 0; langnames[choice]; choice++)
138 {
b4e3cd7f 139 if (strcmp(langnames[choice], "Deutsch") == 0)
d6aaa55d
MT
140 break;
141 }
142 if (!langnames[choice])
143 goto EXIT;
144
72d80898
MT
145 if (!unattended) {
146 rc = newtWinMenu("Language selection",
147 "Select the language you wish to use for the " NAME ".", 50, 5, 5, 8,
148 langnames, &choice, "Ok", NULL);
149 }
150
d6aaa55d
MT
151 ctr = langtrs[choice];
152 strcpy(shortlangname, shortlangnames[choice]);
3d6e1202
MT
153
154 mysystem("/bin/setfont lat0-16");
72d80898 155
33634aa8 156 newtDrawRootText(14, 0, NAME " " VERSION " - " SLOGAN );
d6aaa55d 157 newtPushHelpLine(ctr[TR_HELPLINE]);
4809e64e 158 sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
d6aaa55d 159
72d80898
MT
160 if (!unattended) {
161 sprintf(message, ctr[TR_WELCOME], NAME);
72d80898
MT
162 newtWinMessage(title, ctr[TR_OK], message);
163
164 sprintf(message, ctr[TR_SELECT_INSTALLATION_MEDIA_LONG], NAME);
165 rc = newtWinMenu(ctr[TR_SELECT_INSTALLATION_MEDIA], message,
166 50, 5, 5, 6, installtypes, &installtype, ctr[TR_OK],
167 ctr[TR_CANCEL], NULL);
168 }
169 else {
170 rc = 1;
171 installtype = CDROM_INSTALL;
172 }
173
174 if (rc == 2)
175 goto EXIT;
176
177 // Starting hardware detection
178 runcommandwithstatus("/bin/probehw.sh", ctr[TR_PROBING_HARDWARE]);
179
9607771a
MT
180 /* CDROM INSTALL */
181 if (installtype == CDROM_INSTALL) {
72d80898 182
9607771a
MT
183 switch (mysystem("/bin/mountsource.sh")) {
184 case 0:
185 installtype = CDROM_INSTALL;
186 cdmounted = 1;
187 break;
188 case 1:
189 installtype = DISK_INSTALL;
190 break;
191 case 10:
192 errorbox(ctr[TR_NO_CDROM]);
193 goto EXIT;
194 }
195
196 /* read source drive letter */
0b59f25c 197 if ((handle = fopen("/tmp/source_device", "r")) == NULL) {
33634aa8
MT
198 errorbox(ctr[TR_ERROR_PROBING_CDROM]);
199 goto EXIT;
9607771a
MT
200 }
201 fgets(sourcedrive, 5, handle);
202 fprintf(flog, "Source drive: %s\n", sourcedrive);
203 fclose(handle);
204
205 snprintf(cdromparams.devnode, STRING_SIZE, "/dev/%s", sourcedrive);
206 cdromparams.module = 0;
207 fprintf(flog, "Source device: %s\n", cdromparams.devnode);
72d80898 208 }
9607771a
MT
209
210 /* Configure the network now! */
211 if (installtype == URL_INSTALL) {
212 /* Network driver and params. */
213 if (!(networkmenu(ethernetkv))) {
214 errorbox(ctr[TR_NETWORK_SETUP_FAILED]);
215 goto EXIT;
216 }
217
218 /* Check for ipcop-<VERSION>.tbz2 */
219 if (checktarball(SNAME "-" VERSION ".tbz2", ctr[TR_ENTER_URL])) {
220 errorbox(ctr[TR_NO_IPCOP_TARBALL_FOUND]);
221 goto EXIT;
222 }
72d80898
MT
223 }
224
225 /* Get device for the HD. This has to succeed. */
226 if (!(hdletter = findidetype(IDE_HD)))
227 {
228 /* Need to clean this up at some point */
229 if (!try_scsi("sda") || strstr(sourcedrive, "sda") != NULL) {
230 if (!try_scsi("ida/c0d0")) {
231 if (!try_scsi("cciss/c0d0")) {
232 if (!try_scsi("rd/c0d0")) {
233 if (!try_scsi("ataraid/d0")) {
234 errorbox(ctr[TR_NO_HARDDISK]);
235 goto EXIT;
236 } else {
237 raid_disk = 1;
238 sprintf(harddrive, "ataraid/d0");
239 }
240 } else {
241 raid_disk = 1;
242 sprintf(harddrive, "rd/c0d0");
243 }
244 } else {
245 raid_disk = 1;
246 sprintf(harddrive, "cciss/c0d0");
247 }
248 } else {
249 raid_disk = 1;
250 sprintf(harddrive, "ida/c0d0");
251 }
252 } else {
253 if (strstr(sourcedrive, "sda") != NULL) {
254 // probably installing from usb stick, try sdb
255 if (try_scsi("sdb")) {
256 sprintf(harddrive, "sdb");
257 }
258 else {
259 errorbox(ctr[TR_NO_HARDDISK]);
260 goto EXIT;
261 }
262 }
263 else {
264 sprintf(harddrive, "sda");
265 }
266 }
267 scsi_disk = 1;
268 } else
269 sprintf(harddrive, "hd%c", hdletter);
270
9607771a 271 fprintf(flog, "Destination drive: %s\n", harddrive);
d6aaa55d 272
72d80898
MT
273 /* load unattended configuration */
274 if (unattended) {
275 fprintf(flog, "unattended: Reading unattended.conf\n");
276
277 (void) readkeyvalues(unattendedkv, UNATTENDED_CONF);
278 }
279
280 /* Make the hdparms struct and print the contents. */
281 snprintf(hdparams.devnode, STRING_SIZE, "/dev/%s", harddrive);
282 hdparams.module = 0;
283
284 sprintf(message, ctr[TR_PREPARE_HARDDISK], hdparams.devnode);
285
286 if (unattended) {
287 hardyn = 1;
288 }
289
290 while (! hardyn) {
291 rc = newtWinMenu(title, message,
292 50, 5, 5, 6, yesnoharddisk,
293 &hardyn, ctr[TR_OK],
294 ctr[TR_CANCEL], NULL);
295 if (rc == 2)
296 goto EXIT;
297 }
5433e2c9
MT
298
299 if (rc == 2)
300 goto EXIT;
72d80898
MT
301
302 /* Calculate amount of memory in machine */
303 if ((handle = fopen("/proc/meminfo", "r")))
304 {
305 while (fgets(line, STRING_SIZE-1, handle)) {
306 if (sscanf (line, "MemTotal: %s kB", string)) {
307 memory = atoi(string) / 1024 ;
308 }
309 }
310 fclose(handle);
311 }
312
313 /* Partition, mkswp, mkfs.
314 * before partitioning, first determine the sizes of each
315 * partition. In order to do that we need to know the size of
316 * the disk.
317 */
318 /* Don't use mysystem here so we can redirect output */
0b59f25c 319 sprintf(commandstring, "/bin/sfdisk -s /dev/%s > /tmp/disksize 2> /dev/null", harddrive);
72d80898
MT
320 system(commandstring);
321
322 /* Calculate amount of disk space */
0b59f25c 323 if ((handle = fopen("/tmp/disksize", "r")))
72d80898
MT
324 {
325 fgets(line, STRING_SIZE-1, handle);
326 if (sscanf (line, "%s", string)) {
327 maximum_free = atoi(string) / 1024;
328 }
329 fclose(handle);
330 }
331
332 fprintf(flog, "maximum_free = %ld, memory = %ld",
333 maximum_free, memory);
334
335 swap_file = calc_swapsize(memory, maximum_free);
336
337 if (maximum_free < 512 + swap_file ) {
338 if (maximum_free < 512) {
339 errorbox(ctr[TR_DISK_TOO_SMALL]);
340 goto EXIT;
341 }
342
343 if (!unattended) {
344 rc = newtWinChoice(title, ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_CONTINUE_NO_SWAP]);
345 }
346 else {
347 rc = 1;
348 }
349
350 if (rc != 1)
351 goto EXIT;
352 swap_file = 0;
353 }
354
8e2e5cf3 355 boot_partition = 20; /* in MB */
72d80898
MT
356 current_free = maximum_free - boot_partition - swap_file;
357
8e2e5cf3
MT
358 root_partition = 2048 ;
359 if (current_free < 512) {
72d80898
MT
360 errorbox(ctr[TR_DISK_TOO_SMALL]);
361 goto EXIT;
362 }
363
364 current_free = current_free - root_partition;
365 if (!swap_file) {
366 root_partition = root_partition + swap_file;
367 }
368
8e2e5cf3 369 system_partition = current_free;
72d80898
MT
370
371 fprintf(flog, "boot = %ld, swap = %ld, mylog = %ld, root = %ld\n",
8e2e5cf3 372 boot_partition, swap_file, system_partition, root_partition);
72d80898
MT
373
374 handle = fopen("/tmp/partitiontable", "w");
375
72d80898
MT
376 /* Make swapfile */
377 if (swap_file) {
9607771a 378 fprintf(handle, ",%ld,L,*\n,%ld,S,\n,%ld,L,\n,,L,\n",
72d80898
MT
379 boot_partition, swap_file, root_partition);
380 } else {
9607771a 381 fprintf(handle, ",%ld,L,*\n,0,0,\n,%ld,L,\n,,L,\n",
72d80898
MT
382 boot_partition, root_partition);
383 }
384
385 fclose(handle);
386
387 snprintf(commandstring, STRING_SIZE, "/bin/sfdisk -L -uM %s < /tmp/partitiontable", hdparams.devnode);
388 if (runcommandwithstatus(commandstring, ctr[TR_PARTITIONING_DISK]))
389 {
390 errorbox(ctr[TR_UNABLE_TO_PARTITION]);
391 goto EXIT;
392 }
393
532a3663 394 mysystem("/sbin/udevstart");
72d80898
MT
395
396 if (raid_disk)
8e2e5cf3 397 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %sp1", hdparams.devnode);
72d80898 398 else
8e2e5cf3 399 snprintf(commandstring, STRING_SIZE, "/bin/mke2fs -T ext2 -c %s1", hdparams.devnode);
72d80898
MT
400 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_BOOT_FILESYSTEM]))
401 {
402 errorbox(ctr[TR_UNABLE_TO_MAKE_BOOT_FILESYSTEM]);
403 goto EXIT;
404 }
405
406 if (swap_file) {
407 if (raid_disk)
532a3663 408 snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %sp2", hdparams.devnode);
72d80898 409 else
532a3663 410 snprintf(commandstring, STRING_SIZE, "/sbin/mkswap %s2", hdparams.devnode);
72d80898
MT
411 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_SWAPSPACE]))
412 {
413 errorbox(ctr[TR_UNABLE_TO_MAKE_SWAPSPACE]);
414 goto EXIT;
415 }
416 }
417
418 if (raid_disk)
76ed51e8 419 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %sp3", hdparams.devnode);
72d80898 420 else
76ed51e8 421 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s3", hdparams.devnode);
72d80898
MT
422
423 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_ROOT_FILESYSTEM]))
424 {
425 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
426 goto EXIT;
427 }
428
9607771a 429 if (raid_disk)
76ed51e8 430 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %sp4", hdparams.devnode);
72d80898 431 else
76ed51e8 432 snprintf(commandstring, STRING_SIZE, "/sbin/mkreiserfs -f %s4", hdparams.devnode);
72d80898
MT
433
434 if (runcommandwithstatus(commandstring, ctr[TR_MAKING_LOG_FILESYSTEM]))
435 {
436 errorbox(ctr[TR_UNABLE_TO_MAKE_ROOT_FILESYSTEM]);
437 goto EXIT;
9607771a 438 }
72d80898
MT
439
440 /* Mount harddisk. */
441 if (raid_disk)
532a3663 442 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp3 /harddisk", hdparams.devnode);
72d80898 443 else
532a3663 444 snprintf(commandstring, STRING_SIZE, "/bin/mount %s3 /harddisk", hdparams.devnode);
72d80898
MT
445 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_ROOT_FILESYSTEM]))
446 {
447 errorbox(ctr[TR_UNABLE_TO_MOUNT_ROOT_FILESYSTEM]);
448 goto EXIT;
449 }
450
451 mkdir("/harddisk/boot", S_IRWXU|S_IRWXG|S_IRWXO);
452 mkdir("/harddisk/var", S_IRWXU|S_IRWXG|S_IRWXO);
453 mkdir("/harddisk/var/log", S_IRWXU|S_IRWXG|S_IRWXO);
454
455 if (raid_disk)
532a3663 456 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp1 /harddisk/boot", hdparams.devnode);
72d80898 457 else
532a3663 458 snprintf(commandstring, STRING_SIZE, "/bin/mount %s1 /harddisk/boot", hdparams.devnode);
72d80898
MT
459
460 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_BOOT_FILESYSTEM]))
461 {
462 errorbox(ctr[TR_UNABLE_TO_MOUNT_BOOT_FILESYSTEM]);
463 goto EXIT;
464 }
465 if (swap_file) {
466 if (raid_disk)
532a3663 467 snprintf(commandstring, STRING_SIZE, "/sbin/swapon %sp2", hdparams.devnode);
72d80898 468 else
532a3663 469 snprintf(commandstring, STRING_SIZE, "/sbin/swapon %s2", hdparams.devnode);
72d80898
MT
470 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_SWAP_PARTITION]))
471 {
472 errorbox(ctr[TR_UNABLE_TO_MOUNT_SWAP_PARTITION]);
473 goto EXIT;
474 }
475 }
9607771a 476 if (raid_disk)
532a3663 477 snprintf(commandstring, STRING_SIZE, "/bin/mount %sp4 /harddisk/var", hdparams.devnode);
72d80898 478 else
532a3663 479 snprintf(commandstring, STRING_SIZE, "/bin/mount %s4 /harddisk/var", hdparams.devnode);
72d80898
MT
480 if (runcommandwithstatus(commandstring, ctr[TR_MOUNTING_LOG_FILESYSTEM]))
481 {
482 errorbox(ctr[TR_UNABLE_TO_MOUNT_LOG_FILESYSTEM]);
483 goto EXIT;
9607771a 484 }
c78a77eb
MT
485
486 if (installtype == URL_INSTALL) {
487 snprintf(commandstring, STRING_SIZE,
488 "/bin/wget -q -O - %s/" SNAME "-" VERSION ".tbz2 | /bin/tar -C /harddisk -xvjf -", url);
489 }
490
491 if (installtype == CDROM_INSTALL) {
492 snprintf(commandstring, STRING_SIZE,
493 "/bin/tar -C /harddisk -xvjf /cdrom/" SNAME "-" VERSION ".tbz2");
494 }
d6aaa55d 495
edd536b6
MT
496 if (runcommandwithprogress(60, 4, title, commandstring, INST_FILECOUNT,
497 ctr[TR_INSTALLING_FILES]))
d6aaa55d
MT
498 {
499 errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
500 goto EXIT;
501 }
e57bc1fd 502
d6aaa55d
MT
503 /* Save USB controller type to modules.conf */
504 write_usb_modules_conf();
505
506 /* touch the modules.dep files */
10bc6f06 507 snprintf(commandstring, STRING_SIZE,
c78a77eb 508 "/bin/touch /harddisk/lib/modules/%s-ipfire/modules.dep",
10bc6f06
MT
509 KERNEL_VERSION);
510 mysystem(commandstring);
10bc6f06 511 snprintf(commandstring, STRING_SIZE,
c78a77eb 512 "/bin/touch /harddisk/lib/modules/%s-ipfire-smp/modules.dep",
10bc6f06
MT
513 KERNEL_VERSION);
514 mysystem(commandstring);
d6aaa55d
MT
515
516 /* Rename uname */
517 rename ("/harddisk/bin/uname.bak", "/harddisk/bin/uname");
518
d6aaa55d
MT
519 /* *always* write disk configuration */
520 if (!(write_disk_configs(&hdparams))){
10bc6f06
MT
521 errorbox(ctr[TR_ERROR_WRITING_CONFIG]);
522 goto EXIT;
d6aaa55d
MT
523 }
524
9607771a
MT
525 /* mount proc filesystem */
526 mysystem("mkdir /harddisk/proc");
527 mysystem("/bin/mount -t proc none /harddisk/proc");
528 mysystem("/bin/mount --bind /dev /harddisk/dev");
529
73d9a908 530
22b9e405 531 /* if we detected SCSI then fixup */
73d9a908
MT
532 /* doesn't really work cause it sometimes creates a ramdisk on ide systems */
533/* mysystem("/bin/probecntrl.sh");
9607771a 534 if ((handle = fopen("/cntrldriver", "r")))
22b9e405
MT
535 {
536 char *driver;
537 fgets(line, STRING_SIZE-1, handle);
538 fclose(handle);
539 line[strlen(line) - 1] = 0;
540 driver = strtok(line, ".");
541 fprintf(flog, "Detected SCSI driver %s\n",driver);
542 if (strlen(driver) > 1) {
543 fprintf(flog, "Fixing up ipfirerd.img\n");
532a3663 544 mysystem("/sbin/chroot /harddisk /sbin/modprobe loop");
22b9e405 545 mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
532a3663 546 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 547 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
532a3663 548 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 549 runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
532a3663 550 mysystem("/sbin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
9607771a 551 }
73d9a908 552 } */
22b9e405 553
9607771a 554 /* Build cache lang file */
532a3663 555 snprintf(commandstring, STRING_SIZE, "/sbin/chroot /harddisk /usr/bin/perl -e \"require '" CONFIG_ROOT "/lang.pl'; &Lang::BuildCacheLang\"");
9607771a
MT
556 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_LANG_CACHE]))
557 {
558 errorbox(ctr[TR_UNABLE_TO_INSTALL_LANG_CACHE]);
559 goto EXIT;
560 }
edd536b6
MT
561
562 if (raid_disk)
563 sprintf(string, "root=%sp3", hdparams.devnode);
564 else
565 sprintf(string, "root=%s3", hdparams.devnode);
566 replace( "/harddisk/boot/grub/grub.conf", "root=ROOT", string);
edd536b6 567 replace( "/harddisk/boot/grub/grubbatch", "DEVICE", hdparams.devnode);
fd0763dc 568
edd536b6
MT
569 /* restore permissions */
570 chmod("/harddisk/boot/grub/grubbatch", S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH);
571
edd536b6 572 snprintf(commandstring, STRING_SIZE,
532a3663 573 "/sbin/chroot /harddisk /boot/grub/grubbatch");
edd536b6
MT
574 if (runcommandwithstatus(commandstring, ctr[TR_INSTALLING_GRUB])) {
575 errorbox(ctr[TR_UNABLE_TO_INSTALL_GRUB]);
576 goto EXIT;
577 }
578
73d9a908 579 /* Update /etc/fstab */
c78a77eb 580 replace("/harddisk/etc/fstab", "DEVICE", hdparams.devnode);
73d9a908 581
22b9e405
MT
582 /* Install bootsplash */
583 mysystem("/bin/installbootsplash.sh");
584
585 mysystem("ln -s grub.conf /harddisk/boot/grub/menu.lst");
586 mysystem("umount /harddisk/proc");
587 mysystem("umount /harddisk/dev");
588
73d9a908
MT
589 if (!unattended) {
590 sprintf(message, ctr[TR_CONGRATULATIONS_LONG],
591 NAME, SNAME, SNAME, NAME, NAME, NAME);
592 newtWinMessage(ctr[TR_CONGRATULATIONS], ctr[TR_OK], message);
593 }
22b9e405
MT
594
595 allok = 1;
edd536b6 596
d6aaa55d 597EXIT:
10bc6f06 598 fprintf(flog, "Install program ended.\n");
d6aaa55d 599
10bc6f06 600 if (!(allok))
d6aaa55d 601 newtWinMessage(title, ctr[TR_OK], ctr[TR_PRESS_OK_TO_REBOOT]);
10bc6f06 602
d6aaa55d 603 freekeyvalues(ethernetkv);
d6aaa55d 604
10bc6f06 605 if (allok && !allok_fastexit)
d6aaa55d
MT
606 {
607 /* /proc is needed by the module checker. We have to mount it
608 * so it can be seen by setup, which is run chrooted. */
532a3663 609 if (system("/bin/mount proc -t proc /harddisk/proc"))
d6aaa55d
MT
610 printf("Unable to mount proc in /harddisk.");
611 else
612 {
c78a77eb
MT
613 if (unattended) {
614 fprintf(flog, "Entering unattended setup\n");
615 if (unattended_setup(unattendedkv)) {
616 snprintf(commandstring, STRING_SIZE, "/bin/sleep 10");
617 runcommandwithstatus(commandstring, "Unattended installation finished, system will reboot");
618 } else {
619 errorbox("Unattended setup failed.");
620 goto EXIT;
621 }
622 }
623
624 newtFinished();
625 fflush(flog);
626 fclose(flog);
3a1019f6
MT
627
628 if (!unattended) {
069680ac 629 if (system("/sbin/chroot /harddisk /usr/local/sbin/setup /dev/tty2 INSTALL"))
3a1019f6
MT
630 printf("Unable to run setup.\n");
631 }
3a1019f6 632
532a3663 633 if (system("/bin/umount /harddisk/proc"))
c78a77eb 634 printf("Unable to umount /harddisk/proc.\n");
d6aaa55d
MT
635 }
636 }
d6aaa55d
MT
637 fcloseall();
638
3a1019f6
MT
639 if (swap_file) {
640 if (raid_disk)
641 snprintf(commandstring, STRING_SIZE, "/bin/swapoff %sp2", hdparams.devnode);
642 else
643 snprintf(commandstring, STRING_SIZE, "/bin/swapoff %s2", hdparams.devnode);
644 }
645
646 newtFinished();
647
532a3663
MT
648 system("/bin/umount /harddisk/var");
649 system("/bin/umount /harddisk/boot");
650 system("/bin/umount /harddisk");
10bc6f06 651
d6aaa55d
MT
652 system("/etc/halt");
653
654 return 0;
655}